Paper/patches/server/0514-Buffer-joins-to-world.patch

59 lines
2.9 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +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-06-17 10:37:27 +02:00
index faa1b775e45563b93ac1d5b904938b1f5ad8d80c..545948f20efd6c8dd42140b565af94cd6b52b661 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2021-06-17 10:37:27 +02:00
@@ -457,4 +457,9 @@ public class PaperConfig {
maxPlayerAutoSavePerTick = (playerAutoSaveRate == -1 || playerAutoSaveRate > 100) ? 10 : 20;
}
2021-06-11 14:02:28 +02:00
}
+
+ public static int maxJoinsPerTick;
+ private static void maxJoinsPerTick() {
+ maxJoinsPerTick = getInt("settings.max-joins-per-tick", 3);
+ }
}
diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java
2021-06-17 23:39:36 +02:00
index 34c642a9439faec095c58c6017a0dfd4b35a2401..01b9c360c6d687c6a774bf3375802be487cb0e0c 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/network/Connection.java
+++ b/src/main/java/net/minecraft/network/Connection.java
2021-06-14 15:45:16 +02:00
@@ -37,6 +37,7 @@ import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketFlow;
import net.minecraft.network.protocol.game.ClientboundDisconnectPacket;
import net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket;
2021-06-11 14:02:28 +02:00
+import net.minecraft.server.MinecraftServer;
import net.minecraft.server.RunningOnDifferentThreadException;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
2021-06-14 15:45:16 +02:00
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
@@ -373,10 +374,22 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
2021-06-11 14:02:28 +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 tick() {
2021-06-14 15:45:16 +02:00
this.flushQueue();
2021-06-11 14:02:28 +02:00
+ // Paper start
+ if (currTick != MinecraftServer.currentTick) {
+ currTick = MinecraftServer.currentTick;
+ joinAttemptsThisTick = 0;
+ }
+ // Paper end
if (this.packetListener instanceof ServerLoginPacketListenerImpl) {
2021-06-17 23:39:36 +02:00
+ if ( ((ServerLoginPacketListenerImpl) this.packetListener).state != ServerLoginPacketListenerImpl.State.READY_TO_ACCEPT // Paper
2021-06-11 14:02:28 +02: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) {