Improved oversized chunk data packet handling
Now target all TE data, except for TE's that do not have update packets.
This commit is contained in:
parent
a6f78170db
commit
a76b774070
3 changed files with 143 additions and 96 deletions
|
@ -0,0 +1,137 @@
|
|||
From 5e98ffe924abde6c9985464127a99fc2506fba12 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
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 <spottedleaf@spottedleaf.dev>
|
||||
|
||||
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<Packet<?>> {
|
||||
NetworkManager.LOGGER.debug("Set listener of {} to {}", this, packetlistener);
|
||||
this.packetListener = packetlistener;
|
||||
}
|
||||
+ // Paper start
|
||||
+ private static java.util.List<Packet> buildExtraPackets(Packet packet) {
|
||||
+ java.util.List<Packet> extra = packet.getExtraPackets();
|
||||
+ if (extra == null || extra.isEmpty()) {
|
||||
+ return null;
|
||||
+ }
|
||||
+ java.util.List<Packet> ret = new java.util.ArrayList<>(1 + extra.size());
|
||||
+ buildExtraPackets0(extra, ret);
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ private static void buildExtraPackets0(java.util.List<Packet> extraPackets, java.util.List<Packet> into) {
|
||||
+ for (Packet extra : extraPackets) {
|
||||
+ into.add(extra);
|
||||
+ java.util.List<Packet> 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<? extends Future<? super Void>> 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<Packet> extraPackets = buildExtraPackets(packet);
|
||||
+ boolean hasExtraPackets = extraPackets != null && !extraPackets.isEmpty();
|
||||
+ if (!hasExtraPackets) {
|
||||
this.packetQueue.add(new NetworkManager.QueuedPacket(packet, genericfuturelistener));
|
||||
- }
|
||||
+ } else {
|
||||
+ java.util.List<NetworkManager.QueuedPacket> 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<? extends Future<? super Void>> 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<T extends PacketListener> {
|
||||
void a(T t0);
|
||||
|
||||
// Paper start
|
||||
+ default java.util.List<Packet> 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<PacketListenerPlayOut> {
|
||||
|
||||
public PacketPlayOutMapChunk() {}
|
||||
|
||||
+ // Paper start
|
||||
+ private final java.util.List<Packet> extraPackets = new java.util.ArrayList<>();
|
||||
+ private static final int TE_LIMIT = Integer.getInteger("Paper.excessiveTELimit", 750);
|
||||
+
|
||||
+ @Override
|
||||
+ public java.util.List<Packet> getExtraPackets() {
|
||||
+ return extraPackets;
|
||||
+ }
|
||||
+ // Paper end
|
||||
public PacketPlayOutMapChunk(Chunk chunk, int i) {
|
||||
ChunkCoordIntPair chunkcoordintpair = chunk.getPos();
|
||||
|
||||
@@ -49,6 +58,7 @@ public class PacketPlayOutMapChunk implements Packet<PacketListenerPlayOut> {
|
||||
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<PacketListenerPlayOut> {
|
||||
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
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
From e2da9703f8381ba7de85b37e7c7834e9b90787ed Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
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<Packet<?>> {
|
||||
});
|
||||
}
|
||||
|
||||
+ // Paper start
|
||||
+ java.util.List<Packet> 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<T extends PacketListener> {
|
||||
void a(T t0);
|
||||
|
||||
// Paper start
|
||||
+ default java.util.List<Packet> 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<PacketListenerPlayOut> {
|
||||
|
||||
public PacketPlayOutMapChunk() {}
|
||||
|
||||
+ // Paper start
|
||||
+ private final java.util.List<Packet> extraPackets = new java.util.ArrayList<>();
|
||||
+ private static final int SKIP_EXCESSIVE_SIGNS_LIMIT = Integer.getInteger("Paper.excessiveSignsLimit", 500);
|
||||
+
|
||||
+ @Override
|
||||
+ public java.util.List<Packet> getExtraPackets() {
|
||||
+ return extraPackets;
|
||||
+ }
|
||||
+ // Paper end
|
||||
public PacketPlayOutMapChunk(Chunk chunk, int i) {
|
||||
ChunkCoordIntPair chunkcoordintpair = chunk.getPos();
|
||||
|
||||
@@ -49,6 +58,7 @@ public class PacketPlayOutMapChunk implements Packet<PacketListenerPlayOut> {
|
||||
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<PacketListenerPlayOut> {
|
||||
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
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
From 3e2e32910c3a6bf594339dece51f0618de7a8506 Mon Sep 17 00:00:00 2001
|
||||
From bf95ae8ab5e6e73929fdf02bc049c33b55178c32 Mon Sep 17 00:00:00 2001
|
||||
From: stonar96 <minecraft.stonar96@gmail.com>
|
||||
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<PacketListenerPlayOut> {
|
||||
int totalTileEntities = 0; // Paper
|
||||
@@ -82,9 +97,19 @@ public class PacketPlayOutMapChunk implements Packet<PacketListenerPlayOut> {
|
||||
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<PacketListenerPlayOut> {
|
||||
@@ -151,6 +176,11 @@ public class PacketPlayOutMapChunk implements Packet<PacketListenerPlayOut> {
|
||||
|
||||
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<PacketListenerPlayOut> {
|
||||
@@ -160,7 +190,8 @@ public class PacketPlayOutMapChunk implements Packet<PacketListenerPlayOut> {
|
||||
|
||||
if (chunksection != Chunk.a && (!this.f() || !chunksection.c()) && (i & 1 << k) != 0) {
|
||||
j |= 1 << k;
|
||||
|
|
Loading…
Reference in a new issue