2021-06-11 12:02:28 +00: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
|
2022-01-01 03:05:42 +00:00
|
|
|
index 1fd89294fabcd2a390ba7f1502acbfeb9a2343d6..8111e5e1752d93f94b773e35f7ff3857144def63 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
2021-11-24 16:06:46 +00:00
|
|
|
@@ -91,6 +91,11 @@ public class PaperConfig {
|
2021-06-17 08:37:27 +00:00
|
|
|
}
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
2021-11-24 16:06:46 +00:00
|
|
|
|
2021-06-11 12:02:28 +00:00
|
|
|
+ public static int maxJoinsPerTick;
|
|
|
|
+ private static void maxJoinsPerTick() {
|
|
|
|
+ maxJoinsPerTick = getInt("settings.max-joins-per-tick", 3);
|
|
|
|
+ }
|
2021-11-24 16:06:46 +00:00
|
|
|
+
|
|
|
|
public static void registerCommands() {
|
|
|
|
for (Map.Entry<String, Command> entry : commands.entrySet()) {
|
|
|
|
MinecraftServer.getServer().server.getCommandMap().register(entry.getKey(), "Paper", entry.getValue());
|
2021-06-11 12:02:28 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java
|
2022-03-01 05:43:03 +00:00
|
|
|
index c469688c2b55b1c93435a2ac6e8e4494ab7e5229..1c63947958d202d00593e2b76d113c8b327706d7 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/network/Connection.java
|
|
|
|
+++ b/src/main/java/net/minecraft/network/Connection.java
|
2022-03-01 05:43:03 +00:00
|
|
|
@@ -40,6 +40,7 @@ import net.minecraft.network.protocol.Packet;
|
2021-06-14 13:45:16 +00:00
|
|
|
import net.minecraft.network.protocol.PacketFlow;
|
|
|
|
import net.minecraft.network.protocol.game.ClientboundDisconnectPacket;
|
|
|
|
import net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket;
|
2021-06-11 12:02:28 +00:00
|
|
|
+import net.minecraft.server.MinecraftServer;
|
|
|
|
import net.minecraft.server.RunningOnDifferentThreadException;
|
|
|
|
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
2021-06-14 13:45:16 +00:00
|
|
|
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
|
2022-03-01 05:43:03 +00:00
|
|
|
@@ -385,10 +386,22 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
2021-06-11 12:02:28 +00: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 tick() {
|
2021-06-14 13:45:16 +00:00
|
|
|
this.flushQueue();
|
2021-06-11 12:02:28 +00:00
|
|
|
+ // Paper start
|
|
|
|
+ if (currTick != MinecraftServer.currentTick) {
|
|
|
|
+ currTick = MinecraftServer.currentTick;
|
|
|
|
+ joinAttemptsThisTick = 0;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
if (this.packetListener instanceof ServerLoginPacketListenerImpl) {
|
2021-06-17 21:39:36 +00:00
|
|
|
+ if ( ((ServerLoginPacketListenerImpl) this.packetListener).state != ServerLoginPacketListenerImpl.State.READY_TO_ACCEPT // Paper
|
2021-06-11 12:02:28 +00:00
|
|
|
+ || (joinAttemptsThisTick++ < MAX_PER_TICK)) { // Paper - limit the number of joins which can be processed each tick
|
|
|
|
((ServerLoginPacketListenerImpl) this.packetListener).tick();
|
|
|
|
+ } // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.packetListener instanceof ServerGamePacketListenerImpl) {
|