| 1 | package net.minecraft.util;
|
| 2 |
|
| 3 | import io.netty.buffer.ByteBuf;
|
| 4 | import io.netty.channel.ChannelHandlerContext;
|
| 5 | import io.netty.handler.codec.ByteToMessageDecoder;
|
| 6 | import java.io.IOException;
|
| 7 | import java.util.List;
|
| 8 | import net.minecraft.network.EnumConnectionState;
|
| 9 | import net.minecraft.network.EnumPacketDirection;
|
| 10 | import net.minecraft.network.NetworkManager;
|
| 11 | import net.minecraft.network.Packet;
|
| 12 | import net.minecraft.network.PacketBuffer;
|
| 13 | import org.apache.logging.log4j.LogManager;
|
| 14 | import org.apache.logging.log4j.Logger;
|
| 15 | import org.apache.logging.log4j.Marker;
|
| 16 | import org.apache.logging.log4j.MarkerManager;
|
| 17 |
|
| 18 | public class MessageDeserializer extends ByteToMessageDecoder
|
| 19 | {
|
| 20 | private static final Logger logger = LogManager.getLogger();
|
| 21 | private static final Marker RECEIVED_PACKET_MARKER = MarkerManager.getMarker("PACKET_RECEIVED", NetworkManager.logMarkerPackets);
|
| 22 | private final EnumPacketDirection direction;
|
| 23 |
|
| 24 | public MessageDeserializer(EnumPacketDirection direction)
|
| 25 | {
|
| 26 | this.direction = direction;
|
| 27 | }
|
| 28 |
|
| 29 | protected void decode(ChannelHandlerContext p_decode_1_, ByteBuf p_decode_2_, List<Object> p_decode_3_) throws IOException, InstantiationException, IllegalAccessException, Exception
|
| 30 | {
|
| 31 | if (p_decode_2_.readableBytes() != 0)
|
| 32 | {
|
| 33 | PacketBuffer packetbuffer = new PacketBuffer(p_decode_2_);
|
| 34 | int i = packetbuffer.readVarIntFromBuffer();
|
| 35 | Packet packet = ((EnumConnectionState)p_decode_1_.channel().attr(NetworkManager.attrKeyConnectionState).get()).getPacket(this.direction, i);
|
| 36 |
|
| 37 | if (packet == null)
|
| 38 | {
|
| 39 | throw new IOException("Bad packet id " + i);
|
| 40 | }
|
| 41 | else
|
| 42 | {
|
| 43 | packet.readPacketData(packetbuffer);
|
| 44 |
|
| 45 | if (packetbuffer.readableBytes() > 0)
|
| 46 | {
|
| 47 | throw new IOException("Packet " + ((EnumConnectionState)p_decode_1_.channel().attr(NetworkManager.attrKeyConnectionState).get()).getId() + "/" + i + " (" + packet.getClass().getSimpleName() + ") was larger than I expected, found " + packetbuffer.readableBytes() + " bytes extra whilst reading packet " + i);
|
| 48 | }
|
| 49 | else
|
| 50 | {
|
| 51 | p_decode_3_.add(packet);
|
| 52 |
|
| 53 | if (logger.isDebugEnabled())
|
| 54 | {
|
| 55 | logger.debug(RECEIVED_PACKET_MARKER, " IN: [{}:{}] {}", new Object[] {p_decode_1_.channel().attr(NetworkManager.attrKeyConnectionState).get(), Integer.valueOf(i), packet.getClass().getName()});
|
| 56 | }
|
| 57 | }
|
| 58 | }
|
| 59 | }
|
| 60 | }
|
| 61 | }
|
| 62 |
|