From a447688e18c89d59b8c9c44c1cad5a7c5904bb04 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 2 Mar 2019 15:29:46 -0500 Subject: [PATCH] Handle Excessive Signs in Chunks creating too large of packets Also adds a limit to stop sending Sign data to client after 500 signs per chunk to limit client lag. Use -DPaper.excessiveSignsLimit=500 to configure that limit, or -1 to disable the limit and let your players be abused. fixes #1878 --- ...-Signs-in-Chunks-creating-too-large-.patch | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Spigot-Server-Patches/Handle-Excessive-Signs-in-Chunks-creating-too-large-.patch diff --git a/Spigot-Server-Patches/Handle-Excessive-Signs-in-Chunks-creating-too-large-.patch b/Spigot-Server-Patches/Handle-Excessive-Signs-in-Chunks-creating-too-large-.patch new file mode 100644 index 0000000000..9b1c84e23d --- /dev/null +++ b/Spigot-Server-Patches/Handle-Excessive-Signs-in-Chunks-creating-too-large-.patch @@ -0,0 +1,87 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Sat, 2 Mar 2019 14:55:01 -0500 +Subject: [PATCH] Handle Excessive Signs in Chunks creating too large of + packets + +Also adds a limit to stop sending Sign data to client after 500 +signs per chunk to limit client lag. + +Use -DPaper.excessiveSignsLimit=500 to configure that limit, or -1 +to disable the limit and let your players be abused. + +diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java +index 553637239c..30f646e421 100644 +--- a/src/main/java/net/minecraft/server/NetworkManager.java ++++ b/src/main/java/net/minecraft/server/NetworkManager.java +@@ -0,0 +0,0 @@ public class NetworkManager extends SimpleChannelInboundHandler> { + }); + } + ++ // Paper start ++ java.util.List extraPackets = packet.getExtraPackets(); ++ if (extraPackets != null && !extraPackets.isEmpty()) { ++ for (Packet extraPacket : extraPackets) { ++ this.dispatchPacket(extraPacket, genericfuturelistener); ++ } ++ } ++ // Paper end ++ + } + + // Paper start - Async-Anti-Xray - Stop dispatching further packets and return false if the peeked packet is a chunk packet which is not ready +diff --git a/src/main/java/net/minecraft/server/Packet.java b/src/main/java/net/minecraft/server/Packet.java +index 2d8e6a2f4a..8d0965a053 100644 +--- a/src/main/java/net/minecraft/server/Packet.java ++++ b/src/main/java/net/minecraft/server/Packet.java +@@ -0,0 +0,0 @@ public interface Packet { + void a(T t0); + + // Paper start ++ default java.util.List getExtraPackets() { return null; } + default boolean packetTooLarge(NetworkManager manager) { + return false; + } +diff --git a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java +index 4a57e8a3ec..eb54bdb642 100644 +--- a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java ++++ b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java +@@ -0,0 +0,0 @@ public class PacketPlayOutMapChunk implements Packet { + this.ready = true; // Paper - Async-Anti-Xray - Set the ready flag to true + } + ++ // Paper start ++ private final java.util.List extraPackets = new java.util.ArrayList<>(); ++ private static final int SKIP_EXCESSIVE_SIGNS_LIMIT = Integer.getInteger("Paper.excessiveSignsLimit", 500); ++ public java.util.List getExtraPackets() { ++ return extraPackets; ++ } ++ // Paper end + public PacketPlayOutMapChunk(Chunk chunk, int i) { + ChunkPacketInfo chunkPacketInfo = chunk.world.chunkPacketBlockController.getChunkPacketInfo(this, chunk, i); // Paper - Anti-Xray - Add chunk packet info + this.a = chunk.locX; +@@ -0,0 +0,0 @@ public class PacketPlayOutMapChunk implements Packet { + this.c = this.writeChunk(new PacketDataSerializer(this.h()), chunk, flag, i, chunkPacketInfo); // Paper - Anti-Xray - Add chunk packet info + this.e = Lists.newArrayList(); + Iterator iterator = chunk.getTileEntities().entrySet().iterator(); ++ int totalSigns = 0; // Paper + + while (iterator.hasNext()) { + Entry entry = (Entry) iterator.next(); +@@ -0,0 +0,0 @@ public class PacketPlayOutMapChunk implements Packet { + int j = blockposition.getY() >> 4; + + if (this.f() || (i & 1 << j) != 0) { ++ // Paper start - send signs separately ++ if (tileentity instanceof TileEntitySign) { ++ if (SKIP_EXCESSIVE_SIGNS_LIMIT < 0 || ++totalSigns < SKIP_EXCESSIVE_SIGNS_LIMIT) { ++ extraPackets.add(tileentity.getUpdatePacket()); ++ } ++ continue; ++ } ++ // Paper end ++ + NBTTagCompound nbttagcompound = tileentity.aa_(); + if (tileentity instanceof TileEntitySkull) { TileEntitySkull.sanitizeTileEntityUUID(nbttagcompound); } // Paper + +-- \ No newline at end of file