From d34f8ddad6daca6a1d962869be84c3b4319918f4 Mon Sep 17 00:00:00 2001 From: Mrs4s Date: Tue, 2 Mar 2021 17:09:17 +0800 Subject: [PATCH] update ptt decoder & fix skey refresh panic with device lock disabled. --- client/c2c_processor.go | 23 +++++++++++++++++------ client/client.go | 5 ++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/client/c2c_processor.go b/client/c2c_processor.go index 63d2b779..4dcef337 100644 --- a/client/c2c_processor.go +++ b/client/c2c_processor.go @@ -18,7 +18,7 @@ var c2cDecoders = map[int32]func(*QQClient, *msg.Message, *c2cExtraOption){ 45: troopSystemMessageDecoder, 46: troopSystemMessageDecoder, 84: troopSystemMessageDecoder, 85: troopSystemMessageDecoder, 86: troopSystemMessageDecoder, 87: troopSystemMessageDecoder, 140: tempSessionDecoder, 141: tempSessionDecoder, - 166: privateMessageDecoder, 208: privateMessageDecoder, + 166: privateMessageDecoder, 208: privatePttDecoder, 187: systemMessageDecoder, 188: systemMessageDecoder, 189: systemMessageDecoder, 190: systemMessageDecoder, 191: systemMessageDecoder, 529: msgType0x211Decoder, @@ -153,7 +153,7 @@ func (c *QQClient) c2cMessageSyncProcessor(rsp *msg.GetMessageResponse, opt *c2c } } -func privateMessageDecoder(c *QQClient, pMsg *msg.Message, opt *c2cExtraOption) { +func privateMessageDecoder(c *QQClient, pMsg *msg.Message, _ *c2cExtraOption) { if pMsg.Head.GetFromUin() == c.Uin { for { frdSeq := atomic.LoadInt32(&c.friendSeq) @@ -172,7 +172,18 @@ func privateMessageDecoder(c *QQClient, pMsg *msg.Message, opt *c2cExtraOption) c.dispatchFriendMessage(c.parsePrivateMessage(pMsg)) } -func tempSessionDecoder(c *QQClient, pMsg *msg.Message, opt *c2cExtraOption) { +func privatePttDecoder(c *QQClient, pMsg *msg.Message, _ *c2cExtraOption) { + if pMsg.Body == nil || pMsg.Body.RichText == nil || pMsg.Body.RichText.Ptt == nil { + return + } + if len(pMsg.Body.RichText.Ptt.Reserve) != 0 { + //m := binary.NewReader(pMsg.Body.RichText.Ptt.Reserve[1:]).ReadTlvMap(1) + // T3 -> timestamp T8 -> voiceType T9 -> voiceLength T10 -> PbReserveStruct + } + c.dispatchFriendMessage(c.parsePrivateMessage(pMsg)) +} + +func tempSessionDecoder(c *QQClient, pMsg *msg.Message, _ *c2cExtraOption) { if pMsg.Head.C2CTmpMsgHead == nil { return } @@ -186,7 +197,7 @@ func tempSessionDecoder(c *QQClient, pMsg *msg.Message, opt *c2cExtraOption) { c.dispatchTempMessage(c.parseTempMessage(pMsg)) } -func troopAddMemberBroadcastDecoder(c *QQClient, pMsg *msg.Message, opt *c2cExtraOption) { +func troopAddMemberBroadcastDecoder(c *QQClient, pMsg *msg.Message, _ *c2cExtraOption) { groupJoinLock.Lock() defer groupJoinLock.Unlock() group := c.FindGroupByUin(pMsg.Head.GetFromUin()) @@ -212,7 +223,7 @@ func troopAddMemberBroadcastDecoder(c *QQClient, pMsg *msg.Message, opt *c2cExtr } } -func systemMessageDecoder(c *QQClient, pMsg *msg.Message, opt *c2cExtraOption) { +func systemMessageDecoder(c *QQClient, pMsg *msg.Message, _ *c2cExtraOption) { _, pkt := c.buildSystemMsgNewFriendPacket() _ = c.send(pkt) } @@ -232,7 +243,7 @@ func troopSystemMessageDecoder(c *QQClient, pMsg *msg.Message, opt *c2cExtraOpti } } -func msgType0x211Decoder(c *QQClient, pMsg *msg.Message, opt *c2cExtraOption) { +func msgType0x211Decoder(c *QQClient, pMsg *msg.Message, _ *c2cExtraOption) { sub4 := msg.SubMsgType0X4Body{} if err := proto.Unmarshal(pMsg.Body.MsgContent, &sub4); err != nil { err = errors.Wrap(err, "unmarshal sub msg 0x4 error") diff --git a/client/client.go b/client/client.go index 9f770fd9..94ff10c1 100644 --- a/client/client.go +++ b/client/client.go @@ -304,6 +304,9 @@ func (c *QQClient) RequestSMS() bool { } func (c *QQClient) init() { + if len(c.g) == 0 { + c.Warning("device lock is disable. http api may fail.") + } c.Online = true _ = c.registerClient() c.groupSysMsgCache, _ = c.GetGroupSystemMessages() @@ -629,7 +632,7 @@ func (c *QQClient) SolveFriendRequest(req *NewFriendRequest, accept bool) { } func (c *QQClient) getSKey() string { - if c.sigInfo.sKeyExpiredTime < time.Now().Unix() { + if c.sigInfo.sKeyExpiredTime < time.Now().Unix() && len(c.g) > 0 { c.Debug("skey expired. refresh...") _, _ = c.sendAndWait(c.buildRequestTgtgtNopicsigPacket()) }