1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-04 19:17:37 +08:00

rf: change protocol auto-update to manual update

This commit is contained in:
Mrs4s 2023-04-02 18:04:13 +08:00
parent 268ac07271
commit 1ab1cba84c
No known key found for this signature in database
GPG Key ID: 3186E98FA19CE3A7
4 changed files with 31 additions and 25 deletions

View File

@ -18,6 +18,7 @@ import (
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
"golang.org/x/crypto/pbkdf2"
"golang.org/x/term"
@ -281,24 +282,30 @@ func LoginInteract() {
cli.Uin = base.Account.Uin
cli.PasswordMd5 = base.PasswordHash
}
if !isTokenLogin {
if !base.Account.DisableProtocolUpdate {
log.Infof("正在检查协议更新...")
oldVersionName := device.Protocol.Version().String()
remoteVersion, err := getRemoteLatestProtocolVersion(int(device.Protocol.Version().Protocol))
if err == nil {
if err = device.Protocol.Version().UpdateFromJson(remoteVersion); err == nil {
if device.Protocol.Version().String() != oldVersionName {
log.Infof("已自动更新协议版本: %s -> %s", oldVersionName, device.Protocol.Version().String())
} else {
log.Infof("协议已经是最新版本")
}
_ = os.WriteFile(versionFile, remoteVersion, 0o644)
if !base.FastStart {
log.Infof("正在检查协议更新...")
currentVersionName := device.Protocol.Version().SortVersionName
remoteVersion, err := getRemoteLatestProtocolVersion(int(device.Protocol.Version().Protocol))
if err == nil {
remoteVersionName := gjson.GetBytes(remoteVersion, "sort_version_name").String()
if remoteVersionName != currentVersionName {
switch {
case !base.UpdateProtocol:
log.Infof("检测到协议更新: %s -> %s", currentVersionName, remoteVersionName)
log.Infof("如果登录时出现版本过低错误, 可尝试使用 -update-protocol 参数启动")
case !isTokenLogin:
_ = device.Protocol.Version().UpdateFromJson(remoteVersion)
log.Infof("协议版本已更新: %s -> %s", currentVersionName, remoteVersionName)
default:
log.Infof("检测到协议更新: %s -> %s", currentVersionName, remoteVersionName)
log.Infof("由于使用了会话缓存, 无法自动更新协议, 请删除缓存后重试")
}
} else if err.Error() != "remote version unavailable" {
log.Warnf("检查协议更新失败: %v", err)
}
} else if err.Error() != "remote version unavailable" {
log.Warnf("检查协议更新失败: %v", err)
}
}
if !isTokenLogin {
if !isQRCodeLogin {
if err := commonLogin(); err != nil {
log.Fatalf("登录时发生致命错误: %v", err)

View File

@ -37,6 +37,7 @@ var (
LogColorful bool // 是否启用日志颜色
FastStart bool // 是否为快速启动
AllowTempSession bool // 是否允许发送临时会话信息
UpdateProtocol bool // 是否更新协议
SignServerOverwrite string // 使用特定的服务器进行签名
PostFormat string // 上报格式 string or array
@ -61,6 +62,7 @@ func Parse() {
flag.StringVar(&LittleWD, "w", "", "cover the working directory")
d := flag.Bool("D", false, "debug mode")
flag.BoolVar(&FastStart, "faststart", false, "skip waiting 5 seconds")
flag.BoolVar(&UpdateProtocol, "update-protocol", false, "update protocol")
flag.StringVar(&SignServerOverwrite, "sign-server", "", "use special server to sign tlv")
flag.Parse()

View File

@ -28,14 +28,13 @@ type Reconnect struct {
// Account 账号配置
type Account struct {
Uin int64 `yaml:"uin"`
Password string `yaml:"password"`
Encrypt bool `yaml:"encrypt"`
Status int `yaml:"status"`
ReLogin *Reconnect `yaml:"relogin"`
UseSSOAddress bool `yaml:"use-sso-address"`
AllowTempSession bool `yaml:"allow-temp-session"`
DisableProtocolUpdate bool `yaml:"disable-protocol-update"`
Uin int64 `yaml:"uin"`
Password string `yaml:"password"`
Encrypt bool `yaml:"encrypt"`
Status int `yaml:"status"`
ReLogin *Reconnect `yaml:"relogin"`
UseSSOAddress bool `yaml:"use-sso-address"`
AllowTempSession bool `yaml:"allow-temp-session"`
}
// Config 总配置文件

View File

@ -15,8 +15,6 @@ account: # 账号相关
use-sso-address: true
# 是否允许发送临时会话消息
allow-temp-session: false
# 是否禁用协议更新
disable-protocol-update: false
heartbeat:
# 心跳频率, 单位秒