Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +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
836f9bf1b2
Commit
a9decc5aab
@ -382,17 +382,26 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
|
||||
if (threshold == -1) {
|
||||
channel.pipeline().remove(COMPRESSION_DECODER);
|
||||
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);
|
||||
MinecraftCompressEncoder encoder = new MinecraftCompressEncoder(threshold, compressor);
|
||||
MinecraftCompressDecoder decoder = new MinecraftCompressDecoder(threshold, compressor);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables encryption on the connection.
|
||||
|
@ -20,7 +20,7 @@ public class MinecraftCompressDecoder extends MessageToMessageDecoder<ByteBuf> {
|
||||
Boolean.getBoolean("velocity.increased-compression-cap")
|
||||
? HARD_MAXIMUM_UNCOMPRESSED_SIZE : VANILLA_MAXIMUM_UNCOMPRESSED_SIZE;
|
||||
|
||||
private final int threshold;
|
||||
private int threshold;
|
||||
private final 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 {
|
||||
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> {
|
||||
|
||||
private final int threshold;
|
||||
private int threshold;
|
||||
private final 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 {
|
||||
compressor.close();
|
||||
}
|
||||
|
||||
public void setThreshold(int threshold) {
|
||||
this.threshold = threshold;
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren