Search in sources :

Example 1 with PacketDecoder

use of com.github.dirtpowered.dirtmv.network.server.codec.PacketDecoder in project DirtMultiversion by DirtPowered.

the class DetectionHandler method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object object) {
    ByteBuf buffer = (ByteBuf) object;
    try {
        short packetId = buffer.readUnsignedByte();
        if (packetId != 0x02 && packetId != 0xFE) {
            ctx.channel().pipeline().addAfter(ChannelConstants.DETECTION_HANDLER, ChannelConstants.NETTY_LENGTH_DECODER, new VarIntFrameDecoder()).addAfter(ChannelConstants.NETTY_LENGTH_DECODER, ChannelConstants.NETTY_LENGTH_ENCODER, new VarIntFrameEncoder()).addAfter(ChannelConstants.NETTY_LENGTH_ENCODER, ChannelConstants.NETTY_PACKET_DECODER, new NettyPacketDecoder(main, userData, PacketDirection.TO_SERVER)).addAfter(ChannelConstants.NETTY_PACKET_DECODER, ChannelConstants.NETTY_PACKET_ENCODER, new NettyPacketEncoder());
            if (main.getConfiguration().enableViaVersion()) {
                UserConnection userConnection = new UserConnectionImpl(ctx.channel());
                new ProtocolPipelineImpl(userConnection);
                ctx.channel().pipeline().addBefore(ChannelConstants.NETTY_PACKET_DECODER, ChannelConstants.VIA_DECODER, new ViaDecodeHandler(userConnection));
                ctx.channel().pipeline().addBefore(ChannelConstants.NETTY_PACKET_DECODER, ChannelConstants.VIA_ENCODER, new ViaEncodeHandler(userConnection));
            }
        } else {
            ctx.channel().pipeline().addAfter(ChannelConstants.DETECTION_HANDLER, ChannelConstants.LEGACY_PING, new LegacyPingVersionHandler(userData)).addAfter(ChannelConstants.LEGACY_PING, ChannelConstants.LEGACY_DECODER, new PacketDecoder(main, PacketDirection.TO_SERVER, userData)).addAfter(ChannelConstants.LEGACY_DECODER, ChannelConstants.LEGACY_ENCODER, new PacketEncoder());
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        buffer.resetReaderIndex();
        ctx.channel().pipeline().remove(this);
        ctx.fireChannelRead(object);
    }
}
Also used : PacketEncoder(com.github.dirtpowered.dirtmv.network.server.codec.PacketEncoder) ViaDecodeHandler(com.github.dirtpowered.dirtmv.viaversion.handler.ViaDecodeHandler) ProtocolPipelineImpl(com.viaversion.viaversion.protocol.ProtocolPipelineImpl) PacketDecoder(com.github.dirtpowered.dirtmv.network.server.codec.PacketDecoder) ViaEncodeHandler(com.github.dirtpowered.dirtmv.viaversion.handler.ViaEncodeHandler) ByteBuf(io.netty.buffer.ByteBuf) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) UserConnectionImpl(com.viaversion.viaversion.connection.UserConnectionImpl) LegacyPingVersionHandler(com.github.dirtpowered.dirtmv.network.server.codec.LegacyPingVersionHandler)

Aggregations

LegacyPingVersionHandler (com.github.dirtpowered.dirtmv.network.server.codec.LegacyPingVersionHandler)1 PacketDecoder (com.github.dirtpowered.dirtmv.network.server.codec.PacketDecoder)1 PacketEncoder (com.github.dirtpowered.dirtmv.network.server.codec.PacketEncoder)1 ViaDecodeHandler (com.github.dirtpowered.dirtmv.viaversion.handler.ViaDecodeHandler)1 ViaEncodeHandler (com.github.dirtpowered.dirtmv.viaversion.handler.ViaEncodeHandler)1 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)1 UserConnectionImpl (com.viaversion.viaversion.connection.UserConnectionImpl)1 ProtocolPipelineImpl (com.viaversion.viaversion.protocol.ProtocolPipelineImpl)1 ByteBuf (io.netty.buffer.ByteBuf)1