PaperMC/patches/server/0421-Buffer-joins-to-world.patch
Owen 89d51d5f29
Allow enabling sand duping (#10191)
Because this exploit has been widely known for years and has not been fixed by Mojang, we decided that it was worth allowing people to toggle it on/off due to how easy it is to make it configurable.

It should be noted that this decision does not promise all future exploits will be configurable.
2024-03-03 17:05:34 -05:00

43 lines
2.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Wed, 19 Aug 2020 05:05:54 +0100
Subject: [PATCH] Buffer joins to world
This patch buffers the number of logins which will attempt to join
the world per tick, this attempts to reduce the impact that join floods
has on the server
diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java
index 44e62675a2d612a8d727d9ce6db5fb85d1a0bcc8..1113380f6f142d2faf36191aae158c747bed5bb9 100644
--- a/src/main/java/net/minecraft/network/Connection.java
+++ b/src/main/java/net/minecraft/network/Connection.java
@@ -415,14 +415,29 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
}
}
+ private static final int MAX_PER_TICK = io.papermc.paper.configuration.GlobalConfiguration.get().misc.maxJoinsPerTick; // Paper - Buffer joins to world
+ private static int joinAttemptsThisTick; // Paper - Buffer joins to world
+ private static int currTick; // Paper - Buffer joins to world
public void tick() {
this.flushQueue();
+ // Paper start - Buffer joins to world
+ if (Connection.currTick != net.minecraft.server.MinecraftServer.currentTick) {
+ Connection.currTick = net.minecraft.server.MinecraftServer.currentTick;
+ Connection.joinAttemptsThisTick = 0;
+ }
+ // Paper end - Buffer joins to world
PacketListener packetlistener = this.packetListener;
if (packetlistener instanceof TickablePacketListener) {
TickablePacketListener tickablepacketlistener = (TickablePacketListener) packetlistener;
+ // Paper start - Buffer joins to world
+ if (!(this.packetListener instanceof net.minecraft.server.network.ServerLoginPacketListenerImpl loginPacketListener)
+ || loginPacketListener.state != net.minecraft.server.network.ServerLoginPacketListenerImpl.State.VERIFYING
+ || Connection.joinAttemptsThisTick++ < MAX_PER_TICK) {
tickablepacketlistener.tick();
+ }
+ // Paper end - Buffer joins to world
}
if (!this.isConnected() && !this.disconnectionHandled) {