Limit config phase packet queue

This commit is contained in:
Nassim Jahnke committed 2026-05-04 20:27:30 +02:00
1 parent 1e2c5dbb7a
commit 3e8682f948
2 files changed
+19 -6

No files matched your search

@@ -272,7 +272,7 @@ public final class Protocol1_20To1_20_2 extends AbstractProtocol<ClientboundPack
}
// Queue packets sent by the server while we wait for the client to transition to the configuration state
configurationBridge.addPacketToQueue(packetWrapper, true);
configurationBridge.addClientboundPacketToQueue(packetWrapper);
throw CancelException.generate();
}
@@ -295,7 +295,7 @@ public final class Protocol1_20To1_20_2 extends AbstractProtocol<ClientboundPack
}
}
configurationBridge.addPacketToQueue(packetWrapper, true);
configurationBridge.addClientboundPacketToQueue(packetWrapper);
throw CancelException.generate();
}
@@ -315,7 +315,7 @@ public final class Protocol1_20To1_20_2 extends AbstractProtocol<ClientboundPack
} else {
// Not a packet that can be mapped to the configuration protocol
// Includes resource pack packets to make sure it is not applied sooner than the server expects
configurationBridge.addPacketToQueue(packetWrapper, true);
configurationBridge.addClientboundPacketToQueue(packetWrapper);
throw CancelException.generate();
}
return;
@@ -375,7 +375,7 @@ public final class Protocol1_20To1_20_2 extends AbstractProtocol<ClientboundPack
private PacketHandler queueServerboundPacket(final ServerboundPackets1_20_2 packetType) {
return wrapper -> {
wrapper.setPacketType(packetType);
wrapper.user().get(ConfigurationState.class).addPacketToQueue(wrapper, false);
wrapper.user().get(ConfigurationState.class).addServerboundPacketToQueue(wrapper);
wrapper.cancel();
};
}
@@ -41,6 +41,7 @@ public class ConfigurationState implements StorableObject {
private boolean queuedJoinGame;
private CompoundTag lastDimensionRegistry;
private ClientInformation clientInformation;
private int queuedServerboundBytes;
public BridgePhase bridgePhase() {
return bridgePhase;
@@ -70,8 +71,19 @@ public class ConfigurationState implements StorableObject {
this.clientInformation = clientInformation;
}
public void addPacketToQueue(final PacketWrapper wrapper, final boolean clientbound) {
packetQueue.add(toQueuedPacket(wrapper, clientbound, false));
public void addClientboundPacketToQueue(final PacketWrapper wrapper) {
packetQueue.add(toQueuedPacket(wrapper, true, false));
}
public void addServerboundPacketToQueue(final PacketWrapper wrapper) {
final QueuedPacket queued = toQueuedPacket(wrapper, false, false);
final int bytes = queued.buf().readableBytes();
if (packetQueue.size() > 5000 || queuedServerboundBytes + bytes > 2097152) {
wrapper.user().disconnect("Sent too many packets during config phase");
return;
}
queuedServerboundBytes += bytes;
packetQueue.add(queued);
}
private QueuedPacket toQueuedPacket(final PacketWrapper wrapper, final boolean clientbound, final boolean skipCurrentPipeline) {
@@ -141,6 +153,7 @@ public class ConfigurationState implements StorableObject {
packetQueue.clear();
bridgePhase = BridgePhase.NONE;
queuedJoinGame = false;
queuedServerboundBytes = 0;
}
public boolean queuedOrSentJoinGame() {