From e652825266d23f6bcf15ba3f5f2c065231c6ed75 Mon Sep 17 00:00:00 2001 From: LXY Date: Fri, 21 Aug 2020 16:51:24 +0800 Subject: [PATCH 1/2] atomic! --- client/client.go | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/client/client.go b/client/client.go index 87cbe674..ef4a18b7 100644 --- a/client/client.go +++ b/client/client.go @@ -38,7 +38,7 @@ type QQClient struct { GroupList []*GroupInfo Online bool - SequenceId uint16 + SequenceId int32 OutGoingPacketSessionId []byte RandomKey []byte Conn net.Conn @@ -77,8 +77,6 @@ type QQClient struct { groupListLock sync.Mutex msgSvcLock sync.Mutex - - seqLock sync.Mutex } type loginSigInfo struct { @@ -825,45 +823,27 @@ func (c *QQClient) registerClient() { } func (c *QQClient) nextSeq() uint16 { - c.seqLock.Lock() - defer c.seqLock.Unlock() - - c.SequenceId++ - c.SequenceId &= 0x7FFF - if c.SequenceId == 0 { - c.SequenceId++ - } - return c.SequenceId + return uint16(atomic.AddInt32(&c.SequenceId, 1) & 0x7FFF) } func (c *QQClient) nextPacketSeq() int32 { - s := atomic.LoadInt32(&c.requestPacketRequestId) - atomic.AddInt32(&c.requestPacketRequestId, 2) - return s + return atomic.AddInt32(&c.requestPacketRequestId, 2) } func (c *QQClient) nextGroupSeq() int32 { - s := atomic.LoadInt32(&c.groupSeq) - atomic.AddInt32(&c.groupSeq, 2) - return s + return atomic.AddInt32(&c.groupSeq, 2) } func (c *QQClient) nextFriendSeq() int32 { - s := atomic.LoadInt32(&c.friendSeq) - atomic.AddInt32(&c.friendSeq, 1) - return s + return atomic.AddInt32(&c.friendSeq, 1) } func (c *QQClient) nextGroupDataTransSeq() int32 { - s := atomic.LoadInt32(&c.groupDataTransSeq) - atomic.AddInt32(&c.groupDataTransSeq, 2) - return s + return atomic.AddInt32(&c.groupDataTransSeq, 2) } func (c *QQClient) nextHighwayApplySeq() int32 { - s := atomic.LoadInt32(&c.highwayApplyUpSeq) - atomic.AddInt32(&c.highwayApplyUpSeq, 2) - return s + return atomic.AddInt32(&c.highwayApplyUpSeq, 2) } func (c *QQClient) send(pkt []byte) error { From f715d1ff8a6fc358cebee6e44cc65ad3107279df Mon Sep 17 00:00:00 2001 From: LXY Date: Fri, 21 Aug 2020 17:24:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=86=97=E4=BD=99split?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/client.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/client.go b/client/client.go index ef4a18b7..0b165aa4 100644 --- a/client/client.go +++ b/client/client.go @@ -182,10 +182,10 @@ func (c *QQClient) GetGroupHonorInfo(groupCode int64, honorType HonorType) (*Gro if err != nil { return nil, err } - rsp := string(b) - data := strings.Split(strings.Split(rsp, `window.__INITIAL_STATE__=`)[1], "")[0] + b = b[bytes.Index(b, []byte(`window.__INITIAL_STATE__=`))+25:] + b = b[:bytes.Index(b, []byte(""))] ret := GroupHonorInfo{} - err = json.Unmarshal([]byte(data), &ret) + err = json.Unmarshal(b, &ret) if err != nil { return nil, err }