fix #1695: add "velocity.legacyChatMaxServerboundLength" system property to allow overriding default legacy chat max length

This commit is contained in:
Riley Park
2026-01-25 21:20:14 -08:00
parent fe8dc5eaa2
commit 5320aae5d9

View File

@@ -32,12 +32,24 @@ public class LegacyChatPacket implements MinecraftPacket {
public static final byte GAME_INFO_TYPE = (byte) 2;
public static final int MAX_SERVERBOUND_MESSAGE_LENGTH = 256;
private static final int MAX_SERVERBOUND_MESSAGE_LENGTH_LEGACY = getMaxServerboundMessageLength();
public static final UUID EMPTY_SENDER = new UUID(0, 0);
private @Nullable String message;
private byte type;
private @Nullable UUID sender;
private static int getMaxServerboundMessageLength() {
final String value = System.getProperty("velocity.legacyChatMaxServerboundLength");
if (value != null) {
try {
return Integer.parseInt(value.trim());
} catch (final NumberFormatException e) {
}
}
return 100;
}
public LegacyChatPacket() {
}
@@ -92,7 +104,10 @@ public class LegacyChatPacket implements MinecraftPacket {
@Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
message = ProtocolUtils.readString(buf, direction == ProtocolUtils.Direction.CLIENTBOUND
? 262144 : version.noLessThan(ProtocolVersion.MINECRAFT_1_11) ? 256 : 100);
? 262144
: version.noLessThan(ProtocolVersion.MINECRAFT_1_11)
? MAX_SERVERBOUND_MESSAGE_LENGTH
: MAX_SERVERBOUND_MESSAGE_LENGTH_LEGACY);
if (direction == ProtocolUtils.Direction.CLIENTBOUND
&& version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
type = buf.readByte();