Skip to content
This repository was archived by the owner on Nov 2, 2023. It is now read-only.

Commit b88f759

Browse files
committed
fix logout
1 parent ef779f8 commit b88f759

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

lib/core/base-client.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,16 @@ export class BaseClient extends EventEmitter {
9696
sig_session: BUF0,
9797
session_key: BUF0,
9898
},
99-
hb480: BUF0,
99+
hb480: (() => {
100+
const buf = Buffer.alloc(9)
101+
buf.writeUInt32BE(this.uin)
102+
buf.writeInt32BE(0x19e39, 5)
103+
return pb.encode({
104+
1: 1152,
105+
2: 9,
106+
4: buf
107+
})
108+
})(),
100109
emp_time: 0,
101110
}
102111
readonly pskey: {[domain: string]: Buffer} = { }
@@ -527,8 +536,6 @@ function ssoListener(this: BaseClient, cmd: string, payload: Buffer, seq: number
527536
case "StatSvc.ReqMSFOffline":
528537
case "MessageSvc.PushForceOffline":
529538
{
530-
this[IS_ONLINE] = false
531-
clearInterval(this[HEARTBEAT])
532539
const nested = jce.decodeWrapper(payload)
533540
const msg = nested[4] ? `[${nested[4]}]${nested[3]}` : `[${nested[1]}]${nested[2]}`
534541
this.emit(EVENT_KICKOFF, msg)
@@ -564,31 +571,14 @@ function onlineListener(this: BaseClient) {
564571
if (!this.listenerCount(EVENT_KICKOFF)) {
565572
this.once(EVENT_KICKOFF, (msg: string) => {
566573
this[IS_ONLINE] = false
574+
clearInterval(this[HEARTBEAT])
567575
this.emit("internal.kickoff", msg)
568576
})
569577
}
570-
const buf = Buffer.alloc(9)
571-
buf.writeUInt32BE(this.uin)
572-
buf.writeInt32BE(0x19e39, 5)
573-
this.sig.hb480 = Buffer.from(pb.encode({
574-
1: 1152,
575-
2: 9,
576-
4: buf
577-
}))
578-
this[HEARTBEAT] = setInterval(async () => {
579-
if (typeof this.heartbeat === "function")
580-
await this.heartbeat()
581-
this.sendUni("OidbSvc.0x480_9_IMCore", this.sig.hb480).catch(() => {
582-
this.emit("internal.verbose", "heartbeat timeout", VerboseLevel.Warn)
583-
this.sendUni("OidbSvc.0x480_9_IMCore", this.sig.hb480).catch(() => {
584-
this.emit("internal.verbose", "heartbeat timeout x 2", VerboseLevel.Error)
585-
this[NET].destroy()
586-
})
587-
}).then(refreshToken.bind(this))
588-
}, this.interval * 1000)
589578
}
590579

591580
function lostListener(this: BaseClient) {
581+
clearInterval(this[HEARTBEAT])
592582
if (this[IS_ONLINE]) {
593583
this[IS_ONLINE] = false
594584
this.statistics.lost_times++
@@ -653,6 +643,8 @@ async function packetListener(this: BaseClient, pkt: Buffer) {
653643
}
654644

655645
async function register(this: BaseClient, logout = false) {
646+
this[IS_ONLINE] = false
647+
clearInterval(this[HEARTBEAT])
656648
const pb_buf = pb.encode({
657649
1: [
658650
{ 1: 46, 2: timestamp() },
@@ -679,15 +671,24 @@ async function register(this: BaseClient, logout = false) {
679671
const rsp = jce.decodeWrapper(payload)
680672
const result = rsp[9] ? true : false
681673
if (!result) {
682-
clearInterval(this[HEARTBEAT])
683674
this.emit("internal.error.token")
684675
} else {
685676
this[IS_ONLINE] = true
677+
this[HEARTBEAT] = setInterval(async () => {
678+
if (typeof this.heartbeat === "function")
679+
await this.heartbeat()
680+
this.sendUni("OidbSvc.0x480_9_IMCore", this.sig.hb480).catch(() => {
681+
this.emit("internal.verbose", "heartbeat timeout", VerboseLevel.Warn)
682+
this.sendUni("OidbSvc.0x480_9_IMCore", this.sig.hb480).catch(() => {
683+
this.emit("internal.verbose", "heartbeat timeout x 2", VerboseLevel.Error)
684+
this[NET].destroy()
685+
})
686+
}).then(refreshToken.bind(this))
687+
}, this.interval * 1000)
686688
}
687689
} catch {
688-
if (logout) return
689-
clearInterval(this[HEARTBEAT])
690-
this.emit("internal.error.network", -3, "server is busy(register)")
690+
if (!logout)
691+
this.emit("internal.error.network", -3, "server is busy(register)")
691692
}
692693
}
693694

@@ -726,7 +727,6 @@ async function refreshToken(this: BaseClient) {
726727
const t = readTlv(stream)
727728
if (type === 0) {
728729
const { token } = decodeT119.call(this, t[0x119])
729-
this[IS_ONLINE] = false
730730
await register.call(this)
731731
if (this[IS_ONLINE])
732732
this.emit("internal.token", token)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "oicq",
3-
"version": "2.1.3",
3+
"version": "2.1.4",
44
"upday": "2021/11/07",
55
"description": "QQ protocol!",
66
"main": "lib/index.js",

0 commit comments

Comments
 (0)