Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-12-26 00:00:55 +01:00
Accept changes to compression treshold on the fly.
Vanilla allows this for some reason, and there has been one case where Velocity's strict behavior has caused a bug. Fix this.
Dieser Commit ist enthalten in:
Ursprung
0fa61216e7
Commit
892ac6f626
@ -382,16 +382,25 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
|
|||||||
if (threshold == -1) {
|
if (threshold == -1) {
|
||||||
channel.pipeline().remove(COMPRESSION_DECODER);
|
channel.pipeline().remove(COMPRESSION_DECODER);
|
||||||
channel.pipeline().remove(COMPRESSION_ENCODER);
|
channel.pipeline().remove(COMPRESSION_ENCODER);
|
||||||
return;
|
} else {
|
||||||
|
MinecraftCompressDecoder decoder = (MinecraftCompressDecoder) channel.pipeline()
|
||||||
|
.get(COMPRESSION_DECODER);
|
||||||
|
MinecraftCompressEncoder encoder = (MinecraftCompressEncoder) channel.pipeline()
|
||||||
|
.get(COMPRESSION_ENCODER);
|
||||||
|
if (decoder != null && encoder != null) {
|
||||||
|
decoder.setThreshold(threshold);
|
||||||
|
encoder.setThreshold(threshold);
|
||||||
|
} else {
|
||||||
|
int level = server.getConfiguration().getCompressionLevel();
|
||||||
|
VelocityCompressor compressor = Natives.compress.get().create(level);
|
||||||
|
|
||||||
|
encoder = new MinecraftCompressEncoder(threshold, compressor);
|
||||||
|
decoder = new MinecraftCompressDecoder(threshold, compressor);
|
||||||
|
|
||||||
|
channel.pipeline().addBefore(MINECRAFT_DECODER, COMPRESSION_DECODER, decoder);
|
||||||
|
channel.pipeline().addBefore(MINECRAFT_ENCODER, COMPRESSION_ENCODER, encoder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int level = server.getConfiguration().getCompressionLevel();
|
|
||||||
VelocityCompressor compressor = Natives.compress.get().create(level);
|
|
||||||
MinecraftCompressEncoder encoder = new MinecraftCompressEncoder(threshold, compressor);
|
|
||||||
MinecraftCompressDecoder decoder = new MinecraftCompressDecoder(threshold, compressor);
|
|
||||||
|
|
||||||
channel.pipeline().addBefore(MINECRAFT_DECODER, COMPRESSION_DECODER, decoder);
|
|
||||||
channel.pipeline().addBefore(MINECRAFT_ENCODER, COMPRESSION_ENCODER, encoder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,7 +20,7 @@ public class MinecraftCompressDecoder extends MessageToMessageDecoder<ByteBuf> {
|
|||||||
Boolean.getBoolean("velocity.increased-compression-cap")
|
Boolean.getBoolean("velocity.increased-compression-cap")
|
||||||
? HARD_MAXIMUM_UNCOMPRESSED_SIZE : VANILLA_MAXIMUM_UNCOMPRESSED_SIZE;
|
? HARD_MAXIMUM_UNCOMPRESSED_SIZE : VANILLA_MAXIMUM_UNCOMPRESSED_SIZE;
|
||||||
|
|
||||||
private final int threshold;
|
private int threshold;
|
||||||
private final VelocityCompressor compressor;
|
private final VelocityCompressor compressor;
|
||||||
|
|
||||||
public MinecraftCompressDecoder(int threshold, VelocityCompressor compressor) {
|
public MinecraftCompressDecoder(int threshold, VelocityCompressor compressor) {
|
||||||
@ -60,4 +60,8 @@ public class MinecraftCompressDecoder extends MessageToMessageDecoder<ByteBuf> {
|
|||||||
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
||||||
compressor.close();
|
compressor.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setThreshold(int threshold) {
|
||||||
|
this.threshold = threshold;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import io.netty.handler.codec.MessageToByteEncoder;
|
|||||||
|
|
||||||
public class MinecraftCompressEncoder extends MessageToByteEncoder<ByteBuf> {
|
public class MinecraftCompressEncoder extends MessageToByteEncoder<ByteBuf> {
|
||||||
|
|
||||||
private final int threshold;
|
private int threshold;
|
||||||
private final VelocityCompressor compressor;
|
private final VelocityCompressor compressor;
|
||||||
|
|
||||||
public MinecraftCompressEncoder(int threshold, VelocityCompressor compressor) {
|
public MinecraftCompressEncoder(int threshold, VelocityCompressor compressor) {
|
||||||
@ -54,4 +54,8 @@ public class MinecraftCompressEncoder extends MessageToByteEncoder<ByteBuf> {
|
|||||||
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
||||||
compressor.close();
|
compressor.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setThreshold(int threshold) {
|
||||||
|
this.threshold = threshold;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren