From 4bf0ca21fe9ee9a89a09635fdca1923ca3408298 Mon Sep 17 00:00:00 2001 From: Zach Brown <1254957+zachbr@users.noreply.github.com> Date: Sat, 10 Sep 2016 23:27:07 -0500 Subject: [PATCH] Make UseItem rate limiting stricter, configurable --- .../Rate-limit-PacketPlayInUseItem.patch | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Spigot-Server-Patches/Rate-limit-PacketPlayInUseItem.patch b/Spigot-Server-Patches/Rate-limit-PacketPlayInUseItem.patch index 3b65d419fa..5a98d6fd15 100644 --- a/Spigot-Server-Patches/Rate-limit-PacketPlayInUseItem.patch +++ b/Spigot-Server-Patches/Rate-limit-PacketPlayInUseItem.patch @@ -4,6 +4,20 @@ Date: Sat, 10 Sep 2016 21:40:51 -0500 Subject: [PATCH] Rate limit PacketPlayInUseItem +diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java ++++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java +@@ -0,0 +0,0 @@ public class PaperConfig { + private static void bungeeOnlineMode() { + bungeeOnlineMode = getBoolean("settings.bungee-online-mode", true); + } ++ ++ public static int playInUseItemThreshold = 300; ++ private static void playInUseItemThreshold() { ++ playInUseItemThreshold = getInt("settings.play-in-use-item-spam-threshold", 300); ++ } + } diff --git a/src/main/java/net/minecraft/server/PacketPlayInUseItem.java b/src/main/java/net/minecraft/server/PacketPlayInUseItem.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/PacketPlayInUseItem.java @@ -43,6 +57,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start - Rate limit UseItem as well, copied from Spigot implementation below in BlockPlace + private long lastPlaceUse = -1; + private int packetsUse = 0; ++ private static final int THRESHOLD = com.destroystokyo.paper.PaperConfig.playInUseItemThreshold; + // Paper end public void a(PacketPlayInUseItem packetplayinuseitem) { PlayerConnectionUtils.ensureMainThread(packetplayinuseitem, this, this.player.x()); @@ -53,9 +68,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 this.player.resetIdleTimer(); + + // Paper start - Rate limit UseItem as well, copied from Spigot implementation below in BlockPlace -+ if (lastPlaceUse != -1 && packetplayinuseitem.timestamp - lastPlaceUse < 30 && packetsUse++ >= 4) { ++ if (lastPlaceUse != -1 && packetplayinuseitem.timestamp - lastPlaceUse < THRESHOLD && packetsUse++ >= 4) { + return; -+ } else if (packetplayinuseitem.timestamp - lastPlaceUse >= 30 || lastPlaceUse == -1) { ++ } else if (packetplayinuseitem.timestamp - lastPlaceUse >= THRESHOLD || lastPlaceUse == -1) { + lastPlaceUse = packetplayinuseitem.timestamp; + packetsUse = 0; + }