From d6d47feda9c3c22bde0f236aeb73567c91e4bf00 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 27 Feb 2018 13:22:15 +0000 Subject: [PATCH] Query: Send responses to the source interface only, instead of all the things who the fuck wrote this shitty code? --- src/pocketmine/Server.php | 12 +++++++----- src/pocketmine/network/mcpe/RakLibInterface.php | 2 +- src/pocketmine/network/query/QueryHandler.php | 7 ++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 2769f089a..18497612d 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -78,6 +78,7 @@ use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\LongTag; use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\StringTag; +use pocketmine\network\AdvancedSourceInterface; use pocketmine\network\CompressBatchedTask; use pocketmine\network\mcpe\protocol\BatchPacket; use pocketmine\network\mcpe\protocol\DataPacket; @@ -2452,16 +2453,17 @@ class Server{ } /** - * @param string $address - * @param int $port - * @param string $payload + * @param AdvancedSourceInterface $interface + * @param string $address + * @param int $port + * @param string $payload * * TODO: move this to Network */ - public function handlePacket(string $address, int $port, string $payload){ + public function handlePacket(AdvancedSourceInterface $interface, string $address, int $port, string $payload){ try{ if(strlen($payload) > 2 and substr($payload, 0, 2) === "\xfe\xfd" and $this->queryHandler instanceof QueryHandler){ - $this->queryHandler->handle($address, $port, $payload); + $this->queryHandler->handle($interface, $address, $port, $payload); } }catch(\Throwable $e){ if(\pocketmine\DEBUG > 1){ diff --git a/src/pocketmine/network/mcpe/RakLibInterface.php b/src/pocketmine/network/mcpe/RakLibInterface.php index ca83ae4b3..a654f81af 100644 --- a/src/pocketmine/network/mcpe/RakLibInterface.php +++ b/src/pocketmine/network/mcpe/RakLibInterface.php @@ -165,7 +165,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ } public function handleRaw(string $address, int $port, string $payload) : void{ - $this->server->handlePacket($address, $port, $payload); + $this->server->handlePacket($this, $address, $port, $payload); } public function sendRawPacket(string $address, int $port, string $payload){ diff --git a/src/pocketmine/network/query/QueryHandler.php b/src/pocketmine/network/query/QueryHandler.php index b34486817..c5c8835af 100644 --- a/src/pocketmine/network/query/QueryHandler.php +++ b/src/pocketmine/network/query/QueryHandler.php @@ -27,6 +27,7 @@ declare(strict_types=1); */ namespace pocketmine\network\query; +use pocketmine\network\AdvancedSourceInterface; use pocketmine\Server; use pocketmine\utils\Binary; @@ -73,7 +74,7 @@ class QueryHandler{ return Binary::readInt(substr(hash("sha512", $salt . ":" . $token, true), 7, 4)); } - public function handle($address, $port, $packet){ + public function handle(AdvancedSourceInterface $interface, string $address, int $port, string $packet){ $offset = 2; $packetType = ord($packet{$offset++}); $sessionID = Binary::readInt(substr($packet, $offset, 4)); @@ -86,7 +87,7 @@ class QueryHandler{ $reply .= Binary::writeInt($sessionID); $reply .= self::getTokenString($this->token, $address) . "\x00"; - $this->server->getNetwork()->sendPacket($address, $port, $reply); + $interface->sendRawPacket($address, $port, $reply); break; case self::STATISTICS: //Stat $token = Binary::readInt(substr($payload, 0, 4)); @@ -105,7 +106,7 @@ class QueryHandler{ }else{ $reply .= $this->shortData; } - $this->server->getNetwork()->sendPacket($address, $port, $reply); + $interface->sendRawPacket($address, $port, $reply); break; } }