Paper/CraftBukkit-Patches/0122-Limit-block-placement-interaction-packets.patch

84 Zeilen
4.1 KiB
Diff

2015-06-01 11:22:52 +02:00
From b0893293463044447ddf36e23a571026dd0ba404 Mon Sep 17 00:00:00 2001
From: Thinkofdeath <thinkofdeath@spigotmc.org>
Date: Sun, 29 Jun 2014 21:10:34 +0100
Subject: [PATCH] Limit block placement/interaction packets
2015-03-15 23:18:05 +01:00
diff --git a/src/main/java/net/minecraft/server/PacketPlayInArmAnimation.java b/src/main/java/net/minecraft/server/PacketPlayInArmAnimation.java
2015-05-25 14:05:40 +02:00
index c611db1..28cb5e3 100644
2015-03-15 23:18:05 +01:00
--- a/src/main/java/net/minecraft/server/PacketPlayInArmAnimation.java
+++ b/src/main/java/net/minecraft/server/PacketPlayInArmAnimation.java
@@ -4,9 +4,13 @@ import java.io.IOException;
public class PacketPlayInArmAnimation implements Packet<PacketListenerPlayIn> {
+ public long timestamp; // Spigot
+
public PacketPlayInArmAnimation() {}
- public void a(PacketDataSerializer packetdataserializer) throws IOException {}
+ public void a(PacketDataSerializer packetdataserializer) throws IOException {
+ timestamp = System.currentTimeMillis(); // Spigot
+ }
public void b(PacketDataSerializer packetdataserializer) throws IOException {}
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index 43367dd..aac4851 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
2015-05-09 22:23:26 +02:00
@@ -628,9 +628,22 @@ public class PlayerConnection implements PacketListenerPlayIn, IUpdatePlayerList
2014-11-28 02:17:45 +01:00
// CraftBukkit end
}
+ // Spigot start - limit place/interactions
+ private long lastPlace = -1;
+ private int packets = 0;
+
public void a(PacketPlayInBlockPlace packetplayinblockplace) {
2014-11-28 02:17:45 +01:00
PlayerConnectionUtils.ensureMainThread(packetplayinblockplace, this, this.player.u());
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
+ boolean throttled = false;
+ if (lastPlace != -1 && packetplayinblockplace.timestamp - lastPlace < 30 && packets++ >= 4) {
+ throttled = true;
+ } else if ( packetplayinblockplace.timestamp - lastPlace >= 30 || lastPlace == -1 )
+ {
+ lastPlace = packetplayinblockplace.timestamp;
+ packets = 0;
+ }
+ // Spigot end
2015-05-09 22:23:26 +02:00
// CraftBukkit start
2014-11-28 02:17:45 +01:00
if (this.player.dead) return;
2015-05-09 22:23:26 +02:00
@@ -654,7 +667,8 @@ public class PlayerConnection implements PacketListenerPlayIn, IUpdatePlayerList
// CraftBukkit start
int itemstackAmount = itemstack.count;
2015-02-28 12:36:22 +01:00
-
+ // Spigot start - skip the event if throttled
+ if (!throttled) {
// Raytrace to look for 'rogue armswings'
float f1 = this.player.pitch;
float f2 = this.player.yaw;
2015-05-09 22:23:26 +02:00
@@ -690,6 +704,8 @@ public class PlayerConnection implements PacketListenerPlayIn, IUpdatePlayerList
if (!cancelled) {
this.player.playerInteractManager.useItem(this.player, this.player.world, itemstack);
}
+ }
+ // Spigot end
// CraftBukkit - notch decrements the counter by 1 in the above method with food,
// snowballs and so forth, but he does it in a place that doesn't cause the
2015-05-09 22:23:26 +02:00
@@ -715,7 +731,7 @@ public class PlayerConnection implements PacketListenerPlayIn, IUpdatePlayerList
}
2015-02-28 12:36:22 +01:00
if (this.checkMovement && 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)) {
2014-11-28 02:17:45 +01:00
- always = !this.player.playerInteractManager.interact(this.player, worldserver, itemstack, blockposition, enumdirection, packetplayinblockplace.d(), packetplayinblockplace.e(), packetplayinblockplace.f());
+ always = throttled || !this.player.playerInteractManager.interact(this.player, worldserver, itemstack, blockposition, enumdirection, packetplayinblockplace.d(), packetplayinblockplace.e(), packetplayinblockplace.f());
}
2014-11-28 02:17:45 +01:00
2015-02-28 12:36:22 +01:00
flag = true;
--
2015-05-09 22:23:26 +02:00
2.1.4