From 1393b4c4e2d7f774e844fb5fde00f4ee87065d1b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 31 Dec 2018 19:16:13 +0000 Subject: [PATCH] Player: aDd a HacK foR CliEnt SidE rIghT cLicK SpaM BuG this bug has existed for so long I forgot it was still here. People stopped pestering me to do something about it, and as a result I forgot to do anything about it. This hack isn't perfect, but it filters out the worst of the noise. It has side effects for legitimate fast double-clicks, but I don't think anyone will be too bothered - just click more slowly. This hack may also have negative side effects on poor connections where latency spikes are a problem, but there isn't really much that can be done about that. --- src/pocketmine/Player.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 56cabe00b..689f036ec 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -327,6 +327,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** @var Form[] */ protected $forms = []; + /** @var float */ + protected $lastRightClickTime = 0.0; + /** @var Vector3|null */ + protected $lastRightClickPos = null; + /** * @return TranslationContainer|string */ @@ -2333,6 +2338,19 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $type = $packet->trData->actionType; switch($type){ case InventoryTransactionPacket::USE_ITEM_ACTION_CLICK_BLOCK: + //TODO: start hack for client spam bug + $spamBug = ($this->lastRightClickPos !== null and + microtime(true) - $this->lastRightClickTime < 0.1 and //100ms + $this->lastRightClickPos->distanceSquared($packet->trData->clickPos) < 0.00001 //signature spam bug has 0 distance, but allow some error + ); + //get rid of continued spam if the player clicks and holds right-click + $this->lastRightClickPos = clone $packet->trData->clickPos; + $this->lastRightClickTime = microtime(true); + if($spamBug){ + return true; + } + //TODO: end hack for client spam bug + $this->setUsingItem(false); if(!$this->canInteract($blockVector->add(0.5, 0.5, 0.5), 13) or $this->isSpectator()){