From 915e096cc2db4777e7926752a7ebc9adc51639eb Mon Sep 17 00:00:00 2001 From: Him188 Date: Wed, 10 Feb 2021 15:27:50 +0800 Subject: [PATCH] Switch server when neither new bdh session nor cached one found, fix #1001 --- .../handler/QQAndroidBotNetworkHandler.kt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/network/handler/QQAndroidBotNetworkHandler.kt b/mirai-core/src/commonMain/kotlin/network/handler/QQAndroidBotNetworkHandler.kt index 8d40ffd75..f3ed11327 100644 --- a/mirai-core/src/commonMain/kotlin/network/handler/QQAndroidBotNetworkHandler.kt +++ b/mirai-core/src/commonMain/kotlin/network/handler/QQAndroidBotNetworkHandler.kt @@ -293,9 +293,9 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo // return null // } // }.buildOutgoingUniPacket(bot.client) {}.sendWithoutExpect() - // kotlin.runCatching { - // StatSvc.Register.offline(bot.client).sendAndExpect() - // }.getOrElse { logger.warning(it) } + // kotlin.runCatching { + // StatSvc.Register.offline(bot.client).sendAndExpect() + // }.getOrElse { logger.warning(it) } return StatSvc.Register.online(bot.client).sendAndExpect() } @@ -336,7 +336,10 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo val registerResp = registerClientOnline() - this@QQAndroidBotNetworkHandler.launch(CoroutineName("Awaiting ConfigPushSvc.PushReq"), block= ConfigPushSyncer()) + this@QQAndroidBotNetworkHandler.launch( + CoroutineName("Awaiting ConfigPushSvc.PushReq"), + block = ConfigPushSyncer() + ) launch { syncMessageSvc() @@ -354,7 +357,7 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo postInitActions() } - @Suppress("FunctionName") + @Suppress("FunctionName", "UNUSED_VARIABLE") private fun BotNetworkHandler.ConfigPushSyncer(): suspend CoroutineScope.() -> Unit = launch@{ logger.info { "Awaiting ConfigPushSvc.PushReq." } when (val resp: ConfigPushSvc.PushReq.PushReqResponse? = nextEventOrNull(20_000)) { @@ -362,7 +365,8 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo val hasSession = bot.bdhSyncer.hasSession kotlin.runCatching { bot.bdhSyncer.bdhSession.completeExceptionally(CancellationException("Timeout waiting for ConfigPushSvc.PushReq")) } if (!hasSession) { - logger.warning { "Missing ConfigPushSvc.PushReq. File uploading may be affected." } + logger.warning { "Missing ConfigPushSvc.PushReq. Switching server..." } + bot.launch { BotOfflineEvent.RequireReconnect(bot).broadcast() } } else { logger.warning { "Missing ConfigPushSvc.PushReq. Using latest response. File uploading may be affected." } }