Spam Filter Exclusions

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2014-02-08 08:13:40 +00:00
parent b26b6dadb0
commit ff6d4b2d90
2 changed files with 58 additions and 32 deletions

View file

@ -40,7 +40,7 @@
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level;
@@ -192,11 +195,69 @@
@@ -192,12 +195,70 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
@ -50,7 +50,7 @@
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.slf4j.Logger;
+
+// CraftBukkit start
+import com.mojang.datafixers.util.Pair;
+import java.util.Arrays;
@ -107,9 +107,10 @@
+import org.bukkit.inventory.InventoryView;
+import org.bukkit.inventory.SmithingInventory;
+// CraftBukkit end
+
public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl implements ServerGamePacketListener, ServerPlayerConnection, TickablePacketListener {
static final Logger LOGGER = LogUtils.getLogger();
@@ -247,7 +308,7 @@
private boolean waitingForSwitchToConfig;
@ -858,8 +859,9 @@
+ }
+ // CraftBukkit end
this.performUnsignedChatCommand(packet.command());
this.detectRateSpam();
- this.detectRateSpam();
- });
+ this.detectRateSpam("/" + packet.command()); // Spigot
+ }, true); // CraftBukkit - sync commands
}
@ -889,8 +891,9 @@
+ }
+ // CraftBukkit end
this.performSignedChatCommand(packet, (LastSeenMessages) optional.get());
this.detectRateSpam();
- this.detectRateSpam();
- });
+ this.detectRateSpam("/" + packet.command()); // Spigot
+ }, true); // CraftBukkit - sync commands
}
}
@ -958,10 +961,12 @@
}
}
@@ -1566,6 +2068,121 @@
return false;
}
@@ -1564,8 +2066,123 @@
}
return false;
+ }
+
+ // CraftBukkit start - add method
+ public void chat(String s, PlayerChatMessage original, boolean async) {
+ if (s.isEmpty() || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) {
@ -1046,8 +1051,8 @@
+ this.server.console.sendMessage(s);
+ }
+ }
+ }
+
}
+ private void handleCommand(String s) {
+ org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.startTiming(); // Spigot
+ if ( org.spigotmc.SpigotConfig.logCommands ) // Spigot
@ -1080,11 +1085,12 @@
private PlayerChatMessage getSignedMessage(ServerboundChatPacket packet, LastSeenMessages lastSeenMessages) throws SignedMessageChain.DecodeException {
SignedMessageBody signedmessagebody = new SignedMessageBody(packet.message(), packet.timeStamp(), packet.salt(), lastSeenMessages);
@@ -1573,13 +2190,33 @@
@@ -1573,13 +2190,42 @@
}
private void broadcastChatMessage(PlayerChatMessage message) {
- this.server.getPlayerList().broadcastChatMessage(message, this.player, ChatType.bind(ChatType.CHAT, (Entity) this.player));
- this.detectRateSpam();
+ // CraftBukkit start
+ String s = message.signedContent();
+ if (s.isEmpty()) {
@ -1104,20 +1110,30 @@
+ }
+ // this.server.getPlayerList().broadcastChatMessage(playerchatmessage, this.player, ChatMessageType.bind(ChatMessageType.CHAT, (Entity) this.player));
+ // CraftBukkit end
this.detectRateSpam();
+ this.detectRateSpam(s); // Spigot
}
private void detectRateSpam() {
- private void detectRateSpam() {
- this.chatSpamThrottler.increment();
- if (!this.chatSpamThrottler.isUnderThreshold() && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) {
+ // Spigot start - spam exclusions
+ private void detectRateSpam(String s) {
+ // CraftBukkit start - replaced with thread safe throttle
+ for ( String exclude : org.spigotmc.SpigotConfig.spamExclusions )
+ {
+ if ( exclude != null && s.startsWith( exclude ) )
+ {
+ return;
+ }
+ }
+ // Spigot end
+ // this.chatSpamThrottler.increment();
+ if (!this.chatSpamThrottler.isIncrementAndUnderThreshold() && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) {
+ // CraftBukkit end
this.disconnect((Component) Component.translatable("disconnect.spam"));
}
@@ -1601,7 +2238,33 @@
@@ -1601,7 +2247,33 @@
@Override
public void handleAnimate(ServerboundSwingPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -1151,7 +1167,7 @@
this.player.swing(packet.getHand());
}
@@ -1609,6 +2272,29 @@
@@ -1609,6 +2281,29 @@
public void handlePlayerCommand(ServerboundPlayerCommandPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
if (this.player.hasClientLoaded()) {
@ -1181,7 +1197,7 @@
this.player.resetLastActionTime();
Entity entity;
PlayerRideableJumping ijumpable;
@@ -1691,6 +2377,12 @@
@@ -1691,6 +2386,12 @@
}
public void sendPlayerChatMessage(PlayerChatMessage message, ChatType.Bound params) {
@ -1194,7 +1210,7 @@
this.send(new ClientboundPlayerChatPacket(message.link().sender(), message.link().index(), message.signature(), message.signedBody().pack(this.messageSignatureCache), message.unsignedContent(), message.filterMask(), params));
this.addPendingMessage(message);
}
@@ -1703,6 +2395,13 @@
@@ -1703,6 +2404,13 @@
return this.connection.getRemoteAddress();
}
@ -1208,7 +1224,7 @@
public void switchToConfig() {
this.waitingForSwitchToConfig = true;
this.removePlayerFromWorld();
@@ -1718,9 +2417,17 @@
@@ -1718,9 +2426,17 @@
@Override
public void handleInteract(ServerboundInteractPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -1226,7 +1242,7 @@
this.player.resetLastActionTime();
this.player.setShiftKeyDown(packet.isUsingSecondaryAction());
@@ -1733,20 +2440,58 @@
@@ -1733,20 +2449,58 @@
if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) {
packet.dispatch(new ServerboundInteractPacket.Handler() {
@ -1289,7 +1305,7 @@
}
}
@@ -1755,19 +2500,20 @@
@@ -1755,19 +2509,20 @@
@Override
public void onInteraction(InteractionHand hand) {
@ -1313,7 +1329,7 @@
label23:
{
if (entity instanceof AbstractArrow) {
@@ -1785,6 +2531,11 @@
@@ -1785,6 +2540,11 @@
}
ServerGamePacketListenerImpl.this.player.attack(entity);
@ -1325,7 +1341,7 @@
return;
}
}
@@ -1809,7 +2560,7 @@
@@ -1809,7 +2569,7 @@
case PERFORM_RESPAWN:
if (this.player.wonGame) {
this.player.wonGame = false;
@ -1334,7 +1350,7 @@
this.resetPosition();
CriteriaTriggers.CHANGED_DIMENSION.trigger(this.player, Level.END, Level.OVERWORLD);
} else {
@@ -1817,11 +2568,11 @@
@@ -1817,11 +2577,11 @@
return;
}
@ -1348,7 +1364,7 @@
}
}
break;
@@ -1834,15 +2585,21 @@
@@ -1834,15 +2594,21 @@
@Override
public void handleContainerClose(ServerboundContainerClosePacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -1372,7 +1388,7 @@
this.player.containerMenu.sendAllDataToRemote();
} else if (!this.player.containerMenu.stillValid(this.player)) {
ServerGamePacketListenerImpl.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu);
@@ -1855,7 +2612,284 @@
@@ -1855,7 +2621,284 @@
boolean flag = packet.getStateId() != this.player.containerMenu.getStateId();
this.player.containerMenu.suppressRemoteUpdates();
@ -1658,7 +1674,7 @@
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packet.getChangedSlots()).iterator();
while (objectiterator.hasNext()) {
@@ -1901,8 +2935,22 @@
@@ -1901,8 +2944,22 @@
return;
}
@ -1682,7 +1698,7 @@
if (containerrecipebook_a == RecipeBookMenu.PostPlaceAction.PLACE_GHOST_RECIPE) {
this.player.connection.send(new ClientboundPlaceGhostRecipePacket(this.player.containerMenu.containerId, craftingmanager_d.display().display()));
}
@@ -1917,6 +2965,7 @@
@@ -1917,6 +2974,7 @@
@Override
public void handleContainerButtonClick(ServerboundContainerButtonClickPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -1690,7 +1706,7 @@
this.player.resetLastActionTime();
if (this.player.containerMenu.containerId == packet.containerId() && !this.player.isSpectator()) {
if (!this.player.containerMenu.stillValid(this.player)) {
@@ -1945,7 +2994,44 @@
@@ -1945,7 +3003,44 @@
boolean flag1 = packet.slotNum() >= 1 && packet.slotNum() <= 45;
boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize();
@ -1735,7 +1751,7 @@
if (flag1 && flag2) {
this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemstack);
this.player.inventoryMenu.setRemoteSlot(packet.slotNum(), itemstack);
@@ -1972,6 +3058,7 @@
@@ -1972,6 +3067,7 @@
}
private void updateSignText(ServerboundSignUpdatePacket packet, List<FilteredText> signText) {
@ -1743,7 +1759,7 @@
this.player.resetLastActionTime();
ServerLevel worldserver = this.player.serverLevel();
BlockPos blockposition = packet.getPos();
@@ -1993,7 +3080,17 @@
@@ -1993,7 +3089,17 @@
@Override
public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -1762,7 +1778,7 @@
}
@Override
@@ -2058,7 +3155,7 @@
@@ -2058,7 +3164,7 @@
if (!this.waitingForSwitchToConfig) {
throw new IllegalStateException("Client acknowledged config, but none was requested");
} else {
@ -1771,7 +1787,7 @@
}
}
@@ -2083,8 +3180,10 @@
@@ -2083,8 +3189,10 @@
});
}

View file

@ -6,6 +6,7 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -284,4 +285,13 @@ public class SpigotConfig
{
SpigotConfig.playerShuffle = SpigotConfig.getInt( "settings.player-shuffle", 0 );
}
public static List<String> spamExclusions;
private static void spamExclusions()
{
SpigotConfig.spamExclusions = SpigotConfig.getList( "commands.spam-exclusions", Arrays.asList( new String[]
{
"/skill"
} ) );
}
}