mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-24 00:51:34 +01:00
Fix packet writing when compression is disabled
This commit is contained in:
parent
7cd2d1b896
commit
4c3215bf1b
@ -203,21 +203,23 @@ public final class PacketUtils {
|
|||||||
final int dataLength = packetBuf.readableBytes();
|
final int dataLength = packetBuf.readableBytes();
|
||||||
|
|
||||||
final int compressionThreshold = MinecraftServer.getCompressionThreshold();
|
final int compressionThreshold = MinecraftServer.getCompressionThreshold();
|
||||||
final boolean compression = compressionThreshold > 0 && dataLength >= compressionThreshold;
|
final boolean compression = compressionThreshold > 0;
|
||||||
|
|
||||||
if (compression) {
|
if (compression) {
|
||||||
// Compression
|
if (dataLength >= compressionThreshold) {
|
||||||
|
// Packet large enough
|
||||||
ByteBuf compressedBuf = directBuffer ? BufUtils.getBuffer(true) : Unpooled.buffer();
|
ByteBuf compressedBuf = directBuffer ? BufUtils.getBuffer(true) : Unpooled.buffer();
|
||||||
Utils.writeVarIntBuf(compressedBuf, dataLength);
|
Utils.writeVarIntBuf(compressedBuf, dataLength);
|
||||||
final Deflater deflater = DEFLATER.get();
|
final Deflater deflater = DEFLATER.get();
|
||||||
compress(deflater, null, packetBuf, compressedBuf);
|
compress(deflater, null, packetBuf, compressedBuf);
|
||||||
packetBuf = compressedBuf;
|
packetBuf = compressedBuf;
|
||||||
} else {
|
} else {
|
||||||
// No compression
|
// Packet too small
|
||||||
ByteBuf uncompressedLengthBuffer = Unpooled.buffer();
|
ByteBuf uncompressedLengthBuffer = Unpooled.buffer();
|
||||||
Utils.writeVarIntBuf(uncompressedLengthBuffer, 0);
|
Utils.writeVarIntBuf(uncompressedLengthBuffer, 0);
|
||||||
packetBuf = Unpooled.wrappedBuffer(uncompressedLengthBuffer, packetBuf);
|
packetBuf = Unpooled.wrappedBuffer(uncompressedLengthBuffer, packetBuf);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Write the final length of the packet
|
// Write the final length of the packet
|
||||||
ByteBuf packetLengthBuffer = Unpooled.buffer();
|
ByteBuf packetLengthBuffer = Unpooled.buffer();
|
||||||
|
Loading…
Reference in New Issue
Block a user