Ensure no bytes are left on the bytebufs and ensure it is cancelled properly. Update Version to 0.4.2

This commit is contained in:
Myles 2016-03-02 18:41:47 +00:00
parent ccd6987f11
commit 4cdfd72700
4 changed files with 27 additions and 10 deletions

View File

@ -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,

View File

@ -24,8 +24,8 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> 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;
}
}
}
}

View File

@ -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;
}
}
}
}

View File

@ -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]