diff --git a/removed-patches-1-20-5/0284-Handle-Large-Packets-disconnecting-client.patch b/patches/server/Handle-Large-Packets-disconnecting-client.patch similarity index 71% rename from removed-patches-1-20-5/0284-Handle-Large-Packets-disconnecting-client.patch rename to patches/server/Handle-Large-Packets-disconnecting-client.patch index 8564779c08..4f318b7928 100644 --- a/removed-patches-1-20-5/0284-Handle-Large-Packets-disconnecting-client.patch +++ b/patches/server/Handle-Large-Packets-disconnecting-client.patch @@ -17,13 +17,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start - Handle large packets disconnecting client + if (throwable instanceof io.netty.handler.codec.EncoderException && throwable.getCause() instanceof PacketEncoder.PacketTooLargeException packetTooLargeException) { + final Packet packet = packetTooLargeException.getPacket(); -+ final io.netty.util.Attribute> codecDataAttribute = channelhandlercontext.channel().attr(packetTooLargeException.codecKey); + if (packet.packetTooLarge(this)) { -+ ProtocolSwapHandler.swapProtocolIfNeeded(codecDataAttribute, packet); ++ ProtocolSwapHandler.handleOutboundTerminalPacket(channelhandlercontext, packet); + return; + } else if (packet.isSkippable()) { + Connection.LOGGER.debug("Skipping packet due to errors", throwable.getCause()); -+ ProtocolSwapHandler.swapProtocolIfNeeded(codecDataAttribute, packet); ++ ProtocolSwapHandler.handleOutboundTerminalPacket(channelhandlercontext, packet); + return; + } else { + throwable = throwable.getCause(); @@ -37,42 +36,32 @@ diff --git a/src/main/java/net/minecraft/network/PacketEncoder.java b/src/main/j index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/network/PacketEncoder.java +++ b/src/main/java/net/minecraft/network/PacketEncoder.java -@@ -0,0 +0,0 @@ public class PacketEncoder extends MessageToByteEncoder> { - int j = friendlyByteBuf.writerIndex(); - packet.write(friendlyByteBuf); - int k = friendlyByteBuf.writerIndex() - j; -- if (k > 8388608) { -+ if (false && k > 8388608) { // Paper - Handle large packets disconnecting client; disable - throw new IllegalArgumentException("Packet too big (is " + k + ", should be less than 8388608): " + packet); - } +@@ -0,0 +0,0 @@ public class PacketEncoder extends MessageToByteEncode -@@ -0,0 +0,0 @@ public class PacketEncoder extends MessageToByteEncoder> { - - throw var13; - } finally { -+ // Paper start - Handle large packets disconnecting client -+ int packetLength = friendlyByteBuf.readableBytes(); -+ if (packetLength > MAX_PACKET_SIZE) { -+ throw new PacketTooLargeException(packet, this.codecKey, packetLength); -+ } -+ // Paper end - Handle large packets disconnecting client - ProtocolSwapHandler.swapProtocolIfNeeded(attribute, packet); - } - } + throw var9; + } finally { ++ // Paper start - Handle large packets disconnecting client ++ int packetLength = byteBuf.readableBytes(); ++ if (packetLength > MAX_PACKET_SIZE || (packetLength > MAX_FINAL_PACKET_SIZE && packet.hasLargePacketFallback())) { ++ throw new PacketTooLargeException(packet, packetLength); ++ } ++ // Paper end - Handle large packets disconnecting client + ProtocolSwapHandler.handleOutboundTerminalPacket(channelHandlerContext, packet); } } + + // Paper start -+ private static int MAX_PACKET_SIZE = 8388608; ++ // packet size is encoded into 3-byte varint ++ private static final int MAX_FINAL_PACKET_SIZE = (1 << 21) - 1; ++ // Vanilla Max size for the encoder (before compression) ++ private static final int MAX_PACKET_SIZE = 8388608; + + public static class PacketTooLargeException extends RuntimeException { + private final Packet packet; -+ public final AttributeKey> codecKey; + -+ PacketTooLargeException(Packet packet, AttributeKey> codecKey, int packetLength) { ++ PacketTooLargeException(Packet packet, int packetLength) { + super("PacketTooLarge - " + packet.getClass().getSimpleName() + " is " + packetLength + ". Max is " + MAX_PACKET_SIZE); + this.packet = packet; -+ this.codecKey = codecKey; + } + + public Packet getPacket() { @@ -90,6 +79,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 void handle(T listener); + // Paper start ++ default boolean hasLargePacketFallback() { ++ return false; ++ } ++ ++ /** ++ * override {@link #hasLargePacketFallback()} to return true when overriding in subclasses ++ */ + default boolean packetTooLarge(net.minecraft.network.Connection manager) { + return false; + } @@ -103,10 +99,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java +++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java @@ -0,0 +0,0 @@ public class ClientboundContainerSetContentPacket implements Packet