From 503592de11c1803b6ffe53ca6625fdb2a046ebc7 Mon Sep 17 00:00:00 2001 From: Him188 <Him188@mamoe.net> Date: Sun, 24 May 2020 13:10:31 +0800 Subject: [PATCH] Support IPv6, close #334 --- .../network/protocol/packet/login/StatSvc.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/StatSvc.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/StatSvc.kt index 11e0a9912..7242eb1fa 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/StatSvc.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/StatSvc.kt @@ -136,12 +136,9 @@ internal class StatSvc { strDevName = client.device.model.encodeToString(), strDevType = client.device.model.encodeToString(), strOSVer = client.device.version.release.encodeToString(), - uOldSSOIp = 0, - uNewSSOIp = MiraiPlatformUtils.localIpAddress().split(".") - .foldIndexed(0L) { index: Int, acc: Long, s: String -> - acc or ((s.toLong() shl (index * 16))) - }, + uNewSSOIp = MiraiPlatformUtils.localIpAddress().runCatching { ipToLong() } + .getOrElse { "192.168.1.123".ipToLong() }, strVendorName = "MIUI", strVendorOSName = "?ONEPLUS A5000_23_17", // register 时还需要 @@ -173,6 +170,12 @@ 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))) + } + } + override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): Response { return Response }