Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 12:30:06 +01:00
928bcc8d3a
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 09943450 Update SnakeYAML version 5515734f SPIGOT-7162: Incorrect description for Entity#getVehicle javadoc 6f82b381 PR-788: Add getHand() to all relevant events CraftBukkit Changes: aaf484f6f SPIGOT-7163: CraftMerchantRecipe doesn't copy demand and specialPrice from BukkitMerchantRecipe 5329dd6fd PR-1107: Add getHand() to all relevant events 93061706e SPIGOT-7045: Ocelots never spawn with babies with spawn reason OCELOT_BABY
116 Zeilen
5.5 KiB
Diff
116 Zeilen
5.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
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/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java
|
|
index 7d85817a0a041c2fa257396d1508488bfc7da55b..870badca869aca1ad293542b345a038ddf715135 100644
|
|
--- a/src/main/java/net/minecraft/network/Connection.java
|
|
+++ b/src/main/java/net/minecraft/network/Connection.java
|
|
@@ -148,6 +148,15 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
|
}
|
|
|
|
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 SkipPacketException) {
|
|
Connection.LOGGER.debug("Skipping packet due to errors", throwable.getCause());
|
|
} else {
|
|
diff --git a/src/main/java/net/minecraft/network/PacketEncoder.java b/src/main/java/net/minecraft/network/PacketEncoder.java
|
|
index 00d432bd395e7f7fb6ee24e371818d13892b2f0c..5fce1177e7198d791d4ab1c64b394c5b1c145782 100644
|
|
--- a/src/main/java/net/minecraft/network/PacketEncoder.java
|
|
+++ b/src/main/java/net/minecraft/network/PacketEncoder.java
|
|
@@ -54,7 +54,31 @@ public class PacketEncoder extends MessageToByteEncoder<Packet<?>> {
|
|
throw var10;
|
|
}
|
|
}
|
|
+
|
|
+ // Paper start
|
|
+ int packetLength = friendlyByteBuf.readableBytes();
|
|
+ if (packetLength > MAX_PACKET_SIZE) {
|
|
+ throw new PacketTooLargeException(packet, packetLength);
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
}
|
|
}
|
|
+
|
|
+ // Paper start
|
|
+ private static int MAX_PACKET_SIZE = 2097152;
|
|
+
|
|
+ public static class PacketTooLargeException extends RuntimeException {
|
|
+ private final Packet<?> packet;
|
|
+
|
|
+ PacketTooLargeException(Packet<?> packet, int packetLength) {
|
|
+ super("PacketTooLarge - " + packet.getClass().getSimpleName() + " is " + packetLength + ". Max is " + MAX_PACKET_SIZE);
|
|
+ this.packet = packet;
|
|
+ }
|
|
+
|
|
+ public Packet<?> getPacket() {
|
|
+ return packet;
|
|
+ }
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/network/protocol/Packet.java b/src/main/java/net/minecraft/network/protocol/Packet.java
|
|
index 10c1f2d8a92f848c3f2be9d1d06fd254978e6dcc..74bfe0d3942259c45702b099efdc4e101a4e3022 100644
|
|
--- a/src/main/java/net/minecraft/network/protocol/Packet.java
|
|
+++ b/src/main/java/net/minecraft/network/protocol/Packet.java
|
|
@@ -8,6 +8,12 @@ public interface Packet<T extends PacketListener> {
|
|
|
|
void handle(T listener);
|
|
|
|
+ // Paper start
|
|
+ default boolean packetTooLarge(net.minecraft.network.Connection manager) {
|
|
+ return false;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
default boolean isSkippable() {
|
|
return false;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
|
|
index 0e076173033278587df2b5dfbd01cc9005651eb5..dbd8b9b09b82c1b75e8be9dc7416d9f0863c8c87 100644
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
|
|
@@ -31,6 +31,16 @@ public class ClientboundContainerSetContentPacket implements Packet<ClientGamePa
|
|
this.carriedItem = buf.readItem();
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public boolean packetTooLarge(net.minecraft.network.Connection manager) {
|
|
+ for (int i = 0 ; i < this.items.size() ; i++) {
|
|
+ manager.send(new ClientboundContainerSetSlotPacket(this.containerId, this.stateId, i, this.items.get(i)));
|
|
+ }
|
|
+ return true;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public void write(FriendlyByteBuf buf) {
|
|
buf.writeByte(this.containerId);
|
|
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
|
|
index cc2f53fba1e5f6b6d4d31081ddaca1ace70abf99..fef3507dbaeb963ba4132ab7beb26d22ec39d425 100644
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
|
|
@@ -50,7 +50,7 @@ public class ClientboundLevelChunkPacketData {
|
|
throw new RuntimeException("Can't read heightmap in packet for [" + x + ", " + z + "]");
|
|
} else {
|
|
int i = buf.readVarInt();
|
|
- if (i > 2097152) {
|
|
+ if (i > 2097152) { // Paper - diff on change - if this changes, update PacketEncoder
|
|
throw new RuntimeException("Chunk Packet trying to allocate too much memory on read.");
|
|
} else {
|
|
this.buffer = new byte[i];
|