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.
|
|
|
|
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/network/NetworkManager.java b/src/main/java/net/minecraft/network/NetworkManager.java
|
|
|
|
index 297820baef99e97e1216a64c527219e9ccc3e320..dc788d75a6a34fbbae990609bfbbd13ca6cdee5a 100644
|
|
|
|
--- a/src/main/java/net/minecraft/network/NetworkManager.java
|
|
|
|
+++ b/src/main/java/net/minecraft/network/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;
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -107,6 +108,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 {
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/network/PacketEncoder.java b/src/main/java/net/minecraft/network/PacketEncoder.java
|
|
|
|
index 2f6da89d6b25ba5144ec15b1bf0e8ed13278e85e..037d989522d24a55eced1c462d40a6dc2a7ecfce 100644
|
|
|
|
--- a/src/main/java/net/minecraft/network/PacketEncoder.java
|
|
|
|
+++ b/src/main/java/net/minecraft/network/PacketEncoder.java
|
|
|
|
@@ -53,7 +53,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
|
|
|
}
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/network/protocol/Packet.java b/src/main/java/net/minecraft/network/protocol/Packet.java
|
|
|
|
index cd4493a023748264748d4e892815f14d8a7bd7f6..0783b0777c8d7788bbf6780b464b709bf6dc2191 100644
|
|
|
|
--- a/src/main/java/net/minecraft/network/protocol/Packet.java
|
|
|
|
+++ b/src/main/java/net/minecraft/network/protocol/Packet.java
|
|
|
|
@@ -12,6 +12,12 @@ public interface Packet<T extends PacketListener> {
|
|
|
|
|
|
|
|
void a(T t0);
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ default boolean packetTooLarge(NetworkManager manager) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
default boolean a() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutMapChunk.java b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutMapChunk.java
|
2021-03-16 13:04:28 +00:00
|
|
|
index 152118729b1a95dcae05d32aa4289034ba394226..0059ede4ba3ff271d47dd38ea87fddc2399aa008 100644
|
2021-03-16 07:19:45 +00:00
|
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutMapChunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutMapChunk.java
|
2021-03-16 13:04:28 +00:00
|
|
|
@@ -91,7 +91,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];
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutWindowItems.java b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutWindowItems.java
|
2021-03-16 13:04:28 +00:00
|
|
|
index b90e35a0099a2482f8fc2998bd079fc2fe6439e6..e540f95a370c627d3d81e0d3670049d01923559d 100644
|
2021-03-16 07:19:45 +00:00
|
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutWindowItems.java
|
|
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutWindowItems.java
|
2021-03-16 13:04:28 +00:00
|
|
|
@@ -4,6 +4,7 @@ import java.io.IOException;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import net.minecraft.core.NonNullList;
|
|
|
|
+import net.minecraft.network.NetworkManager;
|
|
|
|
import net.minecraft.network.PacketDataSerializer;
|
|
|
|
import net.minecraft.network.protocol.Packet;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
|
|
|
@@ -13,6 +14,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) {
|