From 4a9acf564ca871f4e7ad6e5d0f85c5f55704896a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 13 May 2017 19:26:57 +0100 Subject: [PATCH 1/3] Silence PlayerFallPacket unhandled spam we're not using this packet --- src/pocketmine/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index f4c75dee5..b9809f763 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2763,7 +2763,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } public function handlePlayerFall(PlayerFallPacket $packet) : bool{ - return false; + return true; //not used } public function handleHurtArmor(HurtArmorPacket $packet) : bool{ From dbb8e8ad0ad793d73492ad54157249144508c47f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 14 May 2017 12:07:15 +0100 Subject: [PATCH 2/3] Improved checks for event registration --- src/pocketmine/plugin/PluginManager.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/plugin/PluginManager.php b/src/pocketmine/plugin/PluginManager.php index aba41363b..ec1aaf822 100644 --- a/src/pocketmine/plugin/PluginManager.php +++ b/src/pocketmine/plugin/PluginManager.php @@ -754,8 +754,15 @@ class PluginManager{ if($class->isAbstract()){ throw new PluginException($event . " is an abstract Event"); } - if($class->getProperty("handlerList")->getDeclaringClass()->getName() !== $event){ - throw new PluginException($event . " does not have a handler list"); + + if(!$class->hasProperty("handlerList") or ($property = $class->getProperty("handlerList"))->getDeclaringClass()->getName() !== $event){ + throw new PluginException($event . " does not have a valid handler list"); + } + if(!$property->isStatic()){ + throw new PluginException($event . " handlerList property is not static"); + } + if(!$property->isPublic()){ + throw new PluginException($event . " handlerList property is not public"); } if(!$plugin->isEnabled()){ From 576702ffa97e16b1ca4cdee7d94460c661347ca7 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 14 May 2017 16:15:15 +0100 Subject: [PATCH 3/3] Improved handling of incompatible protocols Allow plugins to hack around incompatible protocol numbers :see_no_evil: --- src/pocketmine/Player.php | 27 ++++++++++++------- .../network/mcpe/protocol/LoginPacket.php | 7 ++--- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b9809f763..b4ffe0c1f 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1907,15 +1907,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return false; } - $this->username = TextFormat::clean($packet->username); - $this->displayName = $this->username; - $this->iusername = strtolower($this->username); - $this->setDataProperty(self::DATA_NAMETAG, self::DATA_TYPE_STRING, $this->username, false); - - if(count($this->server->getOnlinePlayers()) >= $this->server->getMaxPlayers() and $this->kick("disconnectionScreen.serverFull", false)){ - return true; - } - if($packet->protocol !== ProtocolInfo::CURRENT_PROTOCOL){ if($packet->protocol < ProtocolInfo::CURRENT_PROTOCOL){ $message = "disconnectionScreen.outdatedClient"; @@ -1929,6 +1920,19 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return true; } + $packet->decodeAdditional(); + + //TODO: check MCEE + + $this->username = TextFormat::clean($packet->username); + $this->displayName = $this->username; + $this->iusername = strtolower($this->username); + $this->setDataProperty(self::DATA_NAMETAG, self::DATA_TYPE_STRING, $this->username, false); + + if(count($this->server->getOnlinePlayers()) >= $this->server->getMaxPlayers() and $this->kick("disconnectionScreen.serverFull", false)){ + return true; + } + $this->randomClientId = $packet->clientId; $this->uuid = UUID::fromString($packet->clientUUID); @@ -3365,13 +3369,16 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $timings->startTiming(); $packet->decode(); - assert($packet->feof(), "Still " . strlen(substr($packet->buffer, $packet->offset)) . " bytes unread in " . get_class($packet)); $this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet)); if(!$ev->isCancelled() and !$packet->handle($this)){ $this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->getName() . ": 0x" . bin2hex($packet->buffer)); } + if(!$packet->feof()){ + $this->server->getLogger()->debug("Still " . strlen(substr($packet->buffer, $packet->offset)) . " bytes unread in " . get_class($packet) . " from " . $this->getName() . ": " . bin2hex($packet->get(true))); + } + $timings->stopTiming(); } diff --git a/src/pocketmine/network/mcpe/protocol/LoginPacket.php b/src/pocketmine/network/mcpe/protocol/LoginPacket.php index b8a596475..be249eb03 100644 --- a/src/pocketmine/network/mcpe/protocol/LoginPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LoginPacket.php @@ -54,12 +54,9 @@ class LoginPacket extends DataPacket{ public function decode(){ $this->protocol = $this->getInt(); + } - if($this->protocol !== ProtocolInfo::CURRENT_PROTOCOL){ - $this->buffer = null; - return; //Do not attempt to decode for non-accepted protocols - } - + public function decodeAdditional(){ $this->gameEdition = $this->getByte(); $str = zlib_decode($this->getString(), 1024 * 1024 * 64);