mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-12-04 21:01:02 -05:00
Call PacketErrorEvent for more I/O errors.
This commit is contained in:
parent
72bde6a3c0
commit
b025025001
1 changed files with 15 additions and 13 deletions
|
@ -23,8 +23,9 @@ public class TcpPacketCodec extends ByteToMessageCodec<Packet> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void encode(ChannelHandlerContext ctx, Packet packet, ByteBuf buf) throws Exception {
|
public void encode(ChannelHandlerContext ctx, Packet packet, ByteBuf buf) throws Exception {
|
||||||
NetOutput out = new ByteBufNetOutput(buf);
|
|
||||||
try {
|
try {
|
||||||
|
NetOutput out = new ByteBufNetOutput(buf);
|
||||||
|
|
||||||
this.session.getPacketProtocol().getPacketHeader().writePacketId(out, this.session.getPacketProtocol().getOutgoingId(packet));
|
this.session.getPacketProtocol().getPacketHeader().writePacketId(out, this.session.getPacketProtocol().getOutgoingId(packet));
|
||||||
packet.write(out);
|
packet.write(out);
|
||||||
} catch(Throwable t) {
|
} catch(Throwable t) {
|
||||||
|
@ -38,18 +39,23 @@ public class TcpPacketCodec extends ByteToMessageCodec<Packet> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
|
protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
|
||||||
int initial = buf.readerIndex();
|
|
||||||
NetInput in = new ByteBufNetInput(buf);
|
|
||||||
int id = this.session.getPacketProtocol().getPacketHeader().readPacketId(in);
|
|
||||||
if(id == -1) {
|
|
||||||
buf.readerIndex(initial);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Packet packet;
|
Packet packet;
|
||||||
try {
|
try {
|
||||||
|
NetInput in = new ByteBufNetInput(buf);
|
||||||
|
|
||||||
|
int initial = buf.readerIndex();
|
||||||
|
int id = this.session.getPacketProtocol().getPacketHeader().readPacketId(in);
|
||||||
|
if(id == -1) {
|
||||||
|
buf.readerIndex(initial);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
packet = this.session.getPacketProtocol().createIncomingPacket(id);
|
packet = this.session.getPacketProtocol().createIncomingPacket(id);
|
||||||
packet.read(in);
|
packet.read(in);
|
||||||
|
|
||||||
|
if(buf.readableBytes() > 0) {
|
||||||
|
throw new IllegalStateException("Packet \"" + packet.getClass().getSimpleName() + "\" not fully read.");
|
||||||
|
}
|
||||||
} catch(Throwable t) {
|
} catch(Throwable t) {
|
||||||
PacketErrorEvent e = new PacketErrorEvent(this.session, t);
|
PacketErrorEvent e = new PacketErrorEvent(this.session, t);
|
||||||
this.session.callEvent(e);
|
this.session.callEvent(e);
|
||||||
|
@ -60,10 +66,6 @@ public class TcpPacketCodec extends ByteToMessageCodec<Packet> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(buf.readableBytes() > 0) {
|
|
||||||
throw new IllegalStateException("Packet \"" + packet.getClass().getSimpleName() + "\" not fully read.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(packet.isPriority()) {
|
if(packet.isPriority()) {
|
||||||
this.session.callEvent(new PacketReceivedEvent(this.session, packet));
|
this.session.callEvent(new PacketReceivedEvent(this.session, packet));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue