From 65e44364e50b9be357af5ea60483a857e6a95973 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 13 Jul 2018 10:07:11 +0100 Subject: [PATCH 1/2] Added some debug for raw packets and Query handling --- src/pocketmine/Server.php | 2 ++ src/pocketmine/network/query/QueryHandler.php | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 94b4305f1..aa24df888 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -2471,6 +2471,8 @@ class Server{ try{ if(strlen($payload) > 2 and substr($payload, 0, 2) === "\xfe\xfd" and $this->queryHandler instanceof QueryHandler){ $this->queryHandler->handle($interface, $address, $port, $payload); + }else{ + $this->logger->debug("Unhandled raw packet from $address $port: " . bin2hex($payload)); } }catch(\Throwable $e){ if(\pocketmine\DEBUG > 1){ diff --git a/src/pocketmine/network/query/QueryHandler.php b/src/pocketmine/network/query/QueryHandler.php index 7c6770097..2a34cddb2 100644 --- a/src/pocketmine/network/query/QueryHandler.php +++ b/src/pocketmine/network/query/QueryHandler.php @@ -58,6 +58,11 @@ class QueryHandler{ $this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.server.query.running", [$addr, $port])); } + private function debug(string $message) : void{ + //TODO: replace this with a proper prefixed logger + $this->server->getLogger()->debug("[Query] $message"); + } + public function regenerateInfo(){ $ev = $this->server->getQueryInformation(); $this->longData = $ev->getLongQuery(); @@ -91,7 +96,8 @@ class QueryHandler{ break; case self::STATISTICS: //Stat $token = Binary::readInt(substr($payload, 0, 4)); - if($token !== self::getTokenString($this->token, $address) and $token !== self::getTokenString($this->lastToken, $address)){ + if($token !== ($t1 = self::getTokenString($this->token, $address)) and $token !== ($t2 = self::getTokenString($this->lastToken, $address))){ + $this->debug("Bad token $token from $address $port, expected $t1 or $t2"); break; } $reply = chr(self::STATISTICS); @@ -108,6 +114,9 @@ class QueryHandler{ } $interface->sendRawPacket($address, $port, $reply); break; + default: + $this->debug("Unhandled packet from $address $port: 0x" . bin2hex($packet)); + break; } } } From d8cf835f92d9e093d5fadd2d6d87241e98095924 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 13 Jul 2018 12:26:19 +0100 Subject: [PATCH 2/2] BlockFactory: better handling for dodgy IDs I thought I'd already dealt with this, but it seems not. --- src/pocketmine/block/BlockFactory.php | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/pocketmine/block/BlockFactory.php b/src/pocketmine/block/BlockFactory.php index 6101cde27..4774b4c58 100644 --- a/src/pocketmine/block/BlockFactory.php +++ b/src/pocketmine/block/BlockFactory.php @@ -25,7 +25,6 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\level\Position; -use pocketmine\utils\MainLogger; /** * Manages block registration and instance creation @@ -436,19 +435,12 @@ class BlockFactory{ * @return int */ public static function toStaticRuntimeId(int $id, int $meta = 0) : int{ - if($id === Block::AIR){ - //TODO: HACK! (weird air blocks with non-zero damage values shouldn't turn into update! blocks) - $meta = 0; - } - - $index = ($id << 4) | $meta; - if(!isset(self::$staticRuntimeIdMap[$index])){ - self::registerMapping($rtId = ++self::$lastRuntimeId, $id, $meta); - MainLogger::getLogger()->error("ID $id meta $meta does not have a corresponding block static runtime ID, added a new unknown runtime ID ($rtId)"); - return $rtId; - } - - return self::$staticRuntimeIdMap[$index]; + /* + * try id+meta first + * if not found, try id+0 (strip meta) + * if still not found, return update! block + */ + return self::$staticRuntimeIdMap[($id << 4) | $meta] ?? self::$staticRuntimeIdMap[$id << 4] ?? self::$staticRuntimeIdMap[BlockIds::INFO_UPDATE << 4]; } /**