From d0639731dbead06865acfb9dfb9dd286aa1f9187 Mon Sep 17 00:00:00 2001 From: Mrs4s Date: Wed, 21 Oct 2020 07:31:42 +0800 Subject: [PATCH] fix online push. --- client/client.go | 4 ++-- client/decoders.go | 13 +++---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/client/client.go b/client/client.go index 478e180d..5137eee6 100644 --- a/client/client.go +++ b/client/client.go @@ -76,7 +76,7 @@ type QQClient struct { transCache *utils.Cache lastLostMsg string groupMsgBuilders sync.Map - onlinePushCache []int16 // reset on reconnect + onlinePushCache *utils.Cache requestPacketRequestId int32 groupSeq int32 friendSeq int32 @@ -170,6 +170,7 @@ func NewClientMd5(uin int64, passwordMd5 [16]byte) *QQClient { eventHandlers: &eventHandlers{}, msgSvcCache: utils.NewCache(time.Second * 15), transCache: utils.NewCache(time.Second * 15), + onlinePushCache: utils.NewCache(time.Second * 15), version: genVersionInfo(SystemDeviceInfo.Protocol), servers: []*net.TCPAddr{ // default servers {IP: net.IP{42, 81, 169, 46}, Port: 8080}, @@ -946,7 +947,6 @@ func (c *QQClient) connect() error { c.retryTimes = 0 c.ConnectTime = time.Now() c.Conn = conn - c.onlinePushCache = []int16{} return nil } diff --git a/client/decoders.go b/client/decoders.go index c9cf3dba..aa67ba0d 100644 --- a/client/decoders.go +++ b/client/decoders.go @@ -693,19 +693,12 @@ func decodeOnlinePushReqPacket(c *QQClient, seq uint16, payload []byte) (interfa uin := jr.ReadInt64(0) jr.ReadSlice(&msgInfos, 2) _ = c.send(c.buildDeleteOnlinePushPacket(uin, seq, msgInfos)) - seqExists := func(ms int16) bool { - for _, s := range c.onlinePushCache { - if ms == s { - return true - } - } - return false - } for _, m := range msgInfos { - if seqExists(m.MsgSeq) { + k := fmt.Sprintf("%v%v%v", m.MsgSeq, m.MsgTime, m.MsgUid) + if _, ok := c.onlinePushCache.Get(k); ok { continue } - c.onlinePushCache = append(c.onlinePushCache, m.MsgSeq) + c.onlinePushCache.Add(k, "", time.Second*30) if m.MsgType == 732 { r := binary.NewReader(m.VMsg) groupId := int64(uint32(r.ReadInt32()))