-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8db96ab
commit 5abc439
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> | ||
Date: Tue, 30 Jan 2024 09:40:06 -0500 | ||
Subject: [PATCH] Configurable max VarInt size | ||
|
||
|
||
diff --git a/src/main/java/net/minecraft/network/VarInt.java b/src/main/java/net/minecraft/network/VarInt.java | ||
index 3f362eb42587b333e27b9cf25588a9cfcb8a56e7..7dc909eb095fbc4e68bd604ea48dacaaaf6942bc 100644 | ||
--- a/src/main/java/net/minecraft/network/VarInt.java | ||
+++ b/src/main/java/net/minecraft/network/VarInt.java | ||
@@ -3,7 +3,7 @@ package net.minecraft.network; | ||
import io.netty.buffer.ByteBuf; | ||
|
||
public class VarInt { | ||
- private static final int MAX_VARINT_SIZE = 5; | ||
+ private static final int MAX_VARINT_SIZE = org.dreeam.leaf.LeafConfig.maxVarIntBytes; // Leaf - Configurable max VarInt size | ||
private static final int DATA_BITS_MASK = 127; | ||
private static final int CONTINUATION_BIT_MASK = 128; | ||
private static final int DATA_BITS_PER_BYTE = 7; | ||
@@ -42,7 +42,7 @@ public class VarInt { | ||
do { | ||
b = buf.readByte(); | ||
i |= (b & 127) << j++ * 7; | ||
- if (j > 5) { | ||
+ if (j > MAX_VARINT_SIZE) { // Leaf - Configurable max VarInt size | ||
throw new RuntimeException("VarInt too big"); | ||
} | ||
} while(hasContinuationBit(b)); | ||
diff --git a/src/main/java/net/minecraft/network/Varint21LengthFieldPrepender.java b/src/main/java/net/minecraft/network/Varint21LengthFieldPrepender.java | ||
index fb08ad8fcbecf9f38c45976a8d396ecbcb6838e3..f46bcf8806a1f7435792578bc9b529566e4a6e52 100644 | ||
--- a/src/main/java/net/minecraft/network/Varint21LengthFieldPrepender.java | ||
+++ b/src/main/java/net/minecraft/network/Varint21LengthFieldPrepender.java | ||
@@ -8,13 +8,16 @@ import io.netty.handler.codec.MessageToByteEncoder; | ||
|
||
@Sharable | ||
public class Varint21LengthFieldPrepender extends MessageToByteEncoder<ByteBuf> { | ||
- public static final int MAX_VARINT21_BYTES = 3; | ||
+ public static final int MAX_VARINT21_BYTES = org.dreeam.leaf.LeafConfig.maxVarInt21Bytes; // Leaf - Configurable max VarInt size | ||
+ public static final int DEFAULT_MAX_VARINT21_BYTES = 3; | ||
|
||
protected void encode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, ByteBuf byteBuf2) { | ||
int i = byteBuf.readableBytes(); | ||
int j = VarInt.getByteSize(i); | ||
- if (j > 3) { | ||
- throw new EncoderException("unable to fit " + i + " into 3"); | ||
+ // Leaf start - Configurable max VarInt size | ||
+ if (j > MAX_VARINT21_BYTES) { | ||
+ throw new EncoderException("unable to fit " + i + " into " + MAX_VARINT21_BYTES); | ||
+ // Leaf end | ||
} else { | ||
byteBuf2.ensureWritable(j + i); | ||
VarInt.write(byteBuf2, i); | ||
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java | ||
index 82e51da38a66826feb58fd28b39858ef91ddf7ab..2156073db27fc58e326c2c8fa4dd48dc27fe8323 100644 | ||
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java | ||
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java | ||
@@ -279,6 +279,8 @@ public class LeafConfig { | ||
public static boolean syncmaticaProtocol = false; | ||
public static boolean syncmaticaQuota = false; | ||
public static int syncmaticaQuotaLimit = 40000000; | ||
+ public static int maxVarInt21Bytes = 3; | ||
+ public static int maxVarIntBytes = 5; | ||
private static void network() { | ||
jadeProtocol = getBoolean("network.protocol.jade-protocol", jadeProtocol); | ||
appleskinProtocol = getBoolean("network.protocol.appleskin-protocol", appleskinProtocol); | ||
@@ -290,6 +292,8 @@ public class LeafConfig { | ||
if (syncmaticaProtocol) { | ||
top.leavesmc.leaves.protocol.syncmatica.SyncmaticaProtocol.init(); | ||
} | ||
+ maxVarInt21Bytes = getInt("network.netty.max-VarInt21-size", maxVarInt21Bytes); | ||
+ maxVarIntBytes = getInt("network.netty.max-VarInt-size", maxVarIntBytes); | ||
} | ||
|
||
public static String sentryDsn = ""; |