Add debug logging to packet compression encoder.

Should make figuring out who is sending large packets easier.
Disable with -Pforge.disablePacketCompressionDebug=true
This commit is contained in:
LexManos committed 2021-06-03 10:29:49 -07:00
1 parent 435e65eb18
commit b98991dc70
2 files changed
+25 -1

No files matched your search

@@ -1,6 +1,6 @@
--- a/net/minecraft/block/TripWireHookBlock.java
+++ b/net/minecraft/block/TripWireHookBlock.java
@@ -150,8 +150,8 @@
@@ -150,8 +_,8 @@
BlockPos blockpos2 = p_176260_2_.func_177967_a(direction, k);
BlockState blockstate2 = ablockstate[k];
if (blockstate2 != null) {
@@ -0,0 +1,24 @@
--- a/net/minecraft/network/NettyCompressionEncoder.java
+++ b/net/minecraft/network/NettyCompressionEncoder.java
@@ -9,6 +_,8 @@
private final byte[] field_179302_a = new byte[8192];
private final Deflater field_179300_b;
private int field_179301_c;
+ private static final boolean DISABLE_PACKET_DEBUG = Boolean.parseBoolean(System.getProperty("forge.disablePacketCompressionDebug", "false"));
+ private static final org.apache.logging.log4j.Logger LOGGER = org.apache.logging.log4j.LogManager.getLogger();
public NettyCompressionEncoder(int p_i46005_1_) {
this.field_179301_c = p_i46005_1_;
@@ -22,6 +_,12 @@
packetbuffer.func_150787_b(0);
packetbuffer.writeBytes(p_encode_2_);
} else {
+ if (!DISABLE_PACKET_DEBUG && i > 2097152) {
+ p_encode_2_.markReaderIndex();
+ LOGGER.error("Attempted to send packet over maximum protocol size: {} > 2097152\nData:\n{}", i,
+ net.minecraftforge.fml.common.network.ByteBufUtils.getContentDump(p_encode_2_));
+ p_encode_2_.resetReaderIndex();
+ }
byte[] abyte = new byte[i];
p_encode_2_.readBytes(abyte);
packetbuffer.func_150787_b(abyte.length);