From 58e22417d8fc322983792b3f11229f29200af580 Mon Sep 17 00:00:00 2001 From: tony_all Date: Thu, 6 Apr 2023 18:28:38 +0800 Subject: [PATCH] sync --- .../cc/maxmc/msm/common/network/ClusterPacketHandler.kt | 6 +++++- .../src/main/kotlin/cc/maxmc/msm/common/utils/Coroutines.kt | 6 ++++-- .../main/kotlin/cc/maxmc/msm/parent/manager/ChildManager.kt | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/common/src/main/kotlin/cc/maxmc/msm/common/network/ClusterPacketHandler.kt b/common/src/main/kotlin/cc/maxmc/msm/common/network/ClusterPacketHandler.kt index f5930ed..fe10f59 100644 --- a/common/src/main/kotlin/cc/maxmc/msm/common/network/ClusterPacketHandler.kt +++ b/common/src/main/kotlin/cc/maxmc/msm/common/network/ClusterPacketHandler.kt @@ -7,12 +7,16 @@ import cc.maxmc.msm.common.utils.awaiting import io.netty.channel.ChannelHandler.Sharable import io.netty.channel.ChannelHandlerContext import io.netty.channel.SimpleChannelInboundHandler +import kotlin.coroutines.resume @Sharable object ClusterPacketHandler : SimpleChannelInboundHandler() { override fun channelRead0(ctx: ChannelHandlerContext, msg: BungeePacket) { awaiting.filter { it.first == msg::class.java } - . + .filter { it.second(ctx.channel(), msg) } + .forEach { + it.third.resume(msg) + } PacketReceiveEvent(ctx.channel(), msg).callEvent() } diff --git a/common/src/main/kotlin/cc/maxmc/msm/common/utils/Coroutines.kt b/common/src/main/kotlin/cc/maxmc/msm/common/utils/Coroutines.kt index 08ad567..32ea66c 100644 --- a/common/src/main/kotlin/cc/maxmc/msm/common/utils/Coroutines.kt +++ b/common/src/main/kotlin/cc/maxmc/msm/common/utils/Coroutines.kt @@ -13,10 +13,12 @@ val pluginScope = CoroutineScope(SupervisorJob() + CoroutineExceptionHandler { _ except.printStackTrace() }) -val awaiting = ArrayList, (BungeePacket) -> Boolean, Continuation>>() +val awaiting = + ArrayList, (Channel, BungeePacket) -> Boolean, Continuation>>() + suspend inline fun awaitPacket(packetClass: Class, noinline filter: (Channel, T) -> Boolean) = suspendCoroutine { val triple = Triple(packetClass, filter, it) @Suppress("UNCHECKED_CAST") - awaiting.add(triple as Triple, (BungeePacket) -> Boolean, Continuation>) + awaiting.add(triple as Triple, (Channel, BungeePacket) -> Boolean, Continuation>) } \ No newline at end of file diff --git a/parent/src/main/kotlin/cc/maxmc/msm/parent/manager/ChildManager.kt b/parent/src/main/kotlin/cc/maxmc/msm/parent/manager/ChildManager.kt index e8ae81e..1966414 100644 --- a/parent/src/main/kotlin/cc/maxmc/msm/parent/manager/ChildManager.kt +++ b/parent/src/main/kotlin/cc/maxmc/msm/parent/manager/ChildManager.kt @@ -22,6 +22,7 @@ object ChildManager { } val child = ChildBungee(channel, packet.portRange) + } }