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);
}
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);
}
}
Aggregations