Paper/patches/server/0235-Break-up-and-make-tab-spam-limits-configurable.patch

76 lines
4.7 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: Sun, 29 Jul 2018 05:02:15 +0100
Subject: [PATCH] Break up and make tab spam limits configurable
Due to the changes in 1.13, clients will send a tab completion request
for all bukkit commands in order to factor in the lack of support for
brigadier and provide backwards support in the API.
Craftbukkit, however; has moved the chat spam limiter to also interact
with the tab completion request, which while good for avoiding abuse,
causes 1.13 clients to easilly be kicked from a server in bukkit due
to this. Removing the spam limit could cause issues for servers, however,
there is no way for servers to manipulate this without blindly cancelling
kick events, which only causes additional complications. This also causes
issues in that the tab spam limit and chat share the same field but different
limits, meaning that a player having typed a long command may be kicked from
the server.
Splitting the field up and making it configurable allows for server owners
to take the burden of this into their own hand without having to rely on
plugins doing unsafe things.
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2022-06-03 06:26:56 +02:00
index b46b10c726b53b1106cc74ec9a5d6ca6f45c96fe..c3539fabda1887cca6e82abce26dff088cdc4251 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
@@ -318,4 +318,18 @@ public class PaperConfig {
2021-06-11 14:02:28 +02:00
Bukkit.getLogger().log(Level.INFO, "Using Aikar's Alternative Luck Formula to apply Luck attribute to all loot pool calculations. See https://luckformula.emc.gs");
}
}
+
+ public static int tabSpamIncrement = 1;
+ public static int tabSpamLimit = 500;
+ private static void tabSpamLimiters() {
+ tabSpamIncrement = getInt("settings.spam-limiter.tab-spam-increment", tabSpamIncrement);
+ // Older versions used a smaller limit, which is too low for 1.13, we'll bump this up if default
+ if (version < 14) {
+ if (tabSpamIncrement == 10) {
+ set("settings.spam-limiter.tab-spam-increment", 2);
+ tabSpamIncrement = 2;
+ }
+ }
+ tabSpamLimit = getInt("settings.spam-limiter.tab-spam-limit", tabSpamLimit);
+ }
}
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2022-06-07 23:45:11 +02:00
index 79d9af684d331c5e656697353559d4b3ce70a368..a6add84c2bae068263b0ae9fe4bd66c569884be5 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2022-06-07 23:45:11 +02:00
@@ -245,6 +245,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-13 01:45:00 +02:00
private long keepAliveChallenge;
2021-06-11 14:02:28 +02:00
// CraftBukkit start - multithreaded fields
2021-11-23 16:04:41 +01:00
private final AtomicInteger chatSpamTickCount = new AtomicInteger();
2021-06-11 14:02:28 +02:00
+ private final java.util.concurrent.atomic.AtomicInteger tabSpamLimiter = new java.util.concurrent.atomic.AtomicInteger(); // Paper - configurable tab spam limits
// CraftBukkit end
private int dropSpamTickCount;
2021-06-13 01:45:00 +02:00
private double firstGoodX;
2022-06-07 23:45:11 +02:00
@@ -384,6 +385,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-11 14:02:28 +02:00
this.server.getProfiler().pop();
// CraftBukkit start
2021-06-13 01:45:00 +02:00
for (int spam; (spam = this.chatSpamTickCount.get()) > 0 && !this.chatSpamTickCount.compareAndSet(spam, spam - 1); ) ;
2021-06-11 14:02:28 +02:00
+ if (tabSpamLimiter.get() > 0) tabSpamLimiter.getAndDecrement(); // Paper - split to seperate variable
/* Use thread-safe field access instead
2021-06-13 01:45:00 +02:00
if (this.chatSpamTickCount > 0) {
--this.chatSpamTickCount;
2022-06-07 23:45:11 +02:00
@@ -743,7 +745,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-11 14:02:28 +02:00
public void handleCustomCommandSuggestions(ServerboundCommandSuggestionPacket packet) {
// PlayerConnectionUtils.ensureMainThread(packetplayintabcomplete, this, this.player.getWorldServer()); // Paper - run this async
// CraftBukkit start
2021-06-13 01:45:00 +02:00
- if (this.chatSpamTickCount.addAndGet(1) > 500 && !this.server.getPlayerList().isOp(this.player.getGameProfile())) {
+ if (this.chatSpamTickCount.addAndGet(com.destroystokyo.paper.PaperConfig.tabSpamIncrement) > com.destroystokyo.paper.PaperConfig.tabSpamLimit && !this.server.getPlayerList().isOp(this.player.getGameProfile())) { // Paper start - split and make configurable
2022-06-07 23:45:11 +02:00
server.scheduleOnMain(() -> this.disconnect(Component.translatable("disconnect.spam", new Object[0]))); // Paper
2021-06-11 14:02:28 +02:00
return;
}