mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-06 03:53:50 +08:00
remove 'servers.bin'
This commit is contained in:
parent
9049018d2f
commit
8f5b8375a7
@ -7,7 +7,6 @@ go-cqhttp 默认生成的文件树如下所示:
|
|||||||
├── go-cqhttp
|
├── go-cqhttp
|
||||||
├── config.json
|
├── config.json
|
||||||
├── device.json
|
├── device.json
|
||||||
├── servers.bin
|
|
||||||
├── logs
|
├── logs
|
||||||
│ └── xx-xx-xx.log
|
│ └── xx-xx-xx.log
|
||||||
└── data
|
└── data
|
||||||
@ -21,7 +20,6 @@ go-cqhttp 默认生成的文件树如下所示:
|
|||||||
| go-cqhttp | go-cqhttp可执行文件 |
|
| go-cqhttp | go-cqhttp可执行文件 |
|
||||||
| config.json | 运行配置文件 |
|
| config.json | 运行配置文件 |
|
||||||
| device.json | 虚拟设备配置文件 |
|
| device.json | 虚拟设备配置文件 |
|
||||||
| servers.bin | 储存QQ服务器地址 |
|
|
||||||
| logs | 日志存放目录 |
|
| logs | 日志存放目录 |
|
||||||
| data | 数据目录 |
|
| data | 数据目录 |
|
||||||
| data/images | 图片缓存目录 |
|
| data/images | 图片缓存目录 |
|
||||||
|
42
main.go
42
main.go
@ -10,7 +10,6 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
@ -237,47 +236,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) {
|
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) {
|
||||||
log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. 地址信息已储存到 servers.bin 文件")
|
log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. ")
|
||||||
_ = ioutil.WriteFile("servers.bin", binary.NewWriterF(func(w *binary.Writer) {
|
|
||||||
w.WriteUInt16(func() (c uint16) {
|
|
||||||
for _, s := range e.Servers {
|
|
||||||
if !strings.Contains(s.Server, "com") {
|
|
||||||
c++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}())
|
|
||||||
for _, s := range e.Servers {
|
|
||||||
if !strings.Contains(s.Server, "com") {
|
|
||||||
w.WriteString(s.Server)
|
|
||||||
w.WriteUInt16(uint16(s.Port))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}), 0644)
|
|
||||||
})
|
})
|
||||||
if global.PathExists("servers.bin") {
|
|
||||||
if data, err := ioutil.ReadFile("servers.bin"); err == nil {
|
|
||||||
func() {
|
|
||||||
defer func() {
|
|
||||||
if pan := recover(); pan != nil {
|
|
||||||
log.Error("读取服务器地址时出现错误: ", pan)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
r := binary.NewReader(data)
|
|
||||||
var addr []*net.TCPAddr
|
|
||||||
l := r.ReadUInt16()
|
|
||||||
for i := 0; i < int(l); i++ {
|
|
||||||
addr = append(addr, &net.TCPAddr{
|
|
||||||
IP: net.ParseIP(r.ReadString()),
|
|
||||||
Port: int(r.ReadUInt16()),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if len(addr) > 0 {
|
|
||||||
cli.SetCustomServer(addr)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rsp, err := cli.Login()
|
rsp, err := cli.Login()
|
||||||
for {
|
for {
|
||||||
global.Check(err)
|
global.Check(err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user