mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
Add rate limiting to PacketPlayInUseItem as well
Also removes our toggle for Spigot's option, I doubt anyone uses it.
This commit is contained in:
parent
89b26bb90d
commit
4dcb73693a
@ -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;
|
||||
|
76
Spigot-Server-Patches/Rate-limit-PacketPlayInUseItem.patch
Normal file
76
Spigot-Server-Patches/Rate-limit-PacketPlayInUseItem.patch
Normal file
@ -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<PacketListenerPlayIn> {
|
||||
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<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 {
|
||||
@@ -0,0 +0,0 @@ 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 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());
|
||||
--
|
@ -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 )
|
||||
{
|
||||
--
|
@ -68,6 +68,7 @@ import NBTTagCompound
|
||||
import NBTTagList
|
||||
import PersistentScoreboard
|
||||
import PacketPlayInUseEntity
|
||||
import PacketPlayInUseItem
|
||||
import PacketPlayOutPlayerListHeaderFooter
|
||||
import PacketPlayOutScoreboardTeam
|
||||
import PacketPlayOutTitle
|
||||
|
Loading…
Reference in New Issue
Block a user