3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00

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

Dieser Commit ist enthalten in:
Myles 2016-03-02 18:41:47 +00:00
Ursprung ccd6987f11
Commit 4cdfd72700
4 geänderte Dateien mit 27 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -1,4 +1,4 @@
# ViaVersion 0.4.1 # ViaVersion 0.4.2
**Allows the connection of 1.8 clients to 1.9** **Allows the connection of 1.8 clients to 1.9**
This plugin modifies netty to allow connection of 1.9 clients to 1.8, This plugin modifies netty to allow connection of 1.9 clients to 1.8,

Datei anzeigen

@ -24,8 +24,8 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
@Override @Override
protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> list) throws Exception { protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> list) throws Exception {
// use transformers // use transformers
if(bytebuf.readableBytes() > 0) { if (bytebuf.readableBytes() > 0) {
if(info.isActive()) { if (info.isActive()) {
int id = PacketUtil.readVarInt(bytebuf); int id = PacketUtil.readVarInt(bytebuf);
// Transform // Transform
ByteBuf newPacket = ctx.alloc().buffer(); ByteBuf newPacket = ctx.alloc().buffer();
@ -33,7 +33,8 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
incomingTransformer.transform(id, bytebuf, newPacket); incomingTransformer.transform(id, bytebuf, newPacket);
bytebuf = newPacket; bytebuf = newPacket;
} catch (CancelException e) { } catch (CancelException e) {
return; bytebuf.readBytes(bytebuf.readableBytes());
throw e;
} }
} }
// call minecraft decoder // 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;
}
}
}
} }

Datei anzeigen

@ -44,14 +44,14 @@ public class ViaEncodeHandler extends MessageToByteEncoder {
Object packet = constructor.newInstance(chunk, true, 65535); Object packet = constructor.newInstance(chunk, true, 65535);
ctx.pipeline().writeAndFlush(packet); ctx.pipeline().writeAndFlush(packet);
} }
bytebuf.clear(); bytebuf.readBytes(bytebuf.readableBytes());
return; throw new CancelException();
} }
// call minecraft encoder // call minecraft encoder
PacketUtil.callEncode(this.minecraftEncoder, ctx, o, bytebuf); PacketUtil.callEncode(this.minecraftEncoder, ctx, o, bytebuf);
} }
if (bytebuf.readableBytes() == 0) { if (bytebuf.readableBytes() == 0) {
return; throw new CancelException();
} }
if(info.isActive()) { if(info.isActive()) {
int id = PacketUtil.readVarInt(bytebuf); int id = PacketUtil.readVarInt(bytebuf);
@ -61,12 +61,20 @@ public class ViaEncodeHandler extends MessageToByteEncoder {
try { try {
outgoingTransformer.transform(id, oldPacket, bytebuf); outgoingTransformer.transform(id, oldPacket, bytebuf);
} catch (CancelException e) { } catch (CancelException e) {
bytebuf.clear(); bytebuf.readBytes(bytebuf.readableBytes());
return; throw e;
} finally { } finally {
oldPacket.release(); oldPacket.release();
} }
} }
} }
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if(!(cause.getCause() instanceof CancelException)) {
if(cause instanceof Exception){
throw (Exception) cause;
}
}
}
} }

Datei anzeigen

@ -1,6 +1,6 @@
name: ViaVersion name: ViaVersion
main: us.myles.ViaVersion.ViaVersionPlugin main: us.myles.ViaVersion.ViaVersionPlugin
author: _MylesC author: _MylesC
version: 0.4.1 version: 0.4.2
load: startup load: startup
loadbefore: [ProtocolLib, ProxyPipe] loadbefore: [ProtocolLib, ProxyPipe]