Better BatchPacket decoding and LoginPacket handling

This commit is contained in:
Shoghi Cervantes 2015-04-15 19:30:49 +02:00
parent 81fe98d4cc
commit 7f28deefcb
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
3 changed files with 24 additions and 12 deletions

View File

@ -211,17 +211,27 @@ class Network{
$str = zlib_decode($packet->payload, 1024 * 1024 * 64); //Max 64MB $str = zlib_decode($packet->payload, 1024 * 1024 * 64); //Max 64MB
$len = strlen($str); $len = strlen($str);
$offset = 0; $offset = 0;
while($offset < $len){ try{
if(($pk = $this->getPacket(ord($str{$offset++}))) !== null){ while($offset < $len){
if($pk->pid() === Info::BATCH_PACKET){ if(($pk = $this->getPacket(ord($str{$offset++}))) !== null){
return; 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(); }catch(\Exception $e){
$p->handleDataPacket($pk); if(\pocketmine\DEBUG > 1){
$offset += $pk->getOffset(); $logger = $this->server->getLogger();
if($pk->getOffset() <= 0){ if($logger instanceof MainLogger){
return; $logger->debug("BatchPacket " . " 0x" . bin2hex($packet->payload));
$logger->logException($e);
} }
} }
} }

View File

@ -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);
}
} }
} }
} }

View File

@ -44,7 +44,7 @@ class LoginPacket extends DataPacket{
$this->username = $this->getString(); $this->username = $this->getString();
$this->protocol1 = $this->getInt(); $this->protocol1 = $this->getInt();
$this->protocol2 = $this->getInt(); $this->protocol2 = $this->getInt();
if(Info::CURRENT_PROTOCOL != $this->protocol1){ if($this->protocol1 < 21){ //New fields!
return; return;
} }
$this->clientId = $this->getInt(); $this->clientId = $this->getInt();