84 lines
4.2 KiB
Diff
84 lines
4.2 KiB
Diff
From 49a2546fd62526b61f8dc3b7e88093a5cbcb709a Mon Sep 17 00:00:00 2001
|
|
From: Zach Brown <zach.brown@destroystokyo.com>
|
|
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
|
|
+++ b/src/main/java/net/minecraft/server/PacketPlayInUseItem.java
|
|
@@ -10,6 +10,7 @@ public class PacketPlayInUseItem implements Packet<PacketListenerPlayIn> {
|
|
private float d;
|
|
private float e;
|
|
private float f;
|
|
+ public long timestamp; // Paper - Used for rate limiting
|
|
|
|
public PacketPlayInUseItem() {}
|
|
|
|
@@ -20,6 +21,7 @@ public class PacketPlayInUseItem implements Packet<PacketListenerPlayIn> {
|
|
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 {
|
|
@@ -29,6 +31,7 @@ public class PacketPlayInUseItem implements Packet<PacketListenerPlayIn> {
|
|
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 3d04119..ab30d39 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
@@ -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 +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 < THRESHOLD && packetsUse++ >= 4) {
|
|
+ return;
|
|
+ } else if (packetplayinuseitem.timestamp - lastPlaceUse >= THRESHOLD || 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())});
|
|
|
|
--
|
|
2.10.0.windows.1
|
|
|