This commit is contained in:
tony_all 2023-04-06 18:28:38 +08:00
parent 5681164469
commit 58e22417d8
3 changed files with 10 additions and 3 deletions

View File

@ -7,12 +7,16 @@ import cc.maxmc.msm.common.utils.awaiting
import io.netty.channel.ChannelHandler.Sharable import io.netty.channel.ChannelHandler.Sharable
import io.netty.channel.ChannelHandlerContext import io.netty.channel.ChannelHandlerContext
import io.netty.channel.SimpleChannelInboundHandler import io.netty.channel.SimpleChannelInboundHandler
import kotlin.coroutines.resume
@Sharable @Sharable
object ClusterPacketHandler : SimpleChannelInboundHandler<BungeePacket>() { object ClusterPacketHandler : SimpleChannelInboundHandler<BungeePacket>() {
override fun channelRead0(ctx: ChannelHandlerContext, msg: BungeePacket) { override fun channelRead0(ctx: ChannelHandlerContext, msg: BungeePacket) {
awaiting.filter { it.first == msg::class.java } awaiting.filter { it.first == msg::class.java }
. .filter { it.second(ctx.channel(), msg) }
.forEach {
it.third.resume(msg)
}
PacketReceiveEvent(ctx.channel(), msg).callEvent() PacketReceiveEvent(ctx.channel(), msg).callEvent()
} }

View File

@ -13,10 +13,12 @@ val pluginScope = CoroutineScope(SupervisorJob() + CoroutineExceptionHandler { _
except.printStackTrace() except.printStackTrace()
}) })
val awaiting = ArrayList<Triple<Class<out BungeePacket>, (BungeePacket) -> Boolean, Continuation<BungeePacket>>>() val awaiting =
ArrayList<Triple<Class<out BungeePacket>, (Channel, BungeePacket) -> Boolean, Continuation<BungeePacket>>>()
suspend inline fun <T : BungeePacket> awaitPacket(packetClass: Class<T>, noinline filter: (Channel, T) -> Boolean) = suspend inline fun <T : BungeePacket> awaitPacket(packetClass: Class<T>, noinline filter: (Channel, T) -> Boolean) =
suspendCoroutine<T> { suspendCoroutine<T> {
val triple = Triple(packetClass, filter, it) val triple = Triple(packetClass, filter, it)
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
awaiting.add(triple as Triple<Class<out BungeePacket>, (BungeePacket) -> Boolean, Continuation<BungeePacket>>) awaiting.add(triple as Triple<Class<out BungeePacket>, (Channel, BungeePacket) -> Boolean, Continuation<BungeePacket>>)
} }

View File

@ -22,6 +22,7 @@ object ChildManager {
} }
val child = ChildBungee(channel, packet.portRange) val child = ChildBungee(channel, packet.portRange)
} }
} }