2020-08-25 13:30:57 +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/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
2021-02-26 18:54:48 +01:00
|
|
|
index faa1b775e45563b93ac1d5b904938b1f5ad8d80c..545948f20efd6c8dd42140b565af94cd6b52b661 100644
|
2020-08-25 13:30:57 +02:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
2021-02-26 18:54:48 +01:00
|
|
|
@@ -457,4 +457,9 @@ public class PaperConfig {
|
2020-08-25 13:30:57 +02:00
|
|
|
maxPlayerAutoSavePerTick = (playerAutoSaveRate == -1 || playerAutoSaveRate > 100) ? 10 : 20;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ public static int maxJoinsPerTick;
|
|
|
|
+ private static void maxJoinsPerTick() {
|
2020-08-25 14:23:58 +02:00
|
|
|
+ maxJoinsPerTick = getInt("settings.max-joins-per-tick", 3);
|
2020-08-25 13:30:57 +02:00
|
|
|
+ }
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java
|
2020-12-16 23:16:03 +01:00
|
|
|
index 06d8ad7f57aa629c3c6060545a45411343affc81..fc4ad72ffaed5e747cfecc71e9ac8ee2b556ce31 100644
|
2020-08-25 13:30:57 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/NetworkManager.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/NetworkManager.java
|
2020-12-16 23:16:03 +01:00
|
|
|
@@ -365,10 +365,22 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
|
2020-08-25 13:30:57 +02:00
|
|
|
}
|
|
|
|
// 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) {
|