Search in sources :

Example 1 with PacketInput

use of com.github.dirtpowered.dirtmv.data.protocol.io.model.PacketInput in project DirtMultiversion by DirtPowered.

the class PacketDecoder method decode.

@Override
protected void decode(ChannelHandlerContext context, ByteBuf buffer, List<Object> list) throws IOException {
    boolean flag = packetDirection == PacketDirection.TO_CLIENT;
    setUserProtocol(flag, buffer);
    PacketInput inputBuffer = new NettyInputWrapper(buffer);
    PacketData packet = PacketUtil.readPacket(flag ? main.getConfiguration().getServerVersion() : userData.getClientVersion(), inputBuffer);
    setProtocolState(packet);
    list.add(packet);
}
Also used : PacketInput(com.github.dirtpowered.dirtmv.data.protocol.io.model.PacketInput) NettyInputWrapper(com.github.dirtpowered.dirtmv.data.protocol.io.NettyInputWrapper) PacketData(com.github.dirtpowered.dirtmv.data.protocol.PacketData)

Example 2 with PacketInput

use of com.github.dirtpowered.dirtmv.data.protocol.io.model.PacketInput in project DirtMultiversion by DirtPowered.

the class NettyPacketDecoder method decode.

@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
    if (byteBuf.readableBytes() == 0)
        return;
    PacketInput inputBuffer = new NettyInputWrapper(byteBuf);
    int i = inputBuffer.readVarInt();
    boolean flag = packetDirection == PacketDirection.TO_CLIENT;
    ProtocolState protocolState = userData.getProtocolState();
    if (protocolState == ProtocolState.HANDSHAKE) {
        int readerIndex = byteBuf.readerIndex();
        int protocol = inputBuffer.readVarInt();
        byteBuf.readerIndex(readerIndex);
        userData.setClientVersion(MinecraftVersion.fromNettyProtocolId(protocol));
    }
    PacketData packet;
    if (flag) {
        packet = readModernPacket(main.getConfiguration().getServerVersion(), protocolState, inputBuffer, packetDirection, i);
    } else {
        packet = readModernPacket(userData.getClientVersion(), protocolState, inputBuffer, packetDirection, i);
    }
    int readableBytes = byteBuf.readableBytes();
    if (readableBytes > 0) {
        byteBuf.skipBytes(readableBytes);
        Logger.warn("skipping {} bytes for packet id: {}, direction: {}", readableBytes, i, packetDirection);
    } else {
        list.add(packet);
    }
}
Also used : PacketInput(com.github.dirtpowered.dirtmv.data.protocol.io.model.PacketInput) NettyInputWrapper(com.github.dirtpowered.dirtmv.data.protocol.io.NettyInputWrapper) ProtocolState(com.github.dirtpowered.dirtmv.data.translator.ProtocolState) PacketData(com.github.dirtpowered.dirtmv.data.protocol.PacketData)

Aggregations

PacketData (com.github.dirtpowered.dirtmv.data.protocol.PacketData)2 NettyInputWrapper (com.github.dirtpowered.dirtmv.data.protocol.io.NettyInputWrapper)2 PacketInput (com.github.dirtpowered.dirtmv.data.protocol.io.model.PacketInput)2 ProtocolState (com.github.dirtpowered.dirtmv.data.translator.ProtocolState)1