From 2d33447fc183e5bdbbf1f642c4ce567e49ba8ec0 Mon Sep 17 00:00:00 2001 From: creeper123123321 <7974274+creeper123123321@users.noreply.github.com> Date: Tue, 30 Jun 2020 17:30:57 -0300 Subject: [PATCH] fixed backend compression, remove debug --- .../handlers/VelocityDecodeHandler.java | 17 +++++++++++------ .../handlers/VelocityEncodeHandler.java | 3 +-- .../providers/VelocityVersionProvider.java | 2 -- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityDecodeHandler.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityDecodeHandler.java index fa5ff2a79..773fb1d50 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityDecodeHandler.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityDecodeHandler.java @@ -5,11 +5,9 @@ import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; import io.netty.handler.codec.MessageToMessageDecoder; -import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.exception.CancelDecoderException; import us.myles.ViaVersion.exception.CancelCodecException; +import us.myles.ViaVersion.exception.CancelDecoderException; import us.myles.ViaVersion.util.PipelineUtil; import java.lang.reflect.InvocationTargetException; @@ -18,7 +16,8 @@ import java.util.List; @ChannelHandler.Sharable public class VelocityDecodeHandler extends MessageToMessageDecoder { private final UserConnection info; - boolean handledCompression; + private boolean handledCompression; + private boolean skipDoubleTransform; public VelocityDecodeHandler(UserConnection info) { this.info = info; @@ -26,6 +25,12 @@ public class VelocityDecodeHandler extends MessageToMessageDecoder { @Override protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List out) throws Exception { + if (skipDoubleTransform) { + skipDoubleTransform = false; + out.add(bytebuf.retain()); + return; + } + if (!info.checkIncomingPacket()) throw CancelDecoderException.generate(null); if (!info.shouldTransformPacket()) { out.add(bytebuf.retain()); @@ -40,6 +45,7 @@ public class VelocityDecodeHandler extends MessageToMessageDecoder { if (needsCompress) { recompress(ctx, transformedBuf); + skipDoubleTransform = true; } out.add(transformedBuf.retain()); } finally { @@ -48,13 +54,12 @@ public class VelocityDecodeHandler extends MessageToMessageDecoder { } private boolean handleCompressionOrder(ChannelHandlerContext ctx, ByteBuf draft) throws InvocationTargetException { - //if (handledCompression) return false; + if (handledCompression) return false; int decoderIndex = ctx.pipeline().names().indexOf("compression-decoder"); if (decoderIndex == -1) return false; handledCompression = true; if (decoderIndex > ctx.pipeline().names().indexOf("via-decoder")) { - System.out.println("bad decoder order"); // Need to decompress this packet due to bad order ByteBuf decompressed = (ByteBuf) PipelineUtil.callDecode((MessageToMessageDecoder) ctx.pipeline().get("compression-decoder"), ctx, draft).get(0); try { diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityEncodeHandler.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityEncodeHandler.java index be32e1b11..0d8cf4276 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityEncodeHandler.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/handlers/VelocityEncodeHandler.java @@ -47,13 +47,12 @@ public class VelocityEncodeHandler extends MessageToMessageEncoder { } private boolean handleCompressionOrder(ChannelHandlerContext ctx, ByteBuf buf) throws InvocationTargetException { - //if (handledCompression) return false; + if (handledCompression) return false; int encoderIndex = ctx.pipeline().names().indexOf("compression-encoder"); if (encoderIndex == -1) return false; handledCompression = true; if (encoderIndex > ctx.pipeline().names().indexOf("via-encoder")) { - System.out.println("bad decoder order"); // Need to decompress this packet due to bad order ByteBuf decompressed = (ByteBuf) PipelineUtil.callDecode((MessageToMessageDecoder) ctx.pipeline().get("compression-decoder"), ctx, buf).get(0); try { diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/providers/VelocityVersionProvider.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/providers/VelocityVersionProvider.java index bb0907d60..0fde41837 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/providers/VelocityVersionProvider.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/providers/VelocityVersionProvider.java @@ -31,14 +31,12 @@ public class VelocityVersionProvider extends VersionProvider { } private int getBackProtocol(UserConnection user) throws Exception { - System.out.println("backend protocol!"); ChannelHandler mcHandler = user.getChannel().pipeline().get("handler"); return ProtocolDetectorService.getProtocolId( ((ServerConnection) getAssociation.invoke(mcHandler)).getServerInfo().getName()); } private int getFrontProtocol(UserConnection user) throws Exception { - System.out.println("frontend protocol!"); int playerVersion = user.getProtocolInfo().getProtocolVersion(); IntStream versions = com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS.stream()