2019-04-22 23:36:14 +02:00
|
|
|
From b07b820037f167f150b3af33ed2fff7e9cd88ea6 Mon Sep 17 00:00:00 2001
|
2018-11-28 03:42:42 +01:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Tue, 27 Nov 2018 21:18:06 -0500
|
|
|
|
Subject: [PATCH] Handle Large Packets disconnecting client
|
|
|
|
|
|
|
|
If a players inventory is too big to send in a single packet,
|
|
|
|
split the inventory set into multiple packets instead.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java
|
2019-04-22 23:36:14 +02:00
|
|
|
index c536979140..0b8796d0ae 100644
|
2018-11-28 03:42:42 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/NetworkManager.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/NetworkManager.java
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -99,6 +99,15 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
|
2018-11-28 03:42:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void exceptionCaught(ChannelHandlerContext channelhandlercontext, Throwable throwable) {
|
|
|
|
+ // Paper start
|
|
|
|
+ if (throwable instanceof io.netty.handler.codec.EncoderException && throwable.getCause() instanceof PacketEncoder.PacketTooLargeException) {
|
|
|
|
+ if (((PacketEncoder.PacketTooLargeException) throwable.getCause()).getPacket().packetTooLarge(this)) {
|
|
|
|
+ return;
|
|
|
|
+ } else {
|
|
|
|
+ throwable = throwable.getCause();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
if (throwable instanceof SkipEncodeException) {
|
|
|
|
NetworkManager.g.debug("Skipping packet due to errors", throwable.getCause());
|
|
|
|
} else {
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Packet.java b/src/main/java/net/minecraft/server/Packet.java
|
2019-04-22 23:36:14 +02:00
|
|
|
index 601d4d0fa2..2d8e6a2f4a 100644
|
2018-11-28 03:42:42 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/Packet.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Packet.java
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -10,6 +10,12 @@ public interface Packet<T extends PacketListener> {
|
2018-11-28 03:42:42 +01:00
|
|
|
|
2019-01-01 04:15:55 +01:00
|
|
|
void a(T t0);
|
2018-11-28 03:42:42 +01:00
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ default boolean packetTooLarge(NetworkManager manager) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
default boolean a() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PacketEncoder.java b/src/main/java/net/minecraft/server/PacketEncoder.java
|
2019-04-22 23:36:14 +02:00
|
|
|
index 2aa805eef1..4f7bc186aa 100644
|
2018-11-28 03:42:42 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/PacketEncoder.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PacketEncoder.java
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -49,7 +49,31 @@ public class PacketEncoder extends MessageToByteEncoder<Packet<?>> {
|
2018-11-28 03:42:42 +01:00
|
|
|
throw throwable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ // Paper start
|
|
|
|
+ int packetLength = bytebuf.readableBytes();
|
|
|
|
+ if (packetLength > MAX_PACKET_SIZE) {
|
|
|
|
+ throw new PacketTooLargeException(packet, packetLength);
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-01 04:15:55 +01:00
|
|
|
+
|
2018-11-28 03:42:42 +01:00
|
|
|
+ // Paper start
|
|
|
|
+ private static int MAX_PACKET_SIZE = 2097152;
|
2018-12-17 06:18:06 +01:00
|
|
|
+
|
2018-11-28 03:42:42 +01:00
|
|
|
+ public static class PacketTooLargeException extends RuntimeException {
|
|
|
|
+ private final Packet<?> packet;
|
2018-12-17 06:18:06 +01:00
|
|
|
+
|
2018-11-28 03:42:42 +01:00
|
|
|
+ PacketTooLargeException(Packet<?> packet, int packetLength) {
|
2018-12-17 06:18:06 +01:00
|
|
|
+ super("PacketTooLarge - " + packet.getClass().getSimpleName() + " is " + packetLength + ". Max is " + MAX_PACKET_SIZE);
|
2018-11-28 03:42:42 +01:00
|
|
|
+ this.packet = packet;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Packet<?> getPacket() {
|
|
|
|
+ return packet;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2018-12-17 06:18:06 +01:00
|
|
|
}
|
2018-11-28 03:42:42 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
|
2019-04-22 23:36:14 +02:00
|
|
|
index 8e35d14f97..4a57e8a3ec 100644
|
2018-11-28 03:42:42 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -76,7 +76,7 @@ public class PacketPlayOutMapChunk implements Packet<PacketListenerPlayOut> {
|
2018-11-28 03:42:42 +01:00
|
|
|
this.c = packetdataserializer.g();
|
|
|
|
int i = packetdataserializer.g();
|
2019-01-01 04:15:55 +01:00
|
|
|
|
2018-11-28 03:42:42 +01:00
|
|
|
- if (i > 2097152) {
|
|
|
|
+ if (i > 2097152) { // Paper - if this changes, update PacketEncoder
|
|
|
|
throw new RuntimeException("Chunk Packet trying to allocate too much memory on read.");
|
|
|
|
} else {
|
|
|
|
this.d = new byte[i];
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutWindowItems.java b/src/main/java/net/minecraft/server/PacketPlayOutWindowItems.java
|
2019-04-22 23:36:14 +02:00
|
|
|
index 706d843859..c0d8f8b428 100644
|
2018-11-28 03:42:42 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/PacketPlayOutWindowItems.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PacketPlayOutWindowItems.java
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -9,6 +9,15 @@ public class PacketPlayOutWindowItems implements Packet<PacketListenerPlayOut> {
|
2018-11-28 03:42:42 +01:00
|
|
|
private int a;
|
|
|
|
private List<ItemStack> b;
|
|
|
|
|
|
|
|
+ //Paper start
|
|
|
|
+ @Override
|
|
|
|
+ public boolean packetTooLarge(NetworkManager manager) {
|
|
|
|
+ for (int i = 0 ; i < this.b.size() ; i++) {
|
|
|
|
+ manager.sendPacket(new PacketPlayOutSetSlot(this.a, i, this.b.get(i)));
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2019-01-01 04:15:55 +01:00
|
|
|
public PacketPlayOutWindowItems() {}
|
2018-11-28 03:42:42 +01:00
|
|
|
|
2019-01-01 04:15:55 +01:00
|
|
|
public PacketPlayOutWindowItems(int i, NonNullList<ItemStack> nonnulllist) {
|
2018-11-28 03:42:42 +01:00
|
|
|
--
|
2019-03-20 01:28:15 +01:00
|
|
|
2.21.0
|
2018-11-28 03:42:42 +01:00
|
|
|
|