mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-30 06:24:06 +01:00
61 lines
3.1 KiB
Diff
61 lines
3.1 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/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
index ad67d41484052e38f3b955aafa1f74cf6e2b3701..658569f9cefdbbfc30eef3b63e8bf552557a498a 100644
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
@@ -91,6 +91,11 @@ public class PaperConfig {
|
|
}
|
|
}
|
|
|
|
+ public static int maxJoinsPerTick;
|
|
+ private static void maxJoinsPerTick() {
|
|
+ maxJoinsPerTick = getInt("settings.max-joins-per-tick", 3);
|
|
+ }
|
|
+
|
|
public static void registerCommands() {
|
|
for (Map.Entry<String, Command> entry : commands.entrySet()) {
|
|
MinecraftServer.getServer().server.getCommandMap().register(entry.getKey(), "Paper", entry.getValue());
|
|
diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java
|
|
index ed4587248fada36c4c206be1fa36fef42fc969e2..2ea1895be13eef99a87a7d1b0348699f46f281fc 100644
|
|
--- a/src/main/java/net/minecraft/network/Connection.java
|
|
+++ b/src/main/java/net/minecraft/network/Connection.java
|
|
@@ -40,6 +40,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;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
import net.minecraft.server.RunningOnDifferentThreadException;
|
|
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
|
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
|
|
@@ -387,10 +388,22 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
|
}
|
|
// 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() {
|
|
this.flushQueue();
|
|
+ // Paper start
|
|
+ if (currTick != MinecraftServer.currentTick) {
|
|
+ currTick = 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
|
|
}
|
|
|
|
if (this.packetListener instanceof ServerGamePacketListenerImpl) {
|