diff --git a/src/main/java/com/github/steveice10/packetlib/tcp/TcpPacketCodec.java b/src/main/java/com/github/steveice10/packetlib/tcp/TcpPacketCodec.java index 0a710016..1f42e2c7 100644 --- a/src/main/java/com/github/steveice10/packetlib/tcp/TcpPacketCodec.java +++ b/src/main/java/com/github/steveice10/packetlib/tcp/TcpPacketCodec.java @@ -46,7 +46,6 @@ public class TcpPacketCodec extends ByteToMessageCodec { protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List out) throws Exception { int initial = buf.readerIndex(); - Packet packet; try { NetInput in = new ByteBufNetInput(buf); @@ -56,12 +55,14 @@ public class TcpPacketCodec extends ByteToMessageCodec { return; } - packet = this.session.getPacketProtocol().createIncomingPacket(id); + Packet packet = this.session.getPacketProtocol().createIncomingPacket(id); packet.read(in); if(buf.readableBytes() > 0) { throw new IllegalStateException("Packet \"" + packet.getClass().getSimpleName() + "\" not fully read."); } + + out.add(packet); } catch(Throwable t) { // Advance buffer to end to make sure remaining data in this packet is skipped. buf.readerIndex(buf.readerIndex() + buf.readableBytes()); @@ -71,14 +72,6 @@ public class TcpPacketCodec extends ByteToMessageCodec { if(!e.shouldSuppress()) { throw t; } - - return; } - - if(packet.isPriority()) { - this.session.callEvent(new PacketReceivedEvent(this.session, packet)); - } - - out.add(packet); } } diff --git a/src/main/java/com/github/steveice10/packetlib/tcp/TcpSession.java b/src/main/java/com/github/steveice10/packetlib/tcp/TcpSession.java index 01496e23..f8dba5ca 100644 --- a/src/main/java/com/github/steveice10/packetlib/tcp/TcpSession.java +++ b/src/main/java/com/github/steveice10/packetlib/tcp/TcpSession.java @@ -359,8 +359,10 @@ public abstract class TcpSession extends SimpleChannelInboundHandler imp } @Override - protected void channelRead0(ChannelHandlerContext ctx, Packet packet) throws Exception { - if(!packet.isPriority()) { + protected void channelRead0(ChannelHandlerContext ctx, Packet packet) { + if(packet.isPriority()) { + this.callEvent(new PacketReceivedEvent(this, packet)); + } else { this.packets.add(packet); } }