Unified relogin cause

This commit is contained in:
Him188 2020-02-20 21:42:20 +08:00
parent 48682f3090
commit 9437d1528d
4 changed files with 9 additions and 9 deletions

View File

@ -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) {

View File

@ -92,7 +92,7 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
if (tryCount != 0) {
delay(configuration.reconnectPeriodMillis)
}
network.relogin()
network.relogin(event.cause)
logger.info("Reconnected successfully")
return@subscribeAlways
}?.let {

View File

@ -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
}
/**

View File

@ -68,7 +68,7 @@ abstract class BotNetworkHandler : CoroutineScope {
*/
@Suppress("SpellCheckingInspection")
@MiraiInternalAPI
abstract suspend fun relogin()
abstract suspend fun relogin(cause: Throwable? = null)
/**
* 初始化获取好友列表等值.