From 2e880e76761c1956597c7027712dab9552acce34 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Sat, 10 Sep 2016 23:27:07 -0500 Subject: [PATCH] Make UseItem rate limiting stricter, configurable --- .../0012-Add-PlayerInitialSpawnEvent.patch | 4 +-- ...ly-disable-plugins-that-fail-to-load.patch | 4 +-- .../0170-Rate-limit-PacketPlayInUseItem.patch | 27 ++++++++++++++----- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Spigot-API-Patches/0012-Add-PlayerInitialSpawnEvent.patch b/Spigot-API-Patches/0012-Add-PlayerInitialSpawnEvent.patch index 625d6bd6d..b203f65f4 100644 --- a/Spigot-API-Patches/0012-Add-PlayerInitialSpawnEvent.patch +++ b/Spigot-API-Patches/0012-Add-PlayerInitialSpawnEvent.patch @@ -1,4 +1,4 @@ -From 3dabbf24d9e169631ff0f11df707e0623c4d2cc4 Mon Sep 17 00:00:00 2001 +From f41fd8808accbe9c7771647d3beddc54fc5e7036 Mon Sep 17 00:00:00 2001 From: Steve Anton Date: Mon, 29 Feb 2016 18:13:58 -0600 Subject: [PATCH] Add PlayerInitialSpawnEvent @@ -55,5 +55,5 @@ index 0000000..d1d6f33 + } +} -- -2.8.0 +2.10.0.windows.1 diff --git a/Spigot-API-Patches/0014-Automatically-disable-plugins-that-fail-to-load.patch b/Spigot-API-Patches/0014-Automatically-disable-plugins-that-fail-to-load.patch index f76fbefcc..3d8324593 100644 --- a/Spigot-API-Patches/0014-Automatically-disable-plugins-that-fail-to-load.patch +++ b/Spigot-API-Patches/0014-Automatically-disable-plugins-that-fail-to-load.patch @@ -1,4 +1,4 @@ -From aca5c5298ce7fca0a9b6d8c8240f94d1a09de085 Mon Sep 17 00:00:00 2001 +From 90e6868ac669e61bc3b0e176b452181dcf078c2c Mon Sep 17 00:00:00 2001 From: Aikar Date: Mon, 29 Feb 2016 19:45:21 -0600 Subject: [PATCH] Automatically disable plugins that fail to load @@ -20,5 +20,5 @@ index 759c461..d8b9c24 100644 // Perhaps abort here, rather than continue going, but as it stands, -- -2.9.3 +2.10.0.windows.1 diff --git a/Spigot-Server-Patches/0170-Rate-limit-PacketPlayInUseItem.patch b/Spigot-Server-Patches/0170-Rate-limit-PacketPlayInUseItem.patch index 4f4f66ac0..46e41f93a 100644 --- a/Spigot-Server-Patches/0170-Rate-limit-PacketPlayInUseItem.patch +++ b/Spigot-Server-Patches/0170-Rate-limit-PacketPlayInUseItem.patch @@ -1,9 +1,23 @@ -From 7d5d1e68148e2a526c03aeadffcda93ff8787394 Mon Sep 17 00:00:00 2001 +From 49a2546fd62526b61f8dc3b7e88093a5cbcb709a Mon Sep 17 00:00:00 2001 From: Zach Brown 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 f40440f..f1973e3 100644 +--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java ++++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java +@@ -225,4 +225,9 @@ 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 82e09c1..88ac278 100644 --- a/src/main/java/net/minecraft/server/PacketPlayInUseItem.java @@ -33,29 +47,30 @@ index 82e09c1..88ac278 100644 public void a(PacketListenerPlayIn packetlistenerplayin) { diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java -index 3d04119..a299f4f 100644 +index 3d04119..ab30d39 100644 --- a/src/main/java/net/minecraft/server/PlayerConnection.java +++ b/src/main/java/net/minecraft/server/PlayerConnection.java -@@ -865,6 +865,10 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable { +@@ -865,6 +865,11 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable { // CraftBukkit end } + // 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()); if (this.player.cj()) return; // CraftBukkit -@@ -875,6 +879,16 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable { +@@ -875,6 +880,16 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable { EnumDirection enumdirection = packetplayinuseitem.b(); 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; + }