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/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-06-13 21:04:27 +02:00
index de22f6ce5e24e5deb5793ad1cc0f8187305903ab..3921f9d664ef629361d9ad2050cea97c2182e157 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
2024-04-25 23:21:18 +02:00
@@ -265,6 +265,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2023-09-22 00:01:00 +02:00
private int ackBlockChangesUpTo = -1;
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;
2024-04-25 23:21:18 +02:00
@@ -381,6 +382,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2023-09-22 00:01:00 +02:00
this.keepConnectionAlive();
2021-06-11 14:02:28 +02:00
// CraftBukkit start
2021-06-13 01:45:00 +02:00
for (int spam; (spam = this.chatSpamTickCount.get()) > 0 && !this.chatSpamTickCount.compareAndSet(spam, spam - 1); ) ;
2024-01-21 17:39:05 +01:00
+ if (tabSpamLimiter.get() > 0) tabSpamLimiter.getAndDecrement(); // Paper - configurable tab spam limits
2021-06-11 14:02:28 +02:00
/* Use thread-safe field access instead
2021-06-13 01:45:00 +02:00
if (this.chatSpamTickCount > 0) {
--this.chatSpamTickCount;
2024-06-13 21:04:27 +02:00
@@ -719,7 +721,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2021-06-11 14:02:28 +02:00
public void handleCustomCommandSuggestions(ServerboundCommandSuggestionPacket packet) {
2024-01-22 18:04:55 +01:00
// PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); // Paper - AsyncTabCompleteEvent; run this async
2021-06-11 14:02:28 +02:00
// CraftBukkit start
2021-06-13 01:45:00 +02:00
- if (this.chatSpamTickCount.addAndGet(1) > 500 && !this.server.getPlayerList().isOp(this.player.getGameProfile())) {
2024-01-21 17:39:05 +01:00
+ if (this.chatSpamTickCount.addAndGet(io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.tabSpamIncrement) > io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.tabSpamLimit && !this.server.getPlayerList().isOp(this.player.getGameProfile())) { // Paper - configurable tab spam limits
2024-02-05 12:31:51 +01:00
this.disconnect(Component.translatable("disconnect.spam"));
2021-06-11 14:02:28 +02:00
return;
}