fixed compression in PLAY state

This commit is contained in:
creeper123123321 2021-12-20 20:41:28 -03:00
parent 59ee492c1b
commit ebb2f80328
4 changed files with 24 additions and 7 deletions

View File

@ -28,14 +28,14 @@ public class CompressionCodec extends MessageToMessageCodec<ByteBuf, ByteBuf> {
this.threshold = threshold; this.threshold = threshold;
} }
public void setThreshold(int threshold) {
this.threshold = threshold;
}
public int getThreshold() { public int getThreshold() {
return threshold; return threshold;
} }
public void setThreshold(int threshold) {
this.threshold = threshold;
}
@Override @Override
public void handlerAdded(ChannelHandlerContext ctx) { public void handlerAdded(ChannelHandlerContext ctx) {
var level = VIAaaSConfig.INSTANCE.getCompressionLevel(); var level = VIAaaSConfig.INSTANCE.getCompressionLevel();
@ -114,10 +114,10 @@ public class CompressionCodec extends MessageToMessageCodec<ByteBuf, ByteBuf> {
} }
if (claimedUncompressedSize < threshold) { 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) { 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 compatibleIn = MoreByteBufUtils.ensureCompatible(ctx.alloc(), compressor, input);
var decompressed = MoreByteBufUtils.preferredBuffer(ctx.alloc(), compressor, claimedUncompressedSize); var decompressed = MoreByteBufUtils.preferredBuffer(ctx.alloc(), compressor, claimedUncompressedSize);

View File

@ -1,9 +1,11 @@
package com.viaversion.aas.platform; package com.viaversion.aas.platform;
import com.viaversion.aas.provider.AspirinCompressionProvider;
import com.viaversion.aas.provider.AspirinVersionProvider; import com.viaversion.aas.provider.AspirinVersionProvider;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.platform.ViaPlatformLoader; import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
import com.viaversion.viaversion.api.protocol.version.VersionProvider; 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.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import com.viaversion.viaversion.velocity.providers.VelocityMovementTransmitter; import com.viaversion.viaversion.velocity.providers.VelocityMovementTransmitter;
@ -12,6 +14,7 @@ public class AspirinLoader implements ViaPlatformLoader {
public void load() { public void load() {
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new VelocityMovementTransmitter()); Via.getManager().getProviders().use(MovementTransmitterProvider.class, new VelocityMovementTransmitter());
Via.getManager().getProviders().use(VersionProvider.class, new AspirinVersionProvider()); Via.getManager().getProviders().use(VersionProvider.class, new AspirinVersionProvider());
Via.getManager().getProviders().use(CompressionProvider.class, new AspirinCompressionProvider());
} }
@Override @Override

View File

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

View File

@ -66,7 +66,7 @@ fun encodeBrand(string: String, is17: Boolean): ByteArray {
fun setCompression(channel: Channel, threshold: Int) { fun setCompression(channel: Channel, threshold: Int) {
val pipe = channel.pipeline() val pipe = channel.pipeline()
if (threshold == -1) { if (threshold <= 0) {
if (pipe["compress"] != null) pipe.remove("compress") if (pipe["compress"] != null) pipe.remove("compress")
} else { } else {
if (pipe["compress"] != null) { if (pipe["compress"] != null) {