mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-19 14:51:27 +01:00
Configurable packet in spam threshold
This commit is contained in:
parent
c7287dd5ee
commit
72bc20c589
@ -706,20 +706,21 @@
|
||||
this.player.drop(false);
|
||||
}
|
||||
|
||||
@@ -1218,9 +1605,30 @@
|
||||
@@ -1218,9 +1605,31 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ // Spigot start - limit place/interactions
|
||||
+ private int limitedPackets;
|
||||
+ private long lastLimitedPacket = -1;
|
||||
+ private static int getSpamThreshold() { return io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.incomingPacketThreshold; } // Paper - Configurable threshold
|
||||
+
|
||||
+ private boolean checkLimit(long timestamp) {
|
||||
+ if (this.lastLimitedPacket != -1 && timestamp - this.lastLimitedPacket < 30 && this.limitedPackets++ >= 4) {
|
||||
+ if (this.lastLimitedPacket != -1 && timestamp - this.lastLimitedPacket < getSpamThreshold() && this.limitedPackets++ >= 8) { // Paper - Configurable threshold; raise packet limit to 8
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ if (this.lastLimitedPacket == -1 || timestamp - this.lastLimitedPacket >= 30) {
|
||||
+ if (this.lastLimitedPacket == -1 || timestamp - this.lastLimitedPacket >= getSpamThreshold()) { // Paper - Configurable threshold
|
||||
+ this.lastLimitedPacket = timestamp;
|
||||
+ this.limitedPackets = 0;
|
||||
+ return true;
|
||||
@ -737,7 +738,7 @@
|
||||
if (this.player.hasClientLoaded()) {
|
||||
this.player.connection.ackBlockChangesUpTo(packet.getSequence());
|
||||
ServerLevel worldserver = this.player.serverLevel();
|
||||
@@ -1244,6 +1652,7 @@
|
||||
@@ -1244,6 +1653,7 @@
|
||||
|
||||
if (blockposition.getY() <= i) {
|
||||
if (this.awaitingPositionFromClient == null && worldserver.mayInteract(this.player, blockposition)) {
|
||||
@ -745,7 +746,7 @@
|
||||
InteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock);
|
||||
|
||||
if (enuminteractionresult.consumesAction()) {
|
||||
@@ -1281,6 +1690,8 @@
|
||||
@@ -1281,6 +1691,8 @@
|
||||
@Override
|
||||
public void handleUseItem(ServerboundUseItemPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -754,7 +755,7 @@
|
||||
if (this.player.hasClientLoaded()) {
|
||||
this.ackBlockChangesUpTo(packet.getSequence());
|
||||
ServerLevel worldserver = this.player.serverLevel();
|
||||
@@ -1296,6 +1707,47 @@
|
||||
@@ -1296,6 +1708,47 @@
|
||||
this.player.absRotateTo(f, f1);
|
||||
}
|
||||
|
||||
@ -802,7 +803,7 @@
|
||||
InteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand);
|
||||
|
||||
if (enuminteractionresult instanceof InteractionResult.Success) {
|
||||
@@ -1321,7 +1773,7 @@
|
||||
@@ -1321,7 +1774,7 @@
|
||||
Entity entity = packet.getEntity(worldserver);
|
||||
|
||||
if (entity != null) {
|
||||
@ -811,7 +812,7 @@
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1342,6 +1794,13 @@
|
||||
@@ -1342,6 +1795,13 @@
|
||||
|
||||
@Override
|
||||
public void onDisconnect(DisconnectionDetails info) {
|
||||
@ -825,7 +826,7 @@
|
||||
ServerGamePacketListenerImpl.LOGGER.info("{} lost connection: {}", this.player.getName().getString(), info.reason().getString());
|
||||
this.removePlayerFromWorld();
|
||||
super.onDisconnect(info);
|
||||
@@ -1349,10 +1808,20 @@
|
||||
@@ -1349,10 +1809,20 @@
|
||||
|
||||
private void removePlayerFromWorld() {
|
||||
this.chatMessageChain.close();
|
||||
@ -848,7 +849,7 @@
|
||||
this.player.getTextFilter().leave();
|
||||
}
|
||||
|
||||
@@ -1367,7 +1836,16 @@
|
||||
@@ -1367,7 +1837,16 @@
|
||||
@Override
|
||||
public void handleSetCarriedItem(ServerboundSetCarriedItemPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -865,7 +866,7 @@
|
||||
if (this.player.getInventory().selected != packet.getSlot() && this.player.getUsedItemHand() == InteractionHand.MAIN_HAND) {
|
||||
this.player.stopUsingItem();
|
||||
}
|
||||
@@ -1376,11 +1854,18 @@
|
||||
@@ -1376,11 +1855,18 @@
|
||||
this.player.resetLastActionTime();
|
||||
} else {
|
||||
ServerGamePacketListenerImpl.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString());
|
||||
@ -884,7 +885,7 @@
|
||||
Optional<LastSeenMessages> optional = this.unpackAndApplyLastSeen(packet.lastSeenMessages());
|
||||
|
||||
if (!optional.isEmpty()) {
|
||||
@@ -1394,27 +1879,44 @@
|
||||
@@ -1394,27 +1880,44 @@
|
||||
return;
|
||||
}
|
||||
|
||||
@ -936,7 +937,7 @@
|
||||
ParseResults<CommandSourceStack> parseresults = this.parseCommand(command);
|
||||
|
||||
if (this.server.enforceSecureProfile() && SignableCommand.hasSignableArguments(parseresults)) {
|
||||
@@ -1431,19 +1933,37 @@
|
||||
@@ -1431,19 +1934,37 @@
|
||||
|
||||
if (!optional.isEmpty()) {
|
||||
this.tryHandleChat(packet.command(), () -> {
|
||||
@ -978,7 +979,7 @@
|
||||
} catch (SignedMessageChain.DecodeException signedmessagechain_a) {
|
||||
this.handleMessageDecodeFailure(signedmessagechain_a);
|
||||
return;
|
||||
@@ -1451,10 +1971,10 @@
|
||||
@@ -1451,10 +1972,10 @@
|
||||
|
||||
CommandSigningContext.SignedArguments commandsigningcontext_a = new CommandSigningContext.SignedArguments(map);
|
||||
|
||||
@ -991,7 +992,7 @@
|
||||
}
|
||||
|
||||
private void handleMessageDecodeFailure(SignedMessageChain.DecodeException exception) {
|
||||
@@ -1530,14 +2050,20 @@
|
||||
@@ -1530,14 +2051,20 @@
|
||||
return com_mojang_brigadier_commanddispatcher.parse(command, this.player.createCommandSourceStack());
|
||||
}
|
||||
|
||||
@ -1016,12 +1017,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1564,8 +2090,129 @@
|
||||
}
|
||||
|
||||
@@ -1566,6 +2093,127 @@
|
||||
return false;
|
||||
+ }
|
||||
+
|
||||
}
|
||||
|
||||
+ // CraftBukkit start - add method
|
||||
+ public void chat(String s, PlayerChatMessage original, boolean async) {
|
||||
+ if (s.isEmpty() || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) {
|
||||
@ -1114,8 +1113,8 @@
|
||||
+ this.server.console.sendMessage(s);
|
||||
+ }
|
||||
+ }
|
||||
}
|
||||
|
||||
+ }
|
||||
+
|
||||
+ private void handleCommand(String s) {
|
||||
+ org.spigotmc.AsyncCatcher.catchOp("Command Dispatched Async: " + s); // Paper - Add async catcher
|
||||
+ if ( org.spigotmc.SpigotConfig.logCommands ) // Spigot
|
||||
@ -1146,7 +1145,7 @@
|
||||
private PlayerChatMessage getSignedMessage(ServerboundChatPacket packet, LastSeenMessages lastSeenMessages) throws SignedMessageChain.DecodeException {
|
||||
SignedMessageBody signedmessagebody = new SignedMessageBody(packet.message(), packet.timeStamp(), packet.salt(), lastSeenMessages);
|
||||
|
||||
@@ -1573,13 +2220,42 @@
|
||||
@@ -1573,13 +2221,42 @@
|
||||
}
|
||||
|
||||
private void broadcastChatMessage(PlayerChatMessage message) {
|
||||
@ -1194,7 +1193,7 @@
|
||||
this.disconnect((Component) Component.translatable("disconnect.spam"));
|
||||
}
|
||||
|
||||
@@ -1601,7 +2277,33 @@
|
||||
@@ -1601,7 +2278,33 @@
|
||||
@Override
|
||||
public void handleAnimate(ServerboundSwingPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -1228,7 +1227,7 @@
|
||||
this.player.swing(packet.getHand());
|
||||
}
|
||||
|
||||
@@ -1609,6 +2311,29 @@
|
||||
@@ -1609,6 +2312,29 @@
|
||||
public void handlePlayerCommand(ServerboundPlayerCommandPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
if (this.player.hasClientLoaded()) {
|
||||
@ -1258,7 +1257,7 @@
|
||||
this.player.resetLastActionTime();
|
||||
Entity entity;
|
||||
PlayerRideableJumping ijumpable;
|
||||
@@ -1691,6 +2416,12 @@
|
||||
@@ -1691,6 +2417,12 @@
|
||||
}
|
||||
|
||||
public void sendPlayerChatMessage(PlayerChatMessage message, ChatType.Bound params) {
|
||||
@ -1271,7 +1270,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 +2434,13 @@
|
||||
@@ -1703,6 +2435,13 @@
|
||||
return this.connection.getRemoteAddress();
|
||||
}
|
||||
|
||||
@ -1285,7 +1284,7 @@
|
||||
public void switchToConfig() {
|
||||
this.waitingForSwitchToConfig = true;
|
||||
this.removePlayerFromWorld();
|
||||
@@ -1718,9 +2456,17 @@
|
||||
@@ -1718,9 +2457,17 @@
|
||||
@Override
|
||||
public void handleInteract(ServerboundInteractPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -1303,7 +1302,7 @@
|
||||
|
||||
this.player.resetLastActionTime();
|
||||
this.player.setShiftKeyDown(packet.isUsingSecondaryAction());
|
||||
@@ -1733,20 +2479,58 @@
|
||||
@@ -1733,20 +2480,58 @@
|
||||
|
||||
if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) {
|
||||
packet.dispatch(new ServerboundInteractPacket.Handler() {
|
||||
@ -1366,7 +1365,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1755,19 +2539,20 @@
|
||||
@@ -1755,19 +2540,20 @@
|
||||
|
||||
@Override
|
||||
public void onInteraction(InteractionHand hand) {
|
||||
@ -1390,7 +1389,7 @@
|
||||
label23:
|
||||
{
|
||||
if (entity instanceof AbstractArrow) {
|
||||
@@ -1785,6 +2570,11 @@
|
||||
@@ -1785,6 +2571,11 @@
|
||||
}
|
||||
|
||||
ServerGamePacketListenerImpl.this.player.attack(entity);
|
||||
@ -1402,7 +1401,7 @@
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1795,7 +2585,26 @@
|
||||
@@ -1795,7 +2586,26 @@
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -1429,7 +1428,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1809,7 +2618,7 @@
|
||||
@@ -1809,7 +2619,7 @@
|
||||
case PERFORM_RESPAWN:
|
||||
if (this.player.wonGame) {
|
||||
this.player.wonGame = false;
|
||||
@ -1438,7 +1437,7 @@
|
||||
this.resetPosition();
|
||||
CriteriaTriggers.CHANGED_DIMENSION.trigger(this.player, Level.END, Level.OVERWORLD);
|
||||
} else {
|
||||
@@ -1817,11 +2626,11 @@
|
||||
@@ -1817,11 +2627,11 @@
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1452,7 +1451,7 @@
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1834,15 +2643,21 @@
|
||||
@@ -1834,15 +2644,21 @@
|
||||
@Override
|
||||
public void handleContainerClose(ServerboundContainerClosePacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -1476,7 +1475,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 +2670,284 @@
|
||||
@@ -1855,7 +2671,284 @@
|
||||
boolean flag = packet.getStateId() != this.player.containerMenu.getStateId();
|
||||
|
||||
this.player.containerMenu.suppressRemoteUpdates();
|
||||
@ -1762,7 +1761,7 @@
|
||||
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packet.getChangedSlots()).iterator();
|
||||
|
||||
while (objectiterator.hasNext()) {
|
||||
@@ -1901,8 +2993,22 @@
|
||||
@@ -1901,8 +2994,22 @@
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1786,7 +1785,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 +3023,7 @@
|
||||
@@ -1917,6 +3024,7 @@
|
||||
@Override
|
||||
public void handleContainerButtonClick(ServerboundContainerButtonClickPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -1794,7 +1793,7 @@
|
||||
this.player.resetLastActionTime();
|
||||
if (this.player.containerMenu.containerId == packet.containerId() && !this.player.isSpectator()) {
|
||||
if (!this.player.containerMenu.stillValid(this.player)) {
|
||||
@@ -1945,7 +3052,44 @@
|
||||
@@ -1945,7 +3053,44 @@
|
||||
|
||||
boolean flag1 = packet.slotNum() >= 1 && packet.slotNum() <= 45;
|
||||
boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize();
|
||||
@ -1839,7 +1838,7 @@
|
||||
if (flag1 && flag2) {
|
||||
this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemstack);
|
||||
this.player.inventoryMenu.setRemoteSlot(packet.slotNum(), itemstack);
|
||||
@@ -1972,6 +3116,7 @@
|
||||
@@ -1972,6 +3117,7 @@
|
||||
}
|
||||
|
||||
private void updateSignText(ServerboundSignUpdatePacket packet, List<FilteredText> signText) {
|
||||
@ -1847,7 +1846,7 @@
|
||||
this.player.resetLastActionTime();
|
||||
ServerLevel worldserver = this.player.serverLevel();
|
||||
BlockPos blockposition = packet.getPos();
|
||||
@@ -1993,7 +3138,17 @@
|
||||
@@ -1993,7 +3139,17 @@
|
||||
@Override
|
||||
public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -1866,7 +1865,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2002,6 +3157,7 @@
|
||||
@@ -2002,6 +3158,7 @@
|
||||
boolean flag = this.player.isModelPartShown(PlayerModelPart.HAT);
|
||||
|
||||
this.player.updateOptions(packet.information());
|
||||
@ -1874,7 +1873,7 @@
|
||||
if (this.player.isModelPartShown(PlayerModelPart.HAT) != flag) {
|
||||
this.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_HAT, this.player));
|
||||
}
|
||||
@@ -2058,7 +3214,7 @@
|
||||
@@ -2058,7 +3215,7 @@
|
||||
if (!this.waitingForSwitchToConfig) {
|
||||
throw new IllegalStateException("Client acknowledged config, but none was requested");
|
||||
} else {
|
||||
@ -1883,7 +1882,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2083,8 +3239,10 @@
|
||||
@@ -2083,8 +3240,10 @@
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user