From 7739c4db801a4d4b0f4c10f58233b119e8e7607a Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 6 Jun 2021 13:51:18 +0800 Subject: [PATCH] Close network in MessageSvcPushForceOffline properly by throwing ServerClosedException --- .../network/impl/netty/ServerClosedException.kt | 17 +++++++++++++++++ .../chat/receive/MessageSvc.PushForceOffline.kt | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 mirai-core/src/commonMain/kotlin/network/impl/netty/ServerClosedException.kt diff --git a/mirai-core/src/commonMain/kotlin/network/impl/netty/ServerClosedException.kt b/mirai-core/src/commonMain/kotlin/network/impl/netty/ServerClosedException.kt new file mode 100644 index 000000000..0fb95b459 --- /dev/null +++ b/mirai-core/src/commonMain/kotlin/network/impl/netty/ServerClosedException.kt @@ -0,0 +1,17 @@ +/* + * Copyright 2019-2021 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +package net.mamoe.mirai.internal.network.impl.netty + +import net.mamoe.mirai.internal.network.handler.selector.NetworkException + +internal data class ServerClosedException( + override val message: String? = null, + override val cause: Throwable? = null +) : NetworkException(true) \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/MessageSvc.PushForceOffline.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/MessageSvc.PushForceOffline.kt index 0d45832e0..8dd787c55 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/MessageSvc.PushForceOffline.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/MessageSvc.PushForceOffline.kt @@ -12,6 +12,7 @@ package net.mamoe.mirai.internal.network.protocol.packet.chat.receive import kotlinx.io.core.ByteReadPacket import net.mamoe.mirai.event.events.BotOfflineEvent import net.mamoe.mirai.internal.QQAndroidBot +import net.mamoe.mirai.internal.network.impl.netty.ServerClosedException import net.mamoe.mirai.internal.network.protocol.data.jce.RequestPushForceOffline import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketFactory import net.mamoe.mirai.internal.utils.io.serialization.readUniPacket @@ -29,6 +30,6 @@ internal object MessageSvcPushForceOffline : } override suspend fun QQAndroidBot.handle(packet: BotOfflineEvent.Force) { - network.close(IllegalStateException("Closed by MessageSvc.PushForceOffline: $packet")) + network.close(ServerClosedException("Closed by MessageSvc.PushForceOffline: $packet")) } }