Skip to content

Commit

Permalink
feature sso address control.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrs4s committed Nov 12, 2020
1 parent 0ed6522 commit 535b4ee
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
"ignore_invalid_cqcode": false,
"force_fragmented": true,
"heartbeat_interval": 5,
"use_sso_address": false,
"http_config": {
"enabled": true,
"host": "0.0.0.0",
Expand Down Expand Up @@ -77,6 +78,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
| post_message_format | string | 上报信息类型 |
| ignore_invalid_cqcode| bool | 是否忽略错误的CQ码 |
| force_fragmented | bool | 是否强制分片发送群长消息 |
| use_sso_address | bool | 是否使用服务器下发的地址 |
| heartbeat_interval | int64 | 心跳间隔时间,单位秒。小于0则关闭心跳,等于0使用默认值(5秒) |
| http_config | object | HTTP API配置 |
| ws_config | object | Websocket API 配置 |
Expand Down
1 change: 1 addition & 0 deletions global/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type JsonConfig struct {
WSConfig *GoCQWebsocketConfig `json:"ws_config"`
ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"`
PostMessageFormat string `json:"post_message_format"`
UseSSOAddress bool `json:"use_sso_address"`
Debug bool `json:"debug"`
LogLevel string `json:"log_level"`
WebUi *GoCqWebUi `json:"web_ui"`
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
go 1.14

require (
github.com/Mrs4s/MiraiGo v0.0.0-20201112125100-c41a3dbb0f4a
github.com/Mrs4s/MiraiGo v0.0.0-20201112150130-58e7c82fd2dd
github.com/dustin/go-humanize v1.0.0
github.com/getlantern/go-update v0.0.0-20190510022740-79c495ab728c
github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Mrs4s/MiraiGo v0.0.0-20201112125100-c41a3dbb0f4a h1:6AESfMoGUVTMsgbs4tCE68fXOQq6PUyPTEy6JBX46So=
github.com/Mrs4s/MiraiGo v0.0.0-20201112125100-c41a3dbb0f4a/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs=
github.com/Mrs4s/MiraiGo v0.0.0-20201112150130-58e7c82fd2dd h1:n1llMhWgT5s/dBWtbg0NwDzXFAKWfwr1ZXxaErZkLfc=
github.com/Mrs4s/MiraiGo v0.0.0-20201112150130-58e7c82fd2dd/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,13 @@ func main() {
log.Debug("Protocol -> " + e.Message)
}
})
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) {
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) bool {
if !conf.UseSSOAddress {
log.Infof("收到服务器地址更新通知, 根据配置文件已忽略.")
return false
}
log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. ")
return true
})
if conf.WebUi == nil {
conf.WebUi = &global.GoCqWebUi{
Expand Down
7 changes: 6 additions & 1 deletion server/apiAdmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,13 @@ func (s *webServer) DoReLogin() { // TODO: 协议层的 ReLogin
log.Debug("Protocol -> " + e.Message)
}
})
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) {
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) bool {
if !conf.UseSSOAddress {
log.Infof("收到服务器地址更新通知, 根据配置文件已忽略.")
return false
}
log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. ")
return true
})
s.Cli = cli
s.Dologin()
Expand Down

0 comments on commit 535b4ee

Please sign in to comment.