From 74d2746308f829b622d41412e1a4979b429069fe Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Tue, 25 Aug 2020 12:30:57 +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 --- .../0564-Buffer-joins-to-world.patch | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Spigot-Server-Patches/0564-Buffer-joins-to-world.patch diff --git a/Spigot-Server-Patches/0564-Buffer-joins-to-world.patch b/Spigot-Server-Patches/0564-Buffer-joins-to-world.patch new file mode 100644 index 000000000..3e5ae0425 --- /dev/null +++ b/Spigot-Server-Patches/0564-Buffer-joins-to-world.patch @@ -0,0 +1,50 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Shane Freeder +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/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java +index 9fc12595a566f216620a7fb296d2d30e22332689..83a2363adef4a29547b81be61e260bbdc59b9fd5 100644 +--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java ++++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java +@@ -452,4 +452,9 @@ public class PaperConfig { + maxPlayerAutoSavePerTick = (playerAutoSaveRate == -1 || playerAutoSaveRate > 100) ? 10 : 20; + } + } ++ ++ public static int maxJoinsPerTick; ++ private static void maxJoinsPerTick() { ++ getInt("settings.max-joins-per-tick", 3); ++ } + } +diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java +index 48fc9f40050685ea08af8da54ae8a00cf3d8ee36..c9b36e6040f03e6cee46989bab8415d829f8eef4 100644 +--- a/src/main/java/net/minecraft/server/NetworkManager.java ++++ b/src/main/java/net/minecraft/server/NetworkManager.java +@@ -363,10 +363,22 @@ public class NetworkManager extends SimpleChannelInboundHandler> { + } + // Paper end + ++ private static final int MAX_PER_TICK = com.destroystokyo.paper.PaperConfig.maxJoinsPerTick; // Paper ++ private static int joinAttemptsThisTick; // Paper ++ private static int currTick; // Paper + public void a() { + this.p(); ++ // Paper start ++ if (currTick != MinecraftServer.currentTick) { ++ currTick = MinecraftServer.currentTick; ++ joinAttemptsThisTick = 0; ++ } ++ // Paper end + if (this.packetListener instanceof LoginListener) { ++ if ( ((LoginListener) this.packetListener).getLoginState() != LoginListener.EnumProtocolState.READY_TO_ACCEPT // Paper ++ || (joinAttemptsThisTick++ < MAX_PER_TICK)) { // Paper - limit the number of joins which can be processed each tick + ((LoginListener) this.packetListener).tick(); ++ } // Paper + } + + if (this.packetListener instanceof PlayerConnection) {