From a76b774070d142825a14084fb48f1854e87693bc Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Fri, 1 May 2020 23:18:33 -0400 Subject: [PATCH] Improved oversized chunk data packet handling Now target all TE data, except for TE's that do not have update packets. --- ...-Signs-in-Chunks-creating-large-pack.patch | 137 ++++++++++++++++++ ...-Signs-in-Chunks-creating-too-large-.patch | 90 ------------ Spigot-Server-Patches/0384-Anti-Xray.patch | 12 +- 3 files changed, 143 insertions(+), 96 deletions(-) create mode 100644 Spigot-Server-Patches/0347-Handle-Excessive-Signs-in-Chunks-creating-large-pack.patch delete mode 100644 Spigot-Server-Patches/0347-Handle-Excessive-Signs-in-Chunks-creating-too-large-.patch diff --git a/Spigot-Server-Patches/0347-Handle-Excessive-Signs-in-Chunks-creating-large-pack.patch b/Spigot-Server-Patches/0347-Handle-Excessive-Signs-in-Chunks-creating-large-pack.patch new file mode 100644 index 000000000..1848f0220 --- /dev/null +++ b/Spigot-Server-Patches/0347-Handle-Excessive-Signs-in-Chunks-creating-large-pack.patch @@ -0,0 +1,137 @@ +From 5e98ffe924abde6c9985464127a99fc2506fba12 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 large packets + +Also adds a limit to stop sending Sign and other data to client after +a significant amount have been sent. + +Use -DPaper.excessiveTELimit=750 to configure that limit, or -1 +to disable the limit and let your players be abused. + +With further contributions from + +Co-Authored-by: Spottedleaf + +diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java +index b1dededc15..ddc12364e7 100644 +--- a/src/main/java/net/minecraft/server/NetworkManager.java ++++ b/src/main/java/net/minecraft/server/NetworkManager.java +@@ -158,19 +158,53 @@ public class NetworkManager extends SimpleChannelInboundHandler> { + NetworkManager.LOGGER.debug("Set listener of {} to {}", this, packetlistener); + this.packetListener = packetlistener; + } ++ // Paper start ++ private static java.util.List buildExtraPackets(Packet packet) { ++ java.util.List extra = packet.getExtraPackets(); ++ if (extra == null || extra.isEmpty()) { ++ return null; ++ } ++ java.util.List ret = new java.util.ArrayList<>(1 + extra.size()); ++ buildExtraPackets0(extra, ret); ++ return ret; ++ } ++ ++ private static void buildExtraPackets0(java.util.List extraPackets, java.util.List into) { ++ for (Packet extra : extraPackets) { ++ into.add(extra); ++ java.util.List extraExtra = extra.getExtraPackets(); ++ if (extraExtra != null && !extraExtra.isEmpty()) { ++ buildExtraPackets0(extraExtra, into); ++ } ++ } ++ } ++ // Paper end + + public void sendPacket(Packet packet) { + this.sendPacket(packet, (GenericFutureListener) null); + } + + public void sendPacket(Packet packet, @Nullable GenericFutureListener> genericfuturelistener) { +- if (this.isConnected()) { +- this.o(); +- this.b(packet, genericfuturelistener); +- } else { ++ // Paper start start - handle oversized packets better ++ // write the packets to the queue, then flush - antixray hooks there already ++ java.util.List extraPackets = buildExtraPackets(packet); ++ boolean hasExtraPackets = extraPackets != null && !extraPackets.isEmpty(); ++ if (!hasExtraPackets) { + this.packetQueue.add(new NetworkManager.QueuedPacket(packet, genericfuturelistener)); +- } ++ } else { ++ java.util.List packets = new java.util.ArrayList<>(1 + extraPackets.size()); ++ packets.add(new NetworkManager.QueuedPacket(packet, null)); // delay the future listener until the end of the extra packets + ++ for (int i = 0, len = extraPackets.size(); i < len;) { ++ Packet extra = extraPackets.get(i); ++ boolean end = ++i == len; ++ packets.add(new NetworkManager.QueuedPacket(extra, end ? genericfuturelistener : null)); // append listener to the end ++ } ++ ++ this.packetQueue.addAll(packets); // atomic ++ } ++ this.sendPacketQueue(); // ensure only one flush call is made ++ // Paper end + } + + private void dispatchPacket(Packet packet, @Nullable GenericFutureListener> genericFutureListener) { this.b(packet, genericFutureListener); } // Paper - OBFHELPER +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 +@@ -11,6 +11,7 @@ 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 a0b87f89df..23223f3f45 100644 +--- a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java ++++ b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java +@@ -23,6 +23,15 @@ public class PacketPlayOutMapChunk implements Packet { + + public PacketPlayOutMapChunk() {} + ++ // Paper start ++ private final java.util.List extraPackets = new java.util.ArrayList<>(); ++ private static final int TE_LIMIT = Integer.getInteger("Paper.excessiveTELimit", 750); ++ ++ @Override ++ public java.util.List getExtraPackets() { ++ return extraPackets; ++ } ++ // Paper end + public PacketPlayOutMapChunk(Chunk chunk, int i) { + ChunkCoordIntPair chunkcoordintpair = chunk.getPos(); + +@@ -49,6 +58,7 @@ public class PacketPlayOutMapChunk implements Packet { + this.c = this.a(new PacketDataSerializer(this.j()), chunk, i); + this.g = Lists.newArrayList(); + iterator = chunk.getTileEntities().entrySet().iterator(); ++ int totalTileEntities = 0; // Paper + + while (iterator.hasNext()) { + entry = (Entry) iterator.next(); +@@ -57,6 +67,15 @@ public class PacketPlayOutMapChunk implements Packet { + int j = blockposition.getY() >> 4; + + if (this.f() || (i & 1 << j) != 0) { ++ // Paper start - improve oversized chunk data packet handling ++ if (++totalTileEntities > TE_LIMIT) { ++ PacketPlayOutTileEntityData updatePacket = tileentity.getUpdatePacket(); ++ if (updatePacket != null) { ++ this.extraPackets.add(updatePacket); ++ continue; ++ } ++ } ++ // Paper end + NBTTagCompound nbttagcompound = tileentity.b(); + if (tileentity instanceof TileEntitySkull) { TileEntitySkull.sanitizeTileEntityUUID(nbttagcompound); } // Paper + +-- +2.26.2 + diff --git a/Spigot-Server-Patches/0347-Handle-Excessive-Signs-in-Chunks-creating-too-large-.patch b/Spigot-Server-Patches/0347-Handle-Excessive-Signs-in-Chunks-creating-too-large-.patch deleted file mode 100644 index 73c11093b..000000000 --- a/Spigot-Server-Patches/0347-Handle-Excessive-Signs-in-Chunks-creating-too-large-.patch +++ /dev/null @@ -1,90 +0,0 @@ -From e2da9703f8381ba7de85b37e7c7834e9b90787ed 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 b1dededc15..e156804f7a 100644 ---- a/src/main/java/net/minecraft/server/NetworkManager.java -+++ b/src/main/java/net/minecraft/server/NetworkManager.java -@@ -212,6 +212,15 @@ 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 -+ - } - - private void sendPacketQueue() { this.o(); } // Paper - OBFHELPER -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 -@@ -11,6 +11,7 @@ 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 a0b87f89df..47710067a6 100644 ---- a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java -+++ b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java -@@ -23,6 +23,15 @@ public class PacketPlayOutMapChunk implements Packet { - - public PacketPlayOutMapChunk() {} - -+ // 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); -+ -+ @Override -+ public java.util.List getExtraPackets() { -+ return extraPackets; -+ } -+ // Paper end - public PacketPlayOutMapChunk(Chunk chunk, int i) { - ChunkCoordIntPair chunkcoordintpair = chunk.getPos(); - -@@ -49,6 +58,7 @@ public class PacketPlayOutMapChunk implements Packet { - this.c = this.a(new PacketDataSerializer(this.j()), chunk, i); - this.g = Lists.newArrayList(); - iterator = chunk.getTileEntities().entrySet().iterator(); -+ int totalSigns = 0; // Paper - - while (iterator.hasNext()) { - entry = (Entry) iterator.next(); -@@ -57,6 +67,14 @@ 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) { -+ this.extraPackets.add(tileentity.getUpdatePacket()); -+ } -+ continue; -+ } -+ // Paper end - NBTTagCompound nbttagcompound = tileentity.b(); - if (tileentity instanceof TileEntitySkull) { TileEntitySkull.sanitizeTileEntityUUID(nbttagcompound); } // Paper - --- -2.26.2 - diff --git a/Spigot-Server-Patches/0384-Anti-Xray.patch b/Spigot-Server-Patches/0384-Anti-Xray.patch index 82b2eba74..44203e652 100644 --- a/Spigot-Server-Patches/0384-Anti-Xray.patch +++ b/Spigot-Server-Patches/0384-Anti-Xray.patch @@ -1,4 +1,4 @@ -From 3e2e32910c3a6bf594339dece51f0618de7a8506 Mon Sep 17 00:00:00 2001 +From bf95ae8ab5e6e73929fdf02bc049c33b55178c32 Mon Sep 17 00:00:00 2001 From: stonar96 Date: Mon, 20 Aug 2018 03:03:58 +0200 Subject: [PATCH] Anti-Xray @@ -1440,7 +1440,7 @@ index e156804f7a..96a785af27 100644 public void a() { this.o(); diff --git a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java -index 47710067a6..ef7ade797b 100644 +index 23223f3f45..e54663c214 100644 --- a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java +++ b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java @@ -1,5 +1,6 @@ @@ -1489,8 +1489,8 @@ index 47710067a6..ef7ade797b 100644 + this.c = this.writeChunk(new PacketDataSerializer(this.j()), chunk, i, chunkPacketInfo); // Paper - Anti-Xray - Add chunk packet info this.g = Lists.newArrayList(); iterator = chunk.getTileEntities().entrySet().iterator(); - int totalSigns = 0; // Paper -@@ -81,9 +96,19 @@ public class PacketPlayOutMapChunk implements Packet { + int totalTileEntities = 0; // Paper +@@ -82,9 +97,19 @@ public class PacketPlayOutMapChunk implements Packet { this.g.add(nbttagcompound); } } @@ -1510,7 +1510,7 @@ index 47710067a6..ef7ade797b 100644 @Override public void a(PacketDataSerializer packetdataserializer) throws IOException { this.a = packetdataserializer.readInt(); -@@ -150,6 +175,11 @@ public class PacketPlayOutMapChunk implements Packet { +@@ -151,6 +176,11 @@ public class PacketPlayOutMapChunk implements Packet { public int writeChunk(PacketDataSerializer packetDataSerializer, Chunk chunk, int chunkSectionSelector) { return this.a(packetDataSerializer, chunk, chunkSectionSelector); } // Paper - OBFHELPER public int a(PacketDataSerializer packetdataserializer, Chunk chunk, int i) { @@ -1522,7 +1522,7 @@ index 47710067a6..ef7ade797b 100644 int j = 0; ChunkSection[] achunksection = chunk.getSections(); int k = 0; -@@ -159,7 +189,8 @@ public class PacketPlayOutMapChunk implements Packet { +@@ -160,7 +190,8 @@ public class PacketPlayOutMapChunk implements Packet { if (chunksection != Chunk.a && (!this.f() || !chunksection.c()) && (i & 1 << k) != 0) { j |= 1 << k;