2022-06-09 10:51:45 +02:00
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
2024-01-23 15:43:48 +01:00
index dc9f8625e15c49ea64d2b7d9515d36d5ef834820..777681a58417684a35a875c869ab22e50bb27da5 100644
2022-06-09 10:51:45 +02:00
--- a/src/main/java/net/minecraft/network/Connection.java
+++ b/src/main/java/net/minecraft/network/Connection.java
2024-01-23 15:43:48 +01:00
@@ -415,14 +415,29 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
}
2022-06-09 10:51:45 +02:00
}
2024-01-20 23:13:41 +01:00
+ 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
2022-06-09 10:51:45 +02:00
public void tick() {
this.flushQueue();
2024-01-20 23:13:41 +01:00
+ // Paper start - Buffer joins to world
2022-12-21 22:55:42 +01:00
+ if (Connection.currTick != net.minecraft.server.MinecraftServer.currentTick) {
+ Connection.currTick = net.minecraft.server.MinecraftServer.currentTick;
+ Connection.joinAttemptsThisTick = 0;
2022-06-09 10:51:45 +02:00
+ }
2024-01-20 23:13:41 +01:00
+ // Paper end - Buffer joins to world
2022-07-27 22:46:05 +02:00
PacketListener packetlistener = this.packetListener;
2022-06-09 10:51:45 +02:00
2022-07-27 22:46:05 +02:00
if (packetlistener instanceof TickablePacketListener) {
2022-12-21 22:55:42 +01:00
TickablePacketListener tickablepacketlistener = (TickablePacketListener) packetlistener;
2024-01-20 23:13:41 +01:00
+ // Paper start - Buffer joins to world
2022-12-21 22:55:42 +01:00
+ if (!(this.packetListener instanceof net.minecraft.server.network.ServerLoginPacketListenerImpl loginPacketListener)
2023-09-23 00:33:14 +02:00
+ || loginPacketListener.state != net.minecraft.server.network.ServerLoginPacketListenerImpl.State.VERIFYING
2022-12-21 22:55:42 +01:00
+ || Connection.joinAttemptsThisTick++ < MAX_PER_TICK) {
tickablepacketlistener.tick();
+ }
2024-01-20 23:13:41 +01:00
+ // Paper end - Buffer joins to world
2022-12-21 22:55:42 +01:00
}
if (!this.isConnected() && !this.disconnectionHandled) {