Waterfall/Waterfall-Proxy-Patches/0025-Apply-packet-limits.patch
2023-03-14 15:00:06 -03:00

72 lines
3.1 KiB
Diff

From 1bc16d636d3833dc1f8b8f2d1a88c9e87f40106b Mon Sep 17 00:00:00 2001
From: LinsaFTW <25271111+linsaftw@users.noreply.github.com>
Date: Thu, 10 Jun 2021 11:30:19 -0300
Subject: [PATCH] Apply packet limits
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionRequest.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionRequest.java
index e78519964..222285cc1 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionRequest.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/EncryptionRequest.java
@@ -61,4 +61,14 @@ public class EncryptionRequest extends DefinedPacket
{
handler.handle( this );
}
+
+ @Override
+ public int expectedMaxLength(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
+ return 20 + 256 + 256; // FlameCord - Apply packet limits
+ }
+
+ @Override
+ public int expectedMinLength(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
+ return 20 + 1 + 1; // FlameCord - Apply packet limits
+ }
}
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java
index 7dbbfd3cd..b78420556 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Handshake.java
@@ -7,6 +7,7 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import net.md_5.bungee.protocol.AbstractPacketHandler;
import net.md_5.bungee.protocol.DefinedPacket;
+import net.md_5.bungee.protocol.ProtocolConstants;
@Data
@NoArgsConstructor
@@ -43,4 +44,14 @@ public class Handshake extends DefinedPacket
{
handler.handle( this );
}
+
+ @Override
+ public int expectedMaxLength(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
+ return 1036 + 256; // FlameCord - Apply packet limits
+ }
+
+ @Override
+ public int expectedMinLength(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
+ return 5; // FlameCord - Apply packet limits
+ }
}
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginRequest.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginRequest.java
index d0e37793d..763d34c2f 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginRequest.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/LoginRequest.java
@@ -70,8 +70,9 @@ public class LoginRequest extends DefinedPacket
public int expectedMaxLength(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
// Accommodate the rare (but likely malicious) use of UTF-8 usernames, since it is technically
// legal on the protocol level.
- if (protocolVersion >= ProtocolConstants.MINECRAFT_1_19) return -1;
- return 1 + (16 * 3);
+ // FlameCord - Apply packet limits
+ if (protocolVersion >= ProtocolConstants.MINECRAFT_1_19) return 1 + (16 * 4) + 1024;
+ return 1 + (16 * 4);
}
// Waterfall end
}
--
2.37.3.windows.1