Skip to content

Commit

Permalink
fix #266.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrs4s committed Sep 11, 2020
1 parent 09aa852 commit b0e00fe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
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-20200910013944-236c0f629099
github.com/Mrs4s/MiraiGo v0.0.0-20200911100852-71bc19cd42eb
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/gin-gonic/gin v1.6.3
github.com/go-playground/validator/v10 v10.3.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/Mrs4s/MiraiGo v0.0.0-20200910010455-37409b1f6b9c h1:bhVr3W0+WTVN+vgZG
github.com/Mrs4s/MiraiGo v0.0.0-20200910010455-37409b1f6b9c/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20200910013944-236c0f629099 h1:b+Tmo9h5leZmQokdUu8c2xSIRkkSYoP1z8G+zcwwyRY=
github.com/Mrs4s/MiraiGo v0.0.0-20200910013944-236c0f629099/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20200911100852-71bc19cd42eb h1:WRj/3obehfAMTNKfNo+X3NVqXjeNurMk2yy6haNl/Yk=
github.com/Mrs4s/MiraiGo v0.0.0-20200911100852-71bc19cd42eb/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
23 changes: 23 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"image"
"io"
"io/ioutil"
"net"
"os"
"os/signal"
"path"
Expand Down Expand Up @@ -224,6 +225,16 @@ func main() {
log.Debug("Protocol -> " + e.Message)
}
})
if global.PathExists("servers.bin") {
if data, err := ioutil.ReadFile("servers.bin"); err == nil {
r := binary.NewReader(data)
r.ReadUInt16()
cli.CustomServer = &net.TCPAddr{
IP: r.ReadBytes(4),
Port: int(r.ReadUInt16()),
}
}
}
rsp, err := cli.Login()
for {
global.Check(err)
Expand Down Expand Up @@ -284,6 +295,18 @@ func main() {
}
log.Info("资源初始化完成, 开始处理信息.")
log.Info("アトリは、高性能ですから!")
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) {
log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. 服务器地址: %v:%v 服务器位置: %v", e.Servers[0].Server, e.Servers[0].Port, e.Servers[0].Location)
_ = ioutil.WriteFile("servers.bin", binary.NewWriterF(func(w *binary.Writer) {
w.WriteUInt16(uint16(len(e.Servers)))
for _, s := range e.Servers {
if !strings.Contains(s.Server, "com") {
w.Write(net.ParseIP(s.Server))
w.WriteUInt16(uint16(s.Port))
}
}
}), 0644)
})
cli.OnDisconnected(func(bot *client.QQClient, e *client.ClientDisconnectedEvent) {
if conf.ReLogin.Enabled {
var times uint = 1
Expand Down

0 comments on commit b0e00fe

Please sign in to comment.