testserver/patches/server/0485-Buffer-joins-to-world....

38 lines
1.9 KiB
Diff

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
index c06cb0f0e300c4d00b3aeed12772c38e8379cb0c..eb18253d4ae0618884c9061f8dda689119e10ef0 100644
--- a/src/main/java/net/minecraft/network/Connection.java
+++ b/src/main/java/net/minecraft/network/Connection.java
@@ -396,8 +396,23 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
}
// Paper end
+ private static final int MAX_PER_TICK = io.papermc.paper.configuration.GlobalConfiguration.get().misc.maxJoinsPerTick; // Paper
+ private static int joinAttemptsThisTick; // Paper
+ private static int currTick; // Paper
public void tick() {
this.flushQueue();
+ // Paper start
+ if (currTick != net.minecraft.server.MinecraftServer.currentTick) {
+ currTick = net.minecraft.server.MinecraftServer.currentTick;
+ joinAttemptsThisTick = 0;
+ }
+ // Paper end
+ if (this.packetListener instanceof ServerLoginPacketListenerImpl) {
+ if ( ((ServerLoginPacketListenerImpl) this.packetListener).state != ServerLoginPacketListenerImpl.State.READY_TO_ACCEPT // Paper
+ || (joinAttemptsThisTick++ < MAX_PER_TICK)) { // Paper - limit the number of joins which can be processed each tick
+ ((ServerLoginPacketListenerImpl) this.packetListener).tick();
+ } // Paper
+ }
PacketListener packetlistener = this.packetListener;
if (packetlistener instanceof TickablePacketListener) {