From ebb2f8032864897bb458d6682491bf8587ca12e4 Mon Sep 17 00:00:00 2001 From: creeper123123321 <7974274+creeper123123321@users.noreply.github.com> Date: Mon, 20 Dec 2021 20:41:28 -0300 Subject: [PATCH] fixed compression in PLAY state --- .../com/viaversion/aas/codec/CompressionCodec.java | 12 ++++++------ .../com/viaversion/aas/platform/AspirinLoader.java | 3 +++ .../aas/provider/AspirinCompressionProvider.java | 14 ++++++++++++++ src/main/kotlin/com/viaversion/aas/handler/Util.kt | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/viaversion/aas/provider/AspirinCompressionProvider.java diff --git a/src/main/java/com/viaversion/aas/codec/CompressionCodec.java b/src/main/java/com/viaversion/aas/codec/CompressionCodec.java index 383d365..7ed82da 100644 --- a/src/main/java/com/viaversion/aas/codec/CompressionCodec.java +++ b/src/main/java/com/viaversion/aas/codec/CompressionCodec.java @@ -28,14 +28,14 @@ public class CompressionCodec extends MessageToMessageCodec { this.threshold = threshold; } - public void setThreshold(int threshold) { - this.threshold = threshold; - } - public int getThreshold() { return threshold; } + public void setThreshold(int threshold) { + this.threshold = threshold; + } + @Override public void handlerAdded(ChannelHandlerContext ctx) { var level = VIAaaSConfig.INSTANCE.getCompressionLevel(); @@ -114,10 +114,10 @@ public class CompressionCodec extends MessageToMessageCodec { } if (claimedUncompressedSize < threshold) { - throw new DecoderException("Badly compressed packet - size of $claimedUncompressedSize is below server threshold of $threshold"); + throw new DecoderException("Badly compressed packet - size of " + claimedUncompressedSize + " is below server threshold of " + threshold); } if (claimedUncompressedSize > UNCOMPRESSED_CAP) { - throw new DecoderException("Badly compressed packet - size of $claimedUncompressedSize is larger than maximum of $UNCOMPRESSED_CAP"); + throw new DecoderException("Badly compressed packet - size of " + claimedUncompressedSize + " is larger than maximum of " + UNCOMPRESSED_CAP); } var compatibleIn = MoreByteBufUtils.ensureCompatible(ctx.alloc(), compressor, input); var decompressed = MoreByteBufUtils.preferredBuffer(ctx.alloc(), compressor, claimedUncompressedSize); diff --git a/src/main/java/com/viaversion/aas/platform/AspirinLoader.java b/src/main/java/com/viaversion/aas/platform/AspirinLoader.java index 9a82d0c..57a5d77 100644 --- a/src/main/java/com/viaversion/aas/platform/AspirinLoader.java +++ b/src/main/java/com/viaversion/aas/platform/AspirinLoader.java @@ -1,9 +1,11 @@ package com.viaversion.aas.platform; +import com.viaversion.aas.provider.AspirinCompressionProvider; import com.viaversion.aas.provider.AspirinVersionProvider; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.platform.ViaPlatformLoader; import com.viaversion.viaversion.api.protocol.version.VersionProvider; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CompressionProvider; import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; import com.viaversion.viaversion.velocity.providers.VelocityMovementTransmitter; @@ -12,6 +14,7 @@ public class AspirinLoader implements ViaPlatformLoader { public void load() { Via.getManager().getProviders().use(MovementTransmitterProvider.class, new VelocityMovementTransmitter()); Via.getManager().getProviders().use(VersionProvider.class, new AspirinVersionProvider()); + Via.getManager().getProviders().use(CompressionProvider.class, new AspirinCompressionProvider()); } @Override diff --git a/src/main/java/com/viaversion/aas/provider/AspirinCompressionProvider.java b/src/main/java/com/viaversion/aas/provider/AspirinCompressionProvider.java new file mode 100644 index 0000000..7a6cabc --- /dev/null +++ b/src/main/java/com/viaversion/aas/provider/AspirinCompressionProvider.java @@ -0,0 +1,14 @@ +package com.viaversion.aas.provider; + +import com.viaversion.aas.handler.UtilKt; +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CompressionProvider; + +import java.util.Objects; + +public class AspirinCompressionProvider extends CompressionProvider { + @Override + public void handlePlayCompression(UserConnection user, int threshold) { + UtilKt.setCompression(Objects.requireNonNull(user.getChannel()), threshold); + } +} diff --git a/src/main/kotlin/com/viaversion/aas/handler/Util.kt b/src/main/kotlin/com/viaversion/aas/handler/Util.kt index ba52cad..b7d2c27 100644 --- a/src/main/kotlin/com/viaversion/aas/handler/Util.kt +++ b/src/main/kotlin/com/viaversion/aas/handler/Util.kt @@ -66,7 +66,7 @@ fun encodeBrand(string: String, is17: Boolean): ByteArray { fun setCompression(channel: Channel, threshold: Int) { val pipe = channel.pipeline() - if (threshold == -1) { + if (threshold <= 0) { if (pipe["compress"] != null) pipe.remove("compress") } else { if (pipe["compress"] != null) {