1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-08 04:55:56 +08:00

fix heartbeat.

This commit is contained in:
Mrs4s 2020-09-21 20:11:38 +08:00
parent 249af27463
commit d4f8583488

View File

@ -75,6 +75,7 @@ type QQClient struct {
requestPacketRequestId int32 requestPacketRequestId int32
groupSeq int32 groupSeq int32
friendSeq int32 friendSeq int32
heartbeatEnabled bool
groupDataTransSeq int32 groupDataTransSeq int32
highwayApplyUpSeq int32 highwayApplyUpSeq int32
eventHandlers *eventHandlers eventHandlers *eventHandlers
@ -196,7 +197,9 @@ func (c *QQClient) Login() (*LoginResponse, error) {
if l.Success { if l.Success {
c.lastLostMsg = "" c.lastLostMsg = ""
c.registerClient() c.registerClient()
c.startHeartbeat() if !c.heartbeatEnabled {
c.startHeartbeat()
}
} }
return &l, nil return &l, nil
} }
@ -267,7 +270,9 @@ func (c *QQClient) SubmitCaptcha(result string, sign []byte) (*LoginResponse, er
l := rsp.(LoginResponse) l := rsp.(LoginResponse)
if l.Success { if l.Success {
c.registerClient() c.registerClient()
c.startHeartbeat() if !c.heartbeatEnabled {
c.startHeartbeat()
}
} }
return &l, nil return &l, nil
} }
@ -1069,6 +1074,7 @@ func (c *QQClient) netLoop() {
} }
func (c *QQClient) startHeartbeat() { func (c *QQClient) startHeartbeat() {
c.heartbeatEnabled = true
time.AfterFunc(30*time.Second, c.doHeartbeat) time.AfterFunc(30*time.Second, c.doHeartbeat)
} }
@ -1080,4 +1086,5 @@ func (c *QQClient) doHeartbeat() {
_, _ = c.sendAndWait(seq, packet) _, _ = c.sendAndWait(seq, packet)
time.AfterFunc(30*time.Second, c.doHeartbeat) time.AfterFunc(30*time.Second, c.doHeartbeat)
} }
c.heartbeatEnabled = false
} }