From 4b25900ab8ac2ff324761f12496830af5d6e5a38 Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 11 Sep 2020 23:39:19 +0800 Subject: [PATCH] Drop bad servers on failure, fix #589 --- .../kotlin/net/mamoe/mirai/qqandroid/BotImpl.kt | 4 +++- .../mamoe/mirai/qqandroid/network/QQAndroidClient.kt | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/BotImpl.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/BotImpl.kt index ed1ac5788..b3adda8a6 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/BotImpl.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/BotImpl.kt @@ -89,7 +89,9 @@ internal abstract class BotImpl constructor( // normally closed return@subscribeAlways } - bot.logger.info { "Connection dropped by server or lost, retrying login" } + bot.logger.info { "Connection lost, retrying login" } + + bot.asQQAndroidBot().client.serverList.removeAt(0) var failed = false val time = measureTime { diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt index 40d48e8ec..129372531 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt @@ -46,14 +46,14 @@ private fun generateGuid(androidId: ByteArray, macAddress: ByteArray): ByteArray internal fun getRandomByteArray(length: Int): ByteArray = ByteArray(length) { Random.nextInt(0, 255).toByte() } internal object DefaultServerList : Set> by setOf( - "msfwifi.3g.qq.com" to 8080, "42.81.169.46" to 8080, "42.81.172.81" to 80, "114.221.148.59" to 14000, "42.81.172.147" to 443, "125.94.60.146" to 80, "114.221.144.215" to 80, - "42.81.172.22" to 80 + "42.81.172.22" to 80, + "msfwifi.3g.qq.com" to 8080, ) /* @@ -130,7 +130,7 @@ internal open class QQAndroidClient( internal suspend inline fun useNextServers(crossinline block: suspend (host: String, port: Int) -> Unit) { if (bot.client.serverList.isEmpty()) { - throw NoServerAvailableException(null) + bot.client.serverList.addAll(DefaultServerList) } retryCatching(bot.client.serverList.size, except = LoginFailedException::class) { val pair = bot.client.serverList[0] @@ -159,8 +159,8 @@ internal open class QQAndroidClient( var openAppId: Long = 715019303L - val apkVersionName: ByteArray get() = "8.2.7".toByteArray() - val buildVer: String get() = "8.2.7.4410" // 8.2.0.1296 + val apkVersionName: ByteArray get() = "8.4.8".toByteArray() + val buildVer: String get() = "8.4.8.4810" // 8.2.0.1296 // 8.4.8.4810 // 8.2.7.4410 private val messageSequenceId: AtomicInt = atomic(22911) internal fun atomicNextMessageSequenceId(): Int = messageSequenceId.getAndAdd(2)