mirror of
https://github.com/PaperMC/Velocity.git
synced 2024-11-21 03:11:38 +08:00
Minecraft 1.17.1 support (#530)
This commit is contained in:
parent
1f7d14f6d1
commit
540d970a4d
@ -54,7 +54,8 @@ public enum ProtocolVersion {
|
|||||||
MINECRAFT_1_16_2(751, "1.16.2"),
|
MINECRAFT_1_16_2(751, "1.16.2"),
|
||||||
MINECRAFT_1_16_3(753, "1.16.3"),
|
MINECRAFT_1_16_3(753, "1.16.3"),
|
||||||
MINECRAFT_1_16_4(754, "1.16.4", "1.16.5"),
|
MINECRAFT_1_16_4(754, "1.16.4", "1.16.5"),
|
||||||
MINECRAFT_1_17(755, "1.17");
|
MINECRAFT_1_17(755, "1.17"),
|
||||||
|
MINECRAFT_1_17_1(756, "1.17.1");
|
||||||
|
|
||||||
private static final int SNAPSHOT_BIT = 30;
|
private static final int SNAPSHOT_BIT = 30;
|
||||||
|
|
||||||
|
@ -35,17 +35,6 @@ public class Velocity {
|
|||||||
// How inconvenient. Force AWT to work with its head chopped off.
|
// How inconvenient. Force AWT to work with its head chopped off.
|
||||||
System.setProperty("java.awt.headless", "true");
|
System.setProperty("java.awt.headless", "true");
|
||||||
|
|
||||||
// By default, Netty allocates 16MiB arenas for the PooledByteBufAllocator. This is too much
|
|
||||||
// memory for Minecraft, which imposes a maximum packet size of 2MiB! We'll use 4MiB as a more
|
|
||||||
// sane default.
|
|
||||||
//
|
|
||||||
// Note: io.netty.allocator.pageSize << io.netty.allocator.maxOrder is the formula used to
|
|
||||||
// compute the chunk size. We lower maxOrder from its default of 11 to 9. (We also use a null
|
|
||||||
// check, so that the user is free to choose another setting if need be.)
|
|
||||||
if (System.getProperty("io.netty.allocator.maxOrder") == null) {
|
|
||||||
System.setProperty("io.netty.allocator.maxOrder", "9");
|
|
||||||
}
|
|
||||||
|
|
||||||
// If Velocity's natives are being extracted to a different temporary directory, make sure the
|
// If Velocity's natives are being extracted to a different temporary directory, make sure the
|
||||||
// Netty natives are extracted there as well
|
// Netty natives are extracted there as well
|
||||||
if (System.getProperty("velocity.natives-tmpdir") != null) {
|
if (System.getProperty("velocity.natives-tmpdir") != null) {
|
||||||
|
@ -30,7 +30,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class MinecraftCompressDecoder extends MessageToMessageDecoder<ByteBuf> {
|
public class MinecraftCompressDecoder extends MessageToMessageDecoder<ByteBuf> {
|
||||||
|
|
||||||
private static final int VANILLA_MAXIMUM_UNCOMPRESSED_SIZE = 2 * 1024 * 1024; // 2MiB
|
private static final int VANILLA_MAXIMUM_UNCOMPRESSED_SIZE = 8 * 1024 * 1024; // 8MiB
|
||||||
private static final int HARD_MAXIMUM_UNCOMPRESSED_SIZE = 16 * 1024 * 1024; // 16MiB
|
private static final int HARD_MAXIMUM_UNCOMPRESSED_SIZE = 16 * 1024 * 1024; // 16MiB
|
||||||
|
|
||||||
private static final int UNCOMPRESSED_CAP =
|
private static final int UNCOMPRESSED_CAP =
|
||||||
|
@ -29,9 +29,6 @@ import java.util.zip.DataFormatException;
|
|||||||
|
|
||||||
public class MinecraftCompressorAndLengthEncoder extends MessageToByteEncoder<ByteBuf> {
|
public class MinecraftCompressorAndLengthEncoder extends MessageToByteEncoder<ByteBuf> {
|
||||||
|
|
||||||
private static final boolean MUST_USE_SAFE_AND_SLOW_COMPRESSION_HANDLING =
|
|
||||||
Boolean.getBoolean("velocity.increased-compression-cap");
|
|
||||||
|
|
||||||
private int threshold;
|
private int threshold;
|
||||||
private final VelocityCompressor compressor;
|
private final VelocityCompressor compressor;
|
||||||
|
|
||||||
@ -49,15 +46,11 @@ public class MinecraftCompressorAndLengthEncoder extends MessageToByteEncoder<By
|
|||||||
ProtocolUtils.writeVarInt(out, 0);
|
ProtocolUtils.writeVarInt(out, 0);
|
||||||
out.writeBytes(msg);
|
out.writeBytes(msg);
|
||||||
} else {
|
} else {
|
||||||
if (MUST_USE_SAFE_AND_SLOW_COMPRESSION_HANDLING) {
|
handleCompressed(ctx, msg, out);
|
||||||
handleCompressedSafe(ctx, msg, out);
|
|
||||||
} else {
|
|
||||||
handleCompressedFast(ctx, msg, out);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleCompressedFast(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out)
|
private void handleCompressed(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out)
|
||||||
throws DataFormatException {
|
throws DataFormatException {
|
||||||
int uncompressed = msg.readableBytes();
|
int uncompressed = msg.readableBytes();
|
||||||
|
|
||||||
@ -73,9 +66,7 @@ public class MinecraftCompressorAndLengthEncoder extends MessageToByteEncoder<By
|
|||||||
}
|
}
|
||||||
int compressedLength = out.writerIndex() - startCompressed;
|
int compressedLength = out.writerIndex() - startCompressed;
|
||||||
if (compressedLength >= 1 << 21) {
|
if (compressedLength >= 1 << 21) {
|
||||||
throw new DataFormatException("The server sent a very large (over 2MiB compressed) packet. "
|
throw new DataFormatException("The server sent a very large (over 2MiB compressed) packet.");
|
||||||
+ "Please restart Velocity with the JVM flag -Dvelocity.increased-compression-cap=true "
|
|
||||||
+ "to fix this issue.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int writerIndex = out.writerIndex();
|
int writerIndex = out.writerIndex();
|
||||||
@ -85,26 +76,6 @@ public class MinecraftCompressorAndLengthEncoder extends MessageToByteEncoder<By
|
|||||||
out.writerIndex(writerIndex);
|
out.writerIndex(writerIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleCompressedSafe(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out)
|
|
||||||
throws DataFormatException {
|
|
||||||
int uncompressed = msg.readableBytes();
|
|
||||||
ByteBuf tmpBuf = MoreByteBufUtils.preferredBuffer(ctx.alloc(), compressor, uncompressed - 1);
|
|
||||||
try {
|
|
||||||
ProtocolUtils.writeVarInt(tmpBuf, uncompressed);
|
|
||||||
ByteBuf compatibleIn = MoreByteBufUtils.ensureCompatible(ctx.alloc(), compressor, msg);
|
|
||||||
try {
|
|
||||||
compressor.deflate(compatibleIn, tmpBuf);
|
|
||||||
} finally {
|
|
||||||
compatibleIn.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
ProtocolUtils.writeVarInt(out, tmpBuf.readableBytes());
|
|
||||||
out.writeBytes(tmpBuf);
|
|
||||||
} finally {
|
|
||||||
tmpBuf.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect)
|
protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
Loading…
Reference in New Issue
Block a user