mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
a76b774070
Now target all TE data, except for TE's that do not have update packets.
138 lines
6.2 KiB
Diff
138 lines
6.2 KiB
Diff
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
|
|
|