finish network
This commit is contained in:
parent
2abf1bb7df
commit
0ee45b6179
|
|
@ -1,6 +1,7 @@
|
||||||
package cc.maxmc.msm.common.network
|
package cc.maxmc.msm.common.network
|
||||||
|
|
||||||
import cc.maxmc.msm.common.event.PacketReceiveEvent
|
import cc.maxmc.msm.common.event.PacketReceiveEvent
|
||||||
|
import cc.maxmc.msm.common.utils.debug
|
||||||
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
|
||||||
|
|
@ -8,6 +9,7 @@ import io.netty.channel.SimpleChannelInboundHandler
|
||||||
@Sharable
|
@Sharable
|
||||||
object ClusterPacketHandler : SimpleChannelInboundHandler<BungeePacket>() {
|
object ClusterPacketHandler : SimpleChannelInboundHandler<BungeePacket>() {
|
||||||
override fun channelRead0(ctx: ChannelHandlerContext, msg: BungeePacket) {
|
override fun channelRead0(ctx: ChannelHandlerContext, msg: BungeePacket) {
|
||||||
|
debug("call event")
|
||||||
PacketReceiveEvent(ctx.channel(), msg).callEvent()
|
PacketReceiveEvent(ctx.channel(), msg).callEvent()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -14,8 +14,11 @@ class ClusterMsgCodec(private val current: NetworkRegistry.PacketDirection) : By
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun decode(ctx: ChannelHandlerContext, `in`: ByteBuf, out: MutableList<Any>) {
|
override fun decode(ctx: ChannelHandlerContext, `in`: ByteBuf, out: MutableList<Any>) {
|
||||||
|
debug("decode packet")
|
||||||
val id = `in`.readInt()
|
val id = `in`.readInt()
|
||||||
val packet = NetworkRegistry.getPacketByID(current, id)
|
val packet = NetworkRegistry.getPacketByID(current, id)
|
||||||
|
debug(packet.toString())
|
||||||
packet.decode(`in`)
|
packet.decode(`in`)
|
||||||
|
out.add(packet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -19,6 +19,8 @@ data class PPacketDebug(
|
||||||
|
|
||||||
override fun decode(buf: ByteBuf) {
|
override fun decode(buf: ByteBuf) {
|
||||||
val size = buf.readInt()
|
val size = buf.readInt()
|
||||||
content = buf.readBytes(size).array().decodeToString()
|
val encoded = ByteArray(size)
|
||||||
|
buf.readBytes(encoded)
|
||||||
|
content = encoded.decodeToString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16,8 +16,8 @@ fun <C : Channel> channelInit(initializer: C.() -> Unit): ChannelInitializer<C>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pipelineInit(direction: NetworkRegistry.PacketDirection) = channelInit<SocketChannel> {
|
fun pipelineInit(direction: NetworkRegistry.PacketDirection) = channelInit<SocketChannel> {
|
||||||
pipeline().addLast("frame_prepender", Varint21LengthFieldPrepender())
|
|
||||||
pipeline().addLast("frame_decoder", Varint21FrameDecoder())
|
pipeline().addLast("frame_decoder", Varint21FrameDecoder())
|
||||||
|
pipeline().addLast("frame_prepender", Varint21LengthFieldPrepender())
|
||||||
pipeline().addLast("codec", ClusterMsgCodec(direction))
|
pipeline().addLast("codec", ClusterMsgCodec(direction))
|
||||||
pipeline().addLast("packet_handler", ClusterPacketHandler)
|
pipeline().addLast("packet_handler", ClusterPacketHandler)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue