2015-04-19 10:20:50 +00:00
|
|
|
From 4d08e72d67e499a79d97a6702f8db54fe287496e Mon Sep 17 00:00:00 2001
|
2014-07-21 20:46:54 +00:00
|
|
|
From: Thinkofdeath <thinkofdeath@spigotmc.org>
|
|
|
|
Date: Sun, 29 Jun 2014 21:10:34 +0100
|
|
|
|
Subject: [PATCH] Limit block placement/interaction packets
|
|
|
|
|
|
|
|
|
2015-03-15 22:18:05 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/PacketPlayInArmAnimation.java b/src/main/java/net/minecraft/server/PacketPlayInArmAnimation.java
|
|
|
|
index c611db1..28cb5e3 100644
|
|
|
|
--- 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 {}
|
|
|
|
|
2014-07-21 20:46:54 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
2015-04-19 10:20:50 +00:00
|
|
|
index c46e943..b64503d 100644
|
2014-07-21 20:46:54 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
2015-04-19 10:20:50 +00:00
|
|
|
@@ -632,10 +632,23 @@ public class PlayerConnection implements PacketListenerPlayIn, IUpdatePlayerList
|
2014-11-28 01:17:45 +00:00
|
|
|
// CraftBukkit end
|
2014-07-21 20:46:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // Spigot start - limit place/interactions
|
|
|
|
+ private long lastPlace = -1;
|
2014-07-25 03:21:57 +00:00
|
|
|
+ private int packets = 0;
|
2014-07-21 20:46:54 +00:00
|
|
|
+
|
|
|
|
public void a(PacketPlayInBlockPlace packetplayinblockplace) {
|
2014-11-28 01:17:45 +00:00
|
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinblockplace, this, this.player.u());
|
|
|
|
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
|
2015-02-28 11:36:22 +00:00
|
|
|
-
|
2014-07-21 20:46:54 +00:00
|
|
|
+ boolean throttled = false;
|
2014-07-25 03:21:57 +00:00
|
|
|
+ if (lastPlace != -1 && packetplayinblockplace.timestamp - lastPlace < 30 && packets++ >= 4) {
|
2014-07-21 20:46:54 +00:00
|
|
|
+ throttled = true;
|
2014-07-25 03:21:57 +00:00
|
|
|
+ } else if ( packetplayinblockplace.timestamp - lastPlace >= 30 || lastPlace == -1 )
|
2014-07-21 20:46:54 +00:00
|
|
|
+ {
|
|
|
|
+ lastPlace = packetplayinblockplace.timestamp;
|
2014-07-25 03:21:57 +00:00
|
|
|
+ packets = 0;
|
2014-07-21 20:46:54 +00:00
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
2015-02-28 11:36:22 +00:00
|
|
|
+
|
2014-07-21 20:46:54 +00:00
|
|
|
// CraftBukkit start
|
2014-11-28 01:17:45 +00:00
|
|
|
if (this.player.dead) return;
|
2015-02-28 11:36:22 +00:00
|
|
|
|
2015-04-19 10:20:50 +00:00
|
|
|
@@ -658,7 +671,8 @@ public class PlayerConnection implements PacketListenerPlayIn, IUpdatePlayerList
|
2014-07-21 20:46:54 +00:00
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
int itemstackAmount = itemstack.count;
|
2015-02-28 11:36:22 +00:00
|
|
|
-
|
2014-07-21 20:46:54 +00:00
|
|
|
+ // Spigot start - skip the event if throttled
|
2014-12-07 19:26:30 +00:00
|
|
|
+ if (!throttled) {
|
|
|
|
// Raytrace to look for 'rogue armswings'
|
|
|
|
float f1 = this.player.pitch;
|
|
|
|
float f2 = this.player.yaw;
|
2015-04-19 10:20:50 +00:00
|
|
|
@@ -694,6 +708,8 @@ public class PlayerConnection implements PacketListenerPlayIn, IUpdatePlayerList
|
2014-12-10 01:58:37 +00:00
|
|
|
if (!cancelled) {
|
2014-07-21 20:46:54 +00:00
|
|
|
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-04-19 10:20:50 +00:00
|
|
|
@@ -719,7 +735,7 @@ public class PlayerConnection implements PacketListenerPlayIn, IUpdatePlayerList
|
2014-07-21 20:46:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-28 11:36:22 +00: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 01:17:45 +00: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-07-21 20:46:54 +00:00
|
|
|
}
|
2014-11-28 01:17:45 +00:00
|
|
|
|
2015-02-28 11:36:22 +00:00
|
|
|
flag = true;
|
2015-04-19 10:20:50 +00:00
|
|
|
@@ -1136,6 +1152,19 @@ public class PlayerConnection implements PacketListenerPlayIn, IUpdatePlayerList
|
2015-03-15 22:09:27 +00:00
|
|
|
public void a(PacketPlayInArmAnimation packetplayinarmanimation) {
|
|
|
|
if (this.player.dead) return; // CraftBukkit
|
|
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinarmanimation, this, this.player.u());
|
|
|
|
+ // Spigot start
|
|
|
|
+ boolean throttled = false;
|
|
|
|
+ if (lastPlace != -1 && packetplayinarmanimation.timestamp - lastPlace < 30 && packets++ >= 4) {
|
|
|
|
+ throttled = true;
|
|
|
|
+ } else if ( packetplayinarmanimation.timestamp - lastPlace >= 30 || lastPlace == -1 )
|
|
|
|
+ {
|
|
|
|
+ lastPlace = packetplayinarmanimation.timestamp;
|
|
|
|
+ packets = 0;
|
|
|
|
+ }
|
|
|
|
+ if (throttled) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
this.player.z();
|
|
|
|
// CraftBukkit start - Raytrace to look for 'rogue armswings'
|
|
|
|
float f1 = this.player.pitch;
|
2014-07-21 20:46:54 +00:00
|
|
|
--
|
2014-11-28 01:17:45 +00:00
|
|
|
2.1.0
|
2014-07-21 20:46:54 +00:00
|
|
|
|