diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt index af8165357..4746a5fff 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt @@ -76,7 +76,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler return@launch } catch (e: Throwable) { if (this@QQAndroidBotNetworkHandler.isActive) { - BotOfflineEvent.Dropped(bot).broadcast() + BotOfflineEvent.Dropped(bot, e).broadcast() } return@launch } @@ -96,15 +96,15 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler val failException = doHeartBeat() if (failException != null) { delay(bot.configuration.firstReconnectDelayMillis) - close() - BotOfflineEvent.Dropped(bot).broadcast() + close(failException) + BotOfflineEvent.Dropped(bot, failException).broadcast() } } }.also { heartbeatJob = it } } - override suspend fun relogin() { - heartbeatJob?.cancel(CancellationException("relogin")) + override suspend fun relogin(cause: Throwable?) { + heartbeatJob?.cancel(CancellationException("relogin", cause)) if (::channel.isInitialized) { if (channel.isOpen) { kotlin.runCatching { @@ -119,7 +119,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler withTimeoutOrNull(3000) { channel.connect("113.96.13.208", 8080) } ?: error("timeout connecting server") - startPacketReceiverJobOrKill(CancellationException("reconnect")) + startPacketReceiverJobOrKill(CancellationException("relogin", cause)) var response: WtLogin.Login.LoginPacketResponse = WtLogin.Login.SubCommand9(bot.client).sendAndExpect() mainloop@ while (true) { diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt index 66ffdd235..4f6fc0f8a 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt @@ -92,7 +92,7 @@ abstract class BotImpl constructor( if (tryCount != 0) { delay(configuration.reconnectPeriodMillis) } - network.relogin() + network.relogin(event.cause) logger.info("Reconnected successfully") return@subscribeAlways }?.let { diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt index a855e40b2..0deab64d0 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt @@ -57,7 +57,7 @@ sealed class BotOfflineEvent : BotEvent { /** * 被服务器断开或因网络问题而掉线 */ - data class Dropped(override val bot: Bot) : BotOfflineEvent(), Packet, BotPassiveEvent + data class Dropped(override val bot: Bot, val cause: Throwable?) : BotOfflineEvent(), Packet, BotPassiveEvent } /** diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt index 66e4a544e..b2f36d33b 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/BotNetworkHandler.kt @@ -68,7 +68,7 @@ abstract class BotNetworkHandler : CoroutineScope { */ @Suppress("SpellCheckingInspection") @MiraiInternalAPI - abstract suspend fun relogin() + abstract suspend fun relogin(cause: Throwable? = null) /** * 初始化获取好友列表等值.