From 4cdfd7270063cec71d3c78e73fd12d60780933ca Mon Sep 17 00:00:00 2001 From: Myles Date: Wed, 2 Mar 2016 18:41:47 +0000 Subject: [PATCH] Ensure no bytes are left on the bytebufs and ensure it is cancelled properly. Update Version to 0.4.2 --- README.md | 2 +- .../ViaVersion/handlers/ViaDecodeHandler.java | 15 ++++++++++++--- .../ViaVersion/handlers/ViaEncodeHandler.java | 18 +++++++++++++----- src/main/resources/plugin.yml | 2 +- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 01fe4e297..bc2c9fdd7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ViaVersion 0.4.1 +# ViaVersion 0.4.2 **Allows the connection of 1.8 clients to 1.9** This plugin modifies netty to allow connection of 1.9 clients to 1.8, diff --git a/src/main/java/us/myles/ViaVersion/handlers/ViaDecodeHandler.java b/src/main/java/us/myles/ViaVersion/handlers/ViaDecodeHandler.java index c689c3db4..72d7eb0b0 100644 --- a/src/main/java/us/myles/ViaVersion/handlers/ViaDecodeHandler.java +++ b/src/main/java/us/myles/ViaVersion/handlers/ViaDecodeHandler.java @@ -24,8 +24,8 @@ public class ViaDecodeHandler extends ByteToMessageDecoder { @Override protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List list) throws Exception { // use transformers - if(bytebuf.readableBytes() > 0) { - if(info.isActive()) { + if (bytebuf.readableBytes() > 0) { + if (info.isActive()) { int id = PacketUtil.readVarInt(bytebuf); // Transform ByteBuf newPacket = ctx.alloc().buffer(); @@ -33,7 +33,8 @@ public class ViaDecodeHandler extends ByteToMessageDecoder { incomingTransformer.transform(id, bytebuf, newPacket); bytebuf = newPacket; } catch (CancelException e) { - return; + bytebuf.readBytes(bytebuf.readableBytes()); + throw e; } } // call minecraft decoder @@ -41,5 +42,13 @@ public class ViaDecodeHandler extends ByteToMessageDecoder { } } + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + if (!(cause.getCause() instanceof CancelException)) { + if (cause instanceof Exception) { + throw (Exception) cause; + } + } + } } diff --git a/src/main/java/us/myles/ViaVersion/handlers/ViaEncodeHandler.java b/src/main/java/us/myles/ViaVersion/handlers/ViaEncodeHandler.java index 41930556c..a3f2a814e 100644 --- a/src/main/java/us/myles/ViaVersion/handlers/ViaEncodeHandler.java +++ b/src/main/java/us/myles/ViaVersion/handlers/ViaEncodeHandler.java @@ -44,14 +44,14 @@ public class ViaEncodeHandler extends MessageToByteEncoder { Object packet = constructor.newInstance(chunk, true, 65535); ctx.pipeline().writeAndFlush(packet); } - bytebuf.clear(); - return; + bytebuf.readBytes(bytebuf.readableBytes()); + throw new CancelException(); } // call minecraft encoder PacketUtil.callEncode(this.minecraftEncoder, ctx, o, bytebuf); } if (bytebuf.readableBytes() == 0) { - return; + throw new CancelException(); } if(info.isActive()) { int id = PacketUtil.readVarInt(bytebuf); @@ -61,12 +61,20 @@ public class ViaEncodeHandler extends MessageToByteEncoder { try { outgoingTransformer.transform(id, oldPacket, bytebuf); } catch (CancelException e) { - bytebuf.clear(); - return; + bytebuf.readBytes(bytebuf.readableBytes()); + throw e; } finally { oldPacket.release(); } } } + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + if(!(cause.getCause() instanceof CancelException)) { + if(cause instanceof Exception){ + throw (Exception) cause; + } + } + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 312dbc5e0..a596db287 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: ViaVersion main: us.myles.ViaVersion.ViaVersionPlugin author: _MylesC -version: 0.4.1 +version: 0.4.2 load: startup loadbefore: [ProtocolLib, ProxyPipe] \ No newline at end of file