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 e79faf2..be5b9ab 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 @@ -1,6 +1,7 @@ package cc.maxmc.msm.common.network import cc.maxmc.msm.common.event.PacketReceiveEvent +import cc.maxmc.msm.common.utils.debug import io.netty.channel.ChannelHandler.Sharable import io.netty.channel.ChannelHandlerContext import io.netty.channel.SimpleChannelInboundHandler @@ -8,6 +9,7 @@ import io.netty.channel.SimpleChannelInboundHandler @Sharable object ClusterPacketHandler : SimpleChannelInboundHandler() { override fun channelRead0(ctx: ChannelHandlerContext, msg: BungeePacket) { + debug("call event") PacketReceiveEvent(ctx.channel(), msg).callEvent() } } \ No newline at end of file diff --git a/common/src/main/kotlin/cc/maxmc/msm/common/network/netty/ClusterMsgCodec.kt b/common/src/main/kotlin/cc/maxmc/msm/common/network/netty/ClusterMsgCodec.kt index 8cf8056..f09a3cd 100644 --- a/common/src/main/kotlin/cc/maxmc/msm/common/network/netty/ClusterMsgCodec.kt +++ b/common/src/main/kotlin/cc/maxmc/msm/common/network/netty/ClusterMsgCodec.kt @@ -14,8 +14,11 @@ class ClusterMsgCodec(private val current: NetworkRegistry.PacketDirection) : By } override fun decode(ctx: ChannelHandlerContext, `in`: ByteBuf, out: MutableList) { + debug("decode packet") val id = `in`.readInt() val packet = NetworkRegistry.getPacketByID(current, id) + debug(packet.toString()) packet.decode(`in`) + out.add(packet) } } \ No newline at end of file diff --git a/common/src/main/kotlin/cc/maxmc/msm/common/network/packet/PPacketDebug.kt b/common/src/main/kotlin/cc/maxmc/msm/common/network/packet/PPacketDebug.kt index 3c41a34..d5d2268 100644 --- a/common/src/main/kotlin/cc/maxmc/msm/common/network/packet/PPacketDebug.kt +++ b/common/src/main/kotlin/cc/maxmc/msm/common/network/packet/PPacketDebug.kt @@ -19,6 +19,8 @@ data class PPacketDebug( override fun decode(buf: ByteBuf) { val size = buf.readInt() - content = buf.readBytes(size).array().decodeToString() + val encoded = ByteArray(size) + buf.readBytes(encoded) + content = encoded.decodeToString() } } \ No newline at end of file diff --git a/common/src/main/kotlin/cc/maxmc/msm/common/utils/Netty.kt b/common/src/main/kotlin/cc/maxmc/msm/common/utils/Netty.kt index d267d88..32c6dde 100644 --- a/common/src/main/kotlin/cc/maxmc/msm/common/utils/Netty.kt +++ b/common/src/main/kotlin/cc/maxmc/msm/common/utils/Netty.kt @@ -16,8 +16,8 @@ fun channelInit(initializer: C.() -> Unit): ChannelInitializer } fun pipelineInit(direction: NetworkRegistry.PacketDirection) = channelInit { - pipeline().addLast("frame_prepender", Varint21LengthFieldPrepender()) pipeline().addLast("frame_decoder", Varint21FrameDecoder()) + pipeline().addLast("frame_prepender", Varint21LengthFieldPrepender()) pipeline().addLast("codec", ClusterMsgCodec(direction)) pipeline().addLast("packet_handler", ClusterPacketHandler)