From 7f28deefcb9cf32189023343dad12279f7d4660f Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 15 Apr 2015 19:30:49 +0200 Subject: [PATCH] Better BatchPacket decoding and LoginPacket handling --- src/pocketmine/network/Network.php | 30 ++++++++++++------- src/pocketmine/network/RakLibInterface.php | 4 ++- .../network/protocol/LoginPacket.php | 2 +- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 91b023938..7494c00c0 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -211,17 +211,27 @@ class Network{ $str = zlib_decode($packet->payload, 1024 * 1024 * 64); //Max 64MB $len = strlen($str); $offset = 0; - while($offset < $len){ - if(($pk = $this->getPacket(ord($str{$offset++}))) !== null){ - if($pk->pid() === Info::BATCH_PACKET){ - return; + try{ + while($offset < $len){ + if(($pk = $this->getPacket(ord($str{$offset++}))) !== null){ + if($pk->pid() === Info::BATCH_PACKET){ + throw new \InvalidStateException("Invalid BatchPacket inside BatchPacket"); + } + $pk->setBuffer(substr($str, $offset)); + $pk->decode(); + $p->handleDataPacket($pk); + $offset += $pk->getOffset(); + if($pk->getOffset() <= 0){ + return; + } } - $pk->setBuffer(substr($str, $offset)); - $pk->decode(); - $p->handleDataPacket($pk); - $offset += $pk->getOffset(); - if($pk->getOffset() <= 0){ - return; + } + }catch(\Exception $e){ + if(\pocketmine\DEBUG > 1){ + $logger = $this->server->getLogger(); + if($logger instanceof MainLogger){ + $logger->debug("BatchPacket " . " 0x" . bin2hex($packet->payload)); + $logger->logException($e); } } } diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/RakLibInterface.php index 3324d84af..2e8b0d31f 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/RakLibInterface.php @@ -157,7 +157,9 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ } } - $this->interface->blockAddress($this->players[$identifier]->getAddress(), 5); + if(isset($this->players[$identifier])){ + $this->interface->blockAddress($this->players[$identifier]->getAddress(), 5); + } } } } diff --git a/src/pocketmine/network/protocol/LoginPacket.php b/src/pocketmine/network/protocol/LoginPacket.php index e07bc18cb..f287f97a7 100644 --- a/src/pocketmine/network/protocol/LoginPacket.php +++ b/src/pocketmine/network/protocol/LoginPacket.php @@ -44,7 +44,7 @@ class LoginPacket extends DataPacket{ $this->username = $this->getString(); $this->protocol1 = $this->getInt(); $this->protocol2 = $this->getInt(); - if(Info::CURRENT_PROTOCOL != $this->protocol1){ + if($this->protocol1 < 21){ //New fields! return; } $this->clientId = $this->getInt();