diff --git a/src/network/protocol/DataPacket.php b/src/network/protocol/DataPacket.php new file mode 100644 index 000000000..085c88aad --- /dev/null +++ b/src/network/protocol/DataPacket.php @@ -0,0 +1,115 @@ +decoded = true; + $this->encoded = true; + } + + private function get($len){ + if($len <= 0){ + return ""; + } + if($len === true){ + return substr($this->raw, $this->offset); + } + $this->offset += $len; + return substr($this->raw, $this->offset - $len, $len); + } + + private function getLong($unsigned = false){ + return Utils::readLong($this->get(8), $unsigned); + } + + private function getInt($unsigned = false){ + return Utils::readInt($this->get(4), $unsigned); + } + + private function getShort($unsigned = false){ + return Utils::readShort($this->get(2), $unsigned); + } + + private function getLTriad(){ + return Utils::readTriad($this->get(3)); + } + + private function getLTriad(){ + return Utils::readTriad(strrev($this->get(3))); + } + + private function getByte(){ + return ord($this->get(1)); + } + + private function getDataArray($len = 10){ + $data = array(); + for($i = 1; $i <= $len and !$this->feof(); ++$i){ + $data[] = $this->get($this->getTriad()); + } + return $data; + } + + private function feof(){ + return !isset($this->raw{$this->offset}); + } + + public function decode(){ + if(!isset($this->raw{0})){ + return false; + } + $this->offset = 0; + switch($this->id){ + case MC_PING: + $this->timestamp = $this->getLong(); + break; + case MC_PONG: + $this->originalTimestamp = $this->getLong(); + $this->timestamp = $this->getLong(); + break; + case MC_CLIENT_CONNECT: + $this->clientID = $this->getLong(); + $this->session = $this->getLong(); + $this->unknown0 = $this->get(1); + break; + case MC_CLIENT_HANDSHAKE: + $this->cookie = $this->get(4); + $this->security = $this->get(1); + $this->port = $this->getShort(true); + $this->dataArray0 = $this->get($this->getByte()); + $this->dataArray = $this->getDataArray(9); + $this->timestamp = $this->get(2); + $this->session2 = $this->getLong(); + $this->session = $this->getLong(); + break; + default: + return false; + } + $this->encoded = true; + $this->decoded = true; + } +} \ No newline at end of file diff --git a/src/network/raknet/RakNetParser.php b/src/network/raknet/RakNetParser.php index 2db124198..63c92323b 100644 --- a/src/network/raknet/RakNetParser.php +++ b/src/network/raknet/RakNetParser.php @@ -121,7 +121,7 @@ class RakNetParser{ } private function parseDataPacket(){ - $data = new stdClass; + $data = new DataPacket; $data->pid = $this->getByte(); $data->reliability = ($data->pid & 0b11100000) >> 5; $data->hasSplit = ($data->pid & 0b00010000) > 0; @@ -152,7 +152,7 @@ class RakNetParser{ $data->splitID = $this->getShort(); $data->splitIndex = $this->getInt(); //error! no split packets allowed! - return; + return false; }else{ $data->splitCount = 0; $data->splitID = 0; @@ -162,12 +162,12 @@ class RakNetParser{ if($data->length <= 0 or $this->orderChannel >= 32 or ($hasSplit === 1 and $splitIndex >= $splitCount)){ - return; + return false; } $data->id = $this->getByte(); - $data->payload = $this->get($len - 1); - + $data->raw = $this->get($len - 1); + return $data; } } \ No newline at end of file