2020-05-06 09:48:49 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-11-28 02:42:42 +00: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
|
2020-08-25 02:22:08 +00:00
|
|
|
index 2fda6f6965916e99e603ff87af4226b5ab8417ee..9ea4ce3aa6a43906eb7bf9593de0191a94242da2 100644
|
2018-11-28 02:42:42 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/NetworkManager.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/NetworkManager.java
|
2020-06-26 12:04:38 +00:00
|
|
|
@@ -12,6 +12,7 @@ import io.netty.channel.epoll.EpollEventLoopGroup;
|
|
|
|
import io.netty.channel.local.LocalChannel;
|
|
|
|
import io.netty.channel.local.LocalServerChannel;
|
|
|
|
import io.netty.channel.nio.NioEventLoopGroup;
|
|
|
|
+import io.netty.handler.codec.EncoderException; // Paper
|
|
|
|
import io.netty.handler.timeout.TimeoutException;
|
|
|
|
import io.netty.util.AttributeKey;
|
|
|
|
import io.netty.util.concurrent.Future;
|
|
|
|
@@ -97,6 +98,15 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
|
2018-11-28 02:42:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void exceptionCaught(ChannelHandlerContext channelhandlercontext, Throwable throwable) {
|
|
|
|
+ // Paper start
|
2020-06-26 12:04:38 +00:00
|
|
|
+ if (throwable instanceof EncoderException && throwable.getCause() instanceof PacketEncoder.PacketTooLargeException) {
|
2018-11-28 02:42:42 +00:00
|
|
|
+ if (((PacketEncoder.PacketTooLargeException) throwable.getCause()).getPacket().packetTooLarge(this)) {
|
|
|
|
+ return;
|
|
|
|
+ } else {
|
|
|
|
+ throwable = throwable.getCause();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
if (throwable instanceof SkipEncodeException) {
|
2019-05-05 17:19:34 +00:00
|
|
|
NetworkManager.LOGGER.debug("Skipping packet due to errors", throwable.getCause());
|
2018-11-28 02:42:42 +00:00
|
|
|
} else {
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Packet.java b/src/main/java/net/minecraft/server/Packet.java
|
2020-05-06 09:48:49 +00:00
|
|
|
index 601d4d0fa2a0b3e90f81aed55a2d3473c66c7875..2d8e6a2f4a0c3c5d74a647d7164b0028781d3bf5 100644
|
2018-11-28 02:42:42 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/Packet.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Packet.java
|
2019-01-01 03:15:55 +00:00
|
|
|
@@ -10,6 +10,12 @@ public interface Packet<T extends PacketListener> {
|
2018-11-28 02:42:42 +00:00
|
|
|
|
2019-01-01 03:15:55 +00:00
|
|
|
void a(T t0);
|
2018-11-28 02:42:42 +00: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
|
2020-05-06 09:48:49 +00:00
|
|
|
index 63c4dbd327beb7b6ab42eb44650d68accd3b0de6..b0cfef52cbb5e23beae528668e4e98cedecf603c 100644
|
2018-11-28 02:42:42 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/PacketEncoder.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PacketEncoder.java
|
2019-01-01 03:15:55 +00:00
|
|
|
@@ -49,7 +49,31 @@ public class PacketEncoder extends MessageToByteEncoder<Packet<?>> {
|
2018-11-28 02:42:42 +00:00
|
|
|
throw throwable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ // Paper start
|
|
|
|
+ int packetLength = bytebuf.readableBytes();
|
|
|
|
+ if (packetLength > MAX_PACKET_SIZE) {
|
|
|
|
+ throw new PacketTooLargeException(packet, packetLength);
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-01 03:15:55 +00:00
|
|
|
+
|
2018-11-28 02:42:42 +00:00
|
|
|
+ // Paper start
|
|
|
|
+ private static int MAX_PACKET_SIZE = 2097152;
|
2018-12-17 05:18:06 +00:00
|
|
|
+
|
2018-11-28 02:42:42 +00:00
|
|
|
+ public static class PacketTooLargeException extends RuntimeException {
|
|
|
|
+ private final Packet<?> packet;
|
2018-12-17 05:18:06 +00:00
|
|
|
+
|
2018-11-28 02:42:42 +00:00
|
|
|
+ PacketTooLargeException(Packet<?> packet, int packetLength) {
|
2018-12-17 05:18:06 +00:00
|
|
|
+ super("PacketTooLarge - " + packet.getClass().getSimpleName() + " is " + packetLength + ". Max is " + MAX_PACKET_SIZE);
|
2018-11-28 02:42:42 +00:00
|
|
|
+ this.packet = packet;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Packet<?> getPacket() {
|
|
|
|
+ return packet;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2018-12-17 05:18:06 +00:00
|
|
|
}
|
2018-11-28 02:42:42 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
|
2020-08-25 02:22:08 +00:00
|
|
|
index 0ef4fbb19fc816f578ad741c4406790f4185093d..34e92e544f37167317d58af4242acde49e588673 100644
|
2018-11-28 02:42:42 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
|
2020-08-25 02:22:08 +00:00
|
|
|
@@ -79,7 +79,7 @@ public class PacketPlayOutMapChunk implements Packet<PacketListenerPlayOut> {
|
2019-12-12 16:20:43 +00:00
|
|
|
|
2019-05-05 17:19:34 +00:00
|
|
|
int i = packetdataserializer.i();
|
2019-01-01 03:15:55 +00:00
|
|
|
|
2018-11-28 02:42:42 +00: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 {
|
2019-12-12 16:20:43 +00:00
|
|
|
this.f = new byte[i];
|
2018-11-28 02:42:42 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutWindowItems.java b/src/main/java/net/minecraft/server/PacketPlayOutWindowItems.java
|
2020-08-25 02:22:08 +00:00
|
|
|
index e32db2baf84dcb192800e6048cadf3511da28181..6fb3168fd6de0074b1b378e992e4706c50ae15ab 100644
|
2018-11-28 02:42:42 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/PacketPlayOutWindowItems.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PacketPlayOutWindowItems.java
|
2019-01-01 03:15:55 +00:00
|
|
|
@@ -9,6 +9,15 @@ public class PacketPlayOutWindowItems implements Packet<PacketListenerPlayOut> {
|
2018-11-28 02:42:42 +00: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 03:15:55 +00:00
|
|
|
public PacketPlayOutWindowItems() {}
|
2018-11-28 02:42:42 +00:00
|
|
|
|
2019-01-01 03:15:55 +00:00
|
|
|
public PacketPlayOutWindowItems(int i, NonNullList<ItemStack> nonnulllist) {
|