mirror of
https://github.com/mamoe/mirai.git
synced 2025-04-01 04:10:12 +08:00
Unified relogin cause
This commit is contained in:
parent
48682f3090
commit
9437d1528d
@ -76,7 +76,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
|||||||
return@launch
|
return@launch
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
if (this@QQAndroidBotNetworkHandler.isActive) {
|
if (this@QQAndroidBotNetworkHandler.isActive) {
|
||||||
BotOfflineEvent.Dropped(bot).broadcast()
|
BotOfflineEvent.Dropped(bot, e).broadcast()
|
||||||
}
|
}
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
@ -96,15 +96,15 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
|||||||
val failException = doHeartBeat()
|
val failException = doHeartBeat()
|
||||||
if (failException != null) {
|
if (failException != null) {
|
||||||
delay(bot.configuration.firstReconnectDelayMillis)
|
delay(bot.configuration.firstReconnectDelayMillis)
|
||||||
close()
|
close(failException)
|
||||||
BotOfflineEvent.Dropped(bot).broadcast()
|
BotOfflineEvent.Dropped(bot, failException).broadcast()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.also { heartbeatJob = it }
|
}.also { heartbeatJob = it }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun relogin() {
|
override suspend fun relogin(cause: Throwable?) {
|
||||||
heartbeatJob?.cancel(CancellationException("relogin"))
|
heartbeatJob?.cancel(CancellationException("relogin", cause))
|
||||||
if (::channel.isInitialized) {
|
if (::channel.isInitialized) {
|
||||||
if (channel.isOpen) {
|
if (channel.isOpen) {
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
@ -119,7 +119,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
|||||||
withTimeoutOrNull(3000) {
|
withTimeoutOrNull(3000) {
|
||||||
channel.connect("113.96.13.208", 8080)
|
channel.connect("113.96.13.208", 8080)
|
||||||
} ?: error("timeout connecting server")
|
} ?: error("timeout connecting server")
|
||||||
startPacketReceiverJobOrKill(CancellationException("reconnect"))
|
startPacketReceiverJobOrKill(CancellationException("relogin", cause))
|
||||||
|
|
||||||
var response: WtLogin.Login.LoginPacketResponse = WtLogin.Login.SubCommand9(bot.client).sendAndExpect()
|
var response: WtLogin.Login.LoginPacketResponse = WtLogin.Login.SubCommand9(bot.client).sendAndExpect()
|
||||||
mainloop@ while (true) {
|
mainloop@ while (true) {
|
||||||
|
@ -92,7 +92,7 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
|
|||||||
if (tryCount != 0) {
|
if (tryCount != 0) {
|
||||||
delay(configuration.reconnectPeriodMillis)
|
delay(configuration.reconnectPeriodMillis)
|
||||||
}
|
}
|
||||||
network.relogin()
|
network.relogin(event.cause)
|
||||||
logger.info("Reconnected successfully")
|
logger.info("Reconnected successfully")
|
||||||
return@subscribeAlways
|
return@subscribeAlways
|
||||||
}?.let {
|
}?.let {
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +68,7 @@ abstract class BotNetworkHandler : CoroutineScope {
|
|||||||
*/
|
*/
|
||||||
@Suppress("SpellCheckingInspection")
|
@Suppress("SpellCheckingInspection")
|
||||||
@MiraiInternalAPI
|
@MiraiInternalAPI
|
||||||
abstract suspend fun relogin()
|
abstract suspend fun relogin(cause: Throwable? = null)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化获取好友列表等值.
|
* 初始化获取好友列表等值.
|
||||||
|
Loading…
Reference in New Issue
Block a user