From 6854252c7749c0dfb9037a9d2d742bfc5e59436a Mon Sep 17 00:00:00 2001 From: Him188 <Him188@mamoe.net> Date: Tue, 4 May 2021 12:42:32 +0800 Subject: [PATCH] Old network: re-init client on BotOfflineEvent.Force. #1205 for 2.7-M1 --- mirai-core/src/commonMain/kotlin/AbstractBot.kt | 2 ++ mirai-core/src/commonMain/kotlin/QQAndroidBot.kt | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mirai-core/src/commonMain/kotlin/AbstractBot.kt b/mirai-core/src/commonMain/kotlin/AbstractBot.kt index f503112e2..7e2ff38c4 100644 --- a/mirai-core/src/commonMain/kotlin/AbstractBot.kt +++ b/mirai-core/src/commonMain/kotlin/AbstractBot.kt @@ -104,6 +104,7 @@ internal abstract class AbstractBot<N : BotNetworkHandler> constructor( priority = MONITOR, concurrency = ConcurrencyKind.LOCKED ) { event -> + val bot = bot.asQQAndroidBot() if ( !event.bot.isActive // bot closed || !::_network.isInitialized // bot 还未登录就被 close @@ -129,6 +130,7 @@ internal abstract class AbstractBot<N : BotNetworkHandler> constructor( is BotOfflineEvent.Force -> { bot.logger.info { "Connection occupied by another android device: ${event.message}" } bot.asQQAndroidBot().accountSecretsFile.delete() + bot.client = bot.initClient() if (event.reconnect) { bot.logger.info { "Reconnecting..." } // delay(3000) diff --git a/mirai-core/src/commonMain/kotlin/QQAndroidBot.kt b/mirai-core/src/commonMain/kotlin/QQAndroidBot.kt index d65b497a3..a04a24e08 100644 --- a/mirai-core/src/commonMain/kotlin/QQAndroidBot.kt +++ b/mirai-core/src/commonMain/kotlin/QQAndroidBot.kt @@ -122,7 +122,6 @@ internal class QQAndroidBot constructor( /////////////////////////// accounts secrets end var client: QQAndroidClient = initClient() - private set fun initClient(): QQAndroidClient { val device = configuration.deviceInfo?.invoke(this) ?: DeviceInfo.random()