2022-06-09 08:51:45 +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/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java
|
2022-07-27 22:00:14 +00:00
|
|
|
index 8440b3d6f9811fa16b10843ada91248e0722acc4..2ed32f8c503b7196abfaa1c1e2456fbd4760eac3 100644
|
2022-06-09 08:51:45 +00:00
|
|
|
--- a/src/main/java/net/minecraft/network/Connection.java
|
|
|
|
+++ b/src/main/java/net/minecraft/network/Connection.java
|
2022-07-27 20:46:05 +00:00
|
|
|
@@ -396,8 +396,23 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
2022-06-09 08:51:45 +00:00
|
|
|
}
|
|
|
|
// 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
|
2022-07-27 22:00:14 +00:00
|
|
|
+ if (this.packetListener instanceof net.minecraft.server.network.ServerLoginPacketListenerImpl serverLoginPacketListener) {
|
|
|
|
+ if ( serverLoginPacketListener.state != net.minecraft.server.network.ServerLoginPacketListenerImpl.State.READY_TO_ACCEPT // Paper
|
2022-07-27 20:46:05 +00:00
|
|
|
+ || (joinAttemptsThisTick++ < MAX_PER_TICK)) { // Paper - limit the number of joins which can be processed each tick
|
2022-07-27 22:00:14 +00:00
|
|
|
+ serverLoginPacketListener.tick();
|
2022-06-09 08:51:45 +00:00
|
|
|
+ } // Paper
|
2022-07-27 20:46:05 +00:00
|
|
|
+ }
|
|
|
|
PacketListener packetlistener = this.packetListener;
|
2022-06-09 08:51:45 +00:00
|
|
|
|
2022-07-27 20:46:05 +00:00
|
|
|
if (packetlistener instanceof TickablePacketListener) {
|