mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-08 17:20:11 +08:00
Update StatSvc.register, do unregister before register to help PC clients
This commit is contained in:
parent
06e58c50a1
commit
8c88f0e44f
@ -303,7 +303,16 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo
|
||||
}
|
||||
|
||||
private suspend fun registerClientOnline() {
|
||||
StatSvc.Register(bot.client).sendAndExpect<StatSvc.Register.Response>()
|
||||
// object : OutgoingPacketFactory<Packet?>("push.proxyUnRegister") {
|
||||
// override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): Packet? {
|
||||
// return null
|
||||
// }
|
||||
// }.buildOutgoingUniPacket(bot.client) {}.sendWithoutExpect()
|
||||
kotlin.runCatching {
|
||||
StatSvc.Register.offline(bot.client).sendAndExpect()
|
||||
}.getOrElse { logger.warning(it) }
|
||||
|
||||
StatSvc.Register.online(bot.client).sendAndExpect()
|
||||
}
|
||||
|
||||
private suspend fun updateOtherClientsList() {
|
||||
|
@ -17,6 +17,7 @@ import kotlinx.io.core.ByteReadPacket
|
||||
import kotlinx.serialization.protobuf.ProtoBuf
|
||||
import net.mamoe.mirai.Mirai
|
||||
import net.mamoe.mirai.contact.ClientKind
|
||||
import net.mamoe.mirai.data.OnlineStatus
|
||||
import net.mamoe.mirai.event.events.BotOfflineEvent
|
||||
import net.mamoe.mirai.event.events.OtherClientOfflineEvent
|
||||
import net.mamoe.mirai.event.events.OtherClientOnlineEvent
|
||||
@ -36,7 +37,6 @@ import net.mamoe.mirai.internal.utils._miraiContentToString
|
||||
import net.mamoe.mirai.internal.utils.io.serialization.*
|
||||
import net.mamoe.mirai.utils.currentTimeMillis
|
||||
import net.mamoe.mirai.utils.encodeToString
|
||||
import net.mamoe.mirai.utils.localIpAddress
|
||||
import net.mamoe.mirai.utils.toReadPacket
|
||||
|
||||
@Suppress("EnumEntryName", "unused")
|
||||
@ -113,10 +113,22 @@ internal class StatSvc {
|
||||
return Response
|
||||
}
|
||||
|
||||
operator fun invoke(
|
||||
fun online(
|
||||
client: QQAndroidClient,
|
||||
regPushReason: RegPushReason = RegPushReason.appRegister
|
||||
): OutgoingPacket = buildLoginOutgoingPacket(
|
||||
) = impl(client, 1 or 2 or 4, client.onlineStatus, regPushReason)
|
||||
|
||||
fun offline(
|
||||
client: QQAndroidClient,
|
||||
regPushReason: RegPushReason = RegPushReason.appRegister
|
||||
) = impl(client, 0, OnlineStatus.OFFLINE, regPushReason)
|
||||
|
||||
private fun impl(
|
||||
client: QQAndroidClient,
|
||||
bid: Long,
|
||||
status: OnlineStatus,
|
||||
regPushReason: RegPushReason = RegPushReason.appRegister
|
||||
) = buildLoginOutgoingPacket(
|
||||
client,
|
||||
bodyType = 1,
|
||||
extraData = client.wLoginSigInfo.d2.data,
|
||||
@ -137,14 +149,14 @@ internal class StatSvc {
|
||||
SvcReqRegister.serializer(),
|
||||
SvcReqRegister(
|
||||
cConnType = 0,
|
||||
lBid = 1 or 2 or 4,
|
||||
lBid = bid,
|
||||
lUin = client.uin,
|
||||
iStatus = client.onlineStatus.id,
|
||||
iStatus = status.id,
|
||||
bKikPC = 0, // 是否把 PC 踢下线
|
||||
bKikWeak = 0,
|
||||
timeStamp = 0,
|
||||
// timeStamp = currentTimeSeconds // millis or seconds??
|
||||
iLargeSeq = 1551, // ?
|
||||
iLargeSeq = 0, // ?
|
||||
bOpenPush = 1,
|
||||
iLocaleID = 2052,
|
||||
bRegType =
|
||||
@ -161,8 +173,7 @@ internal class StatSvc {
|
||||
strDevType = client.device.model.encodeToString(),
|
||||
strOSVer = client.device.version.release.encodeToString(),
|
||||
uOldSSOIp = 0,
|
||||
uNewSSOIp = localIpAddress().runCatching { ipToLong() }
|
||||
.getOrElse { "192.168.1.123".ipToLong() },
|
||||
uNewSSOIp = 0,
|
||||
strVendorName = "MIUI",
|
||||
strVendorOSName = "?ONEPLUS A5000_23_17",
|
||||
// register 时还需要
|
||||
@ -177,7 +188,7 @@ internal class StatSvc {
|
||||
configList = listOf(
|
||||
Oidb0x769.ConfigSeq(
|
||||
type = 46,
|
||||
version = 0
|
||||
version = 1610538309
|
||||
),
|
||||
Oidb0x769.ConfigSeq(
|
||||
type = 283,
|
||||
@ -194,6 +205,7 @@ internal class StatSvc {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun String.ipToLong(): Long {
|
||||
return split('.').foldIndexed(0L) { index: Int, acc: Long, s: String ->
|
||||
acc or (((s.toLongOrNull() ?: 0) shl (index * 16)))
|
||||
|
Loading…
Reference in New Issue
Block a user