sync
This commit is contained in:
@@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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>>)
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,7 @@ object ChildManager {
|
|||||||
}
|
}
|
||||||
val child = ChildBungee(channel, packet.portRange)
|
val child = ChildBungee(channel, packet.portRange)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user