Skip to content

Commit 943ccbc

Browse files
committed
add param client_protocol
1 parent 374ab4c commit 943ccbc

File tree

9 files changed

+148
-68
lines changed

9 files changed

+148
-68
lines changed

dto_proto/http_dto.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ message CreateBotReq{
2727
int64 bot_id = 1;
2828
string password = 2;
2929
int64 device_seed = 3; // 设备信息随机种子
30+
int32 client_protocol = 4; // 协议类型
3031
}
3132
message CreateBotResp{
3233
}
@@ -63,6 +64,7 @@ message SolveCaptchaResp{
6364
// 获取二维码 /qrcode/fetch/v1/
6465
message FetchQRCodeReq{
6566
int64 device_seed = 1;
67+
int32 client_protocol = 2; // 协议类型
6668
}
6769
// 查询二维码状态 /qrcode/query/v1/
6870
message QueryQRCodeStatusReq{
@@ -90,7 +92,7 @@ service HttpService{
9092
rpc CreateBot(CreateBotReq)returns (CreateBotResp);
9193
rpc DeleteBot(DeleteBotReq)returns (DeleteBotResp);
9294
rpc ListBot(ListBotReq)returns (ListBotResp);
93-
// rpc BotLoginAsync(BotLoginAsyncReq)returns (BotLoginAsyncResp);
95+
// rpc BotLoginAsync(BotLoginAsyncReq)returns (BotLoginAsyncResp);
9496
rpc SolveCaptcha(SolveCaptchaReq)returns (SolveCaptchaResp);
9597
rpc FetchQRCode(FetchQRCodeReq)returns (QRCodeLoginResp);
9698
rpc QueryQRCodeStatus(QueryQRCodeStatusReq)returns (QRCodeLoginResp);

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/ProtobufBot/Go-Mirai-Client
33
go 1.17
44

55
require (
6-
github.com/Mrs4s/MiraiGo v0.0.0-20211208080234-25c67a3ee1c1
6+
github.com/Mrs4s/MiraiGo v0.0.0-20211217145841-1c29ac7d96a9
77
github.com/fanliao/go-promise v0.0.0-20141029170127-1890db352a72
88
github.com/gin-gonic/gin v1.7.2
99
github.com/go-playground/validator/v10 v10.8.0 // indirect
@@ -41,6 +41,7 @@ require (
4141
github.com/tidwall/match v1.1.1 // indirect
4242
github.com/tidwall/pretty v1.2.0 // indirect
4343
github.com/ugorji/go/codec v1.2.6 // indirect
44+
go.uber.org/atomic v1.9.0 // indirect
4445
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
4546
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
4647
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/Mrs4s/MiraiGo v0.0.0-20211208080234-25c67a3ee1c1 h1:UipCzEST10GzJnvlhHsY4g39xzwVzSHE+5Go9d0dTPY=
2-
github.com/Mrs4s/MiraiGo v0.0.0-20211208080234-25c67a3ee1c1/go.mod h1:YD9gBKkxC9lPPtx3doYXRG26VBkK6YXjrS76cv01C5w=
1+
github.com/Mrs4s/MiraiGo v0.0.0-20211217145841-1c29ac7d96a9 h1:ofK17BISIwIhVWRvlI/IBmQYqkI8aoVZlMwmYEtun0E=
2+
github.com/Mrs4s/MiraiGo v0.0.0-20211217145841-1c29ac7d96a9/go.mod h1:HI05ardsa5HE1Z2xTw69dytmaqqRWv4ajD5Jpnycqqw=
33
github.com/RomiChan/protobuf v0.0.0-20211204042931-ff4f35848737 h1:p4o7/eSoP39jwnGZz08N1IpH/mNzg9SdCn7kPM9A9BE=
44
github.com/RomiChan/protobuf v0.0.0-20211204042931-ff4f35848737/go.mod h1:CKKOWC7mBxd36zxsCB1V8DTrwlTNRQvkSVbYqyUiGEE=
55
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -101,6 +101,8 @@ github.com/ugorji/go/codec v1.2.6 h1:7kbGefxLoDBuYXOms4yD7223OpNMMPNPZxXk5TvFcyQ
101101
github.com/ugorji/go/codec v1.2.6/go.mod h1:V6TCNZ4PHqoHGFZuSG1W8nrCzzdgA2DozYxWFFpvxTw=
102102
github.com/zserge/lorca v0.1.10 h1:f/xBJ3D3ipcVRCcvN8XqZnpoKcOXV8I4vwqlFyw7ruc=
103103
github.com/zserge/lorca v0.1.10/go.mod h1:bVmnIbIRlOcoV285KIRSe4bUABKi7R7384Ycuum6e4A=
104+
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
105+
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
104106
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
105107
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
106108
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI=

pkg/bot/bot.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ func Login(cli *client.QQClient) (bool, error) {
5151
func SetRelogin(cli *client.QQClient, retryInterval int, retryCount int) {
5252
LoginTokens.Store(cli.Uin, cli.GenToken())
5353
cli.OnDisconnected(func(bot *client.QQClient, e *client.ClientDisconnectedEvent) {
54-
if bot.Online {
54+
if bot.Online.Load() {
5555
return
5656
}
5757
bot.Disconnect()
5858
var times = 1
5959
for IsClientExist(bot.Uin) {
60-
if bot.Online {
60+
if bot.Online.Load() {
6161
log.Warn("Bot已登录")
6262
return
6363
}

pkg/bot/remote.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func OnWsRecvMessage(cli *client.QQClient) func(ws *safe_ws.SafeWebSocket, messa
118118
if messageType == websocket.PingMessage || messageType == websocket.PongMessage {
119119
return
120120
}
121-
if !cli.Online {
121+
if !cli.Online.Load() {
122122
log.Warnf("bot is not online, ignore API, %+v", cli.Uin)
123123
return
124124
}

pkg/device/device.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func GenNewTgtgtKey(randGen *rand.Rand, info *client.DeviceInfo) {
103103
// 使用种子生成随机设备信息
104104
// 如果已有设备文件,使用已有设备信息覆盖
105105
// 存储设备信息到文件
106-
func GetDevice(seed int64) *client.DeviceInfo {
106+
func GetDevice(seed int64, clientProtocol int32) *client.DeviceInfo {
107107
randGen := rand.New(rand.NewSource(seed))
108108
if seed == 0 {
109109
randGen = rand.New(rand.NewSource(time.Now().UnixNano()))
@@ -136,6 +136,10 @@ func GetDevice(seed int64) *client.DeviceInfo {
136136
}
137137
}
138138

139+
if clientProtocol > 0 && clientProtocol < 6 {
140+
deviceInfo.Protocol = client.ClientProtocol(clientProtocol)
141+
}
142+
139143
GenNewGuid(deviceInfo)
140144
GenNewTgtgtKey(randGen, deviceInfo)
141145

pkg/gmc/gmc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func CreateBotIfParamExist() {
150150
if uin != 0 && pass != "" {
151151
log.Infof("使用参数创建机器人 %d", uin)
152152
go func() {
153-
handler.CreateBotImpl(uin, pass, 0)
153+
handler.CreateBotImpl(uin, pass, 0, 0)
154154
}()
155155
}
156156
}

pkg/gmc/handler/bot.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func CreateBot(c *gin.Context) {
6969
return
7070
}
7171
go func() {
72-
CreateBotImpl(req.BotId, req.Password, req.DeviceSeed)
72+
CreateBotImpl(req.BotId, req.Password, req.DeviceSeed, req.ClientProtocol)
7373
}()
7474
resp := &dto.CreateBotResp{}
7575
Return(c, resp)
@@ -105,7 +105,7 @@ func ListBot(c *gin.Context) {
105105
bot.Clients.Range(func(_ int64, cli *client.QQClient) bool {
106106
resp.BotList = append(resp.BotList, &dto.Bot{
107107
BotId: cli.Uin,
108-
IsOnline: cli.Online,
108+
IsOnline: cli.Online.Load(),
109109
Captcha: func() *dto.Bot_Captcha {
110110
if waitingCaptcha, ok := bot.WaitingCaptchas.Load(cli.Uin); ok {
111111
return waitingCaptcha.Captcha
@@ -152,7 +152,7 @@ func FetchQrCode(c *gin.Context) {
152152
qrCodeBot.Release()
153153
}
154154
qrCodeBot = client.NewClientEmpty()
155-
deviceInfo := device.GetDevice(req.DeviceSeed)
155+
deviceInfo := device.GetDevice(req.DeviceSeed, req.ClientProtocol)
156156
qrCodeBot.UseDevice(deviceInfo)
157157

158158
log.Infof("初始化日志")
@@ -185,7 +185,7 @@ func QueryQRCodeStatus(c *gin.Context) {
185185
return
186186
}
187187

188-
if qrCodeBot.Online {
188+
if qrCodeBot.Online.Load() {
189189
c.String(http.StatusBadRequest, "already online")
190190
return
191191
}
@@ -247,15 +247,15 @@ func Return(c *gin.Context, resp proto.Message) {
247247
c.Data(http.StatusOK, c.ContentType(), data)
248248
}
249249

250-
func CreateBotImpl(uin int64, password string, deviceRandSeed int64) {
251-
CreateBotImplMd5(uin, md5.Sum([]byte(password)), deviceRandSeed)
250+
func CreateBotImpl(uin int64, password string, deviceRandSeed int64, clientProtocol int32) {
251+
CreateBotImplMd5(uin, md5.Sum([]byte(password)), deviceRandSeed, clientProtocol)
252252
}
253253

254-
func CreateBotImplMd5(uin int64, passwordMd5 [16]byte, deviceRandSeed int64) {
254+
func CreateBotImplMd5(uin int64, passwordMd5 [16]byte, deviceRandSeed int64, clientProtocol int32) {
255255
log.Infof("开始初始化设备信息")
256-
deviceInfo := device.GetDevice(uin)
256+
deviceInfo := device.GetDevice(uin, clientProtocol)
257257
if deviceRandSeed != 0 {
258-
deviceInfo = device.GetDevice(deviceRandSeed)
258+
deviceInfo = device.GetDevice(deviceRandSeed, clientProtocol)
259259
}
260260
log.Infof("设备信息 %+v", string(deviceInfo.ToJson()))
261261

@@ -286,7 +286,7 @@ func CreateBotImplMd5(uin int64, passwordMd5 [16]byte, deviceRandSeed int64) {
286286
func AfterLogin(cli *client.QQClient) {
287287
for {
288288
time.Sleep(5 * time.Second)
289-
if cli.Online {
289+
if cli.Online.Load() {
290290
break
291291
}
292292
log.Warnf("机器人不在线,可能在等待输入验证码,或出错了。如果出错请重启。")

0 commit comments

Comments
 (0)