From 4dcb73693a9549b12347d16740b378f4486c9b19 Mon Sep 17 00:00:00 2001 From: Zach Brown <1254957+zachbr@users.noreply.github.com> Date: Sat, 10 Sep 2016 21:42:47 -0500 Subject: [PATCH] Add rate limiting to PacketPlayInUseItem as well Also removes our toggle for Spigot's option, I doubt anyone uses it. --- ...figurable-Chunk-IO-Thread-Base-Count.patch | 4 +- .../Rate-limit-PacketPlayInUseItem.patch | 76 +++++++++++++++++++ .../Toggle-for-player-interact-limiter.patch | 38 ---------- scripts/importmcdev.sh | 1 + 4 files changed, 79 insertions(+), 40 deletions(-) create mode 100644 Spigot-Server-Patches/Rate-limit-PacketPlayInUseItem.patch delete mode 100644 Spigot-Server-Patches/Toggle-for-player-interact-limiter.patch diff --git a/Spigot-Server-Patches/Configurable-Chunk-IO-Thread-Base-Count.patch b/Spigot-Server-Patches/Configurable-Chunk-IO-Thread-Base-Count.patch index 48d66d6a63..d2ce0959ce 100644 --- a/Spigot-Server-Patches/Configurable-Chunk-IO-Thread-Base-Count.patch +++ b/Spigot-Server-Patches/Configurable-Chunk-IO-Thread-Base-Count.patch @@ -9,8 +9,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- 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 { - Bukkit.getLogger().log(Level.INFO, "Disabling player interaction limiter, your server may be more vulnerable to malicious users"); - } + " - Interval: " + timeSummary(Timings.getHistoryInterval() / 20) + + " - Length: " + timeSummary(Timings.getHistoryLength() / 20)); } + + public static int minChunkLoadThreads = 2; diff --git a/Spigot-Server-Patches/Rate-limit-PacketPlayInUseItem.patch b/Spigot-Server-Patches/Rate-limit-PacketPlayInUseItem.patch new file mode 100644 index 0000000000..209979619d --- /dev/null +++ b/Spigot-Server-Patches/Rate-limit-PacketPlayInUseItem.patch @@ -0,0 +1,76 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Zach Brown <1254957+zachbr@users.noreply.github.com> +Date: Sat, 10 Sep 2016 21:40:51 -0500 +Subject: [PATCH] Rate limit PacketPlayInUseItem + + +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 ++++ b/src/main/java/net/minecraft/server/PacketPlayInUseItem.java +@@ -0,0 +0,0 @@ public class PacketPlayInUseItem implements Packet { + private float d; + private float e; + private float f; ++ public long timestamp; // Paper - Used for rate limiting + + public PacketPlayInUseItem() {} + +@@ -0,0 +0,0 @@ public class PacketPlayInUseItem implements Packet { + this.d = (float) packetdataserializer.readUnsignedByte() / 16.0F; + this.e = (float) packetdataserializer.readUnsignedByte() / 16.0F; + this.f = (float) packetdataserializer.readUnsignedByte() / 16.0F; ++ this.timestamp = System.currentTimeMillis(); // Paper + } + + public void b(PacketDataSerializer packetdataserializer) throws IOException { +@@ -0,0 +0,0 @@ public class PacketPlayInUseItem implements Packet { + packetdataserializer.writeByte((int) (this.d * 16.0F)); + packetdataserializer.writeByte((int) (this.e * 16.0F)); + packetdataserializer.writeByte((int) (this.f * 16.0F)); ++ this.timestamp = System.currentTimeMillis(); // Paper + } + + 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/PlayerConnection.java ++++ b/src/main/java/net/minecraft/server/PlayerConnection.java +@@ -0,0 +0,0 @@ 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; ++ // Paper end + public void a(PacketPlayInUseItem packetplayinuseitem) { + PlayerConnectionUtils.ensureMainThread(packetplayinuseitem, this, this.player.x()); + if (this.player.cj()) return; // CraftBukkit +@@ -0,0 +0,0 @@ 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 ++ boolean throttled = false; ++ if (lastPlaceUse != -1 && packetplayinuseitem.timestamp - lastPlaceUse < 30 && packetsUse++ >= 4) { ++ throttled = true; ++ } else if (packetplayinuseitem.timestamp - lastPlaceUse >= 30 || lastPlaceUse == -1) { ++ lastPlaceUse = packetplayinuseitem.timestamp; ++ packetsUse = 0; ++ } ++ // Paper end ++ + if (blockposition.getY() >= this.minecraftServer.getMaxBuildHeight() - 1 && (enumdirection == EnumDirection.UP || blockposition.getY() >= this.minecraftServer.getMaxBuildHeight())) { + ChatMessage chatmessage = new ChatMessage("build.tooHigh", new Object[] { Integer.valueOf(this.minecraftServer.getMaxBuildHeight())}); + + chatmessage.getChatModifier().setColor(EnumChatFormat.RED); + this.player.playerConnection.sendPacket(new PacketPlayOutChat(chatmessage)); +- } else if (this.teleportPos == null && this.player.e((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) < 64.0D && !this.minecraftServer.a(worldserver, blockposition, this.player) && worldserver.getWorldBorder().a(blockposition)) { ++ // Paper - Ignore if throttled ++ } else if (!throttled && this.teleportPos == null && this.player.e((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) < 64.0D && !this.minecraftServer.a(worldserver, blockposition, this.player) && worldserver.getWorldBorder().a(blockposition)) { + // CraftBukkit start - Check if we can actually do something over this large a distance + Location eyeLoc = this.getPlayer().getEyeLocation(); + double reachDistance = NumberConversions.square(eyeLoc.getX() - blockposition.getX()) + NumberConversions.square(eyeLoc.getY() - blockposition.getY()) + NumberConversions.square(eyeLoc.getZ() - blockposition.getZ()); +-- \ No newline at end of file diff --git a/Spigot-Server-Patches/Toggle-for-player-interact-limiter.patch b/Spigot-Server-Patches/Toggle-for-player-interact-limiter.patch deleted file mode 100644 index 05ce70c982..0000000000 --- a/Spigot-Server-Patches/Toggle-for-player-interact-limiter.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Zach Brown <1254957+zachbr@users.noreply.github.com> -Date: Tue, 1 Mar 2016 13:31:05 -0600 -Subject: [PATCH] Toggle for player interact limiter - - -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 { - " - Interval: " + timeSummary(Timings.getHistoryInterval() / 20) + - " - Length: " + timeSummary(Timings.getHistoryLength() / 20)); - } -+ -+ public static boolean useInteractLimiter; -+ private static void useInteractLimiter() { -+ useInteractLimiter = getBoolean("settings.limit-player-interactions", true); -+ if (!useInteractLimiter) { -+ Bukkit.getLogger().log(Level.INFO, "Disabling player interaction limiter, your server may be more vulnerable to malicious users"); -+ } -+ } - } -diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/net/minecraft/server/PlayerConnection.java -+++ b/src/main/java/net/minecraft/server/PlayerConnection.java -@@ -0,0 +0,0 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable { - this.player.resetIdleTimer(); - // Spigot start - boolean throttled = false; -- if (lastPlace != -1 && packetplayinblockplace.timestamp - lastPlace < 30 && packets++ >= 4) { -+ // Paper - Allow disabling interact limiter -+ if (com.destroystokyo.paper.PaperConfig.useInteractLimiter && lastPlace != -1 && packetplayinblockplace.timestamp - lastPlace < 30 && packets++ >= 4) { - throttled = true; - } else if ( packetplayinblockplace.timestamp - lastPlace >= 30 || lastPlace == -1 ) - { --- \ No newline at end of file diff --git a/scripts/importmcdev.sh b/scripts/importmcdev.sh index c4d6dd50de..2c07a45038 100755 --- a/scripts/importmcdev.sh +++ b/scripts/importmcdev.sh @@ -68,6 +68,7 @@ import NBTTagCompound import NBTTagList import PersistentScoreboard import PacketPlayInUseEntity +import PacketPlayInUseItem import PacketPlayOutPlayerListHeaderFooter import PacketPlayOutScoreboardTeam import PacketPlayOutTitle