mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-31 03:22:36 +08:00
Kill bot on returnCode <=-10000, fix #691
This commit is contained in:
parent
79242ed483
commit
d51b268c15
@ -73,7 +73,8 @@ public sealed class BotOfflineEvent : BotEvent, AbstractEvent() {
|
||||
* 因 returnCode = -10008 等原因掉线
|
||||
*/
|
||||
@MiraiInternalApi("This is very experimental and might be changed")
|
||||
public data class PacketFactory10008 internal constructor(
|
||||
public data class PacketFactoryErrorCode internal constructor(
|
||||
val returnCode: Int,
|
||||
public override val bot: Bot,
|
||||
public override val cause: Throwable
|
||||
) : BotOfflineEvent(), Packet, BotPassiveEvent, CauseAware
|
||||
|
@ -103,7 +103,7 @@ internal abstract class AbstractBot<N : BotNetworkHandler> constructor(
|
||||
is BotOfflineEvent.MsfOffline,
|
||||
is BotOfflineEvent.Dropped,
|
||||
is BotOfflineEvent.RequireReconnect,
|
||||
is BotOfflineEvent.PacketFactory10008
|
||||
is BotOfflineEvent.PacketFactoryErrorCode
|
||||
-> {
|
||||
if (!_network.isActive) {
|
||||
// normally closed
|
||||
|
@ -30,7 +30,7 @@ import net.mamoe.mirai.internal.contact.*
|
||||
import net.mamoe.mirai.internal.network.protocol.data.jce.StTroopNum
|
||||
import net.mamoe.mirai.internal.network.protocol.data.proto.MsgSvc
|
||||
import net.mamoe.mirai.internal.network.protocol.packet.*
|
||||
import net.mamoe.mirai.internal.network.protocol.packet.KnownPacketFactories.PacketFactoryIllegalState10008Exception
|
||||
import net.mamoe.mirai.internal.network.protocol.packet.KnownPacketFactories.PacketFactoryIllegalStateException
|
||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.GroupInfoImpl
|
||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.receive.MessageSvcPbGetMsg
|
||||
import net.mamoe.mirai.internal.network.protocol.packet.list.FriendList
|
||||
@ -443,9 +443,9 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo
|
||||
input.use {
|
||||
try {
|
||||
parsePacket(it)
|
||||
} catch (e: PacketFactoryIllegalState10008Exception) {
|
||||
} catch (e: PacketFactoryIllegalStateException) {
|
||||
logger.warning { "Network force offline: ${e.message}" }
|
||||
bot.launch { BotOfflineEvent.PacketFactory10008(bot, e).broadcast() }
|
||||
bot.launch { BotOfflineEvent.PacketFactoryErrorCode(e.code, bot, e).broadcast() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -173,7 +173,8 @@ internal object KnownPacketFactories {
|
||||
?: IncomingFactories.firstOrNull { it.receivingCommandName == commandName }
|
||||
}
|
||||
|
||||
class PacketFactoryIllegalState10008Exception @JvmOverloads constructor(
|
||||
class PacketFactoryIllegalStateException @JvmOverloads constructor(
|
||||
val code: Int,
|
||||
override val message: String? = null,
|
||||
override val cause: Throwable? = null
|
||||
) : RuntimeException()
|
||||
@ -310,8 +311,9 @@ internal object KnownPacketFactories {
|
||||
|
||||
val returnCode = readInt()
|
||||
check(returnCode == 0) {
|
||||
if (returnCode == -10008) { // https://github.com/mamoe/mirai/issues/470
|
||||
throw PacketFactoryIllegalState10008Exception("returnCode = $returnCode")
|
||||
if (returnCode <= -10000) {
|
||||
// https://github.com/mamoe/mirai/issues/470
|
||||
throw PacketFactoryIllegalStateException(returnCode, "returnCode = $returnCode")
|
||||
} else "returnCode = $returnCode"
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user