From dbbfbdffaafe2c6cda89ab373c6a3c606709fb9a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Feb 2014 00:56:40 +0100 Subject: [PATCH] RakNet data packet codec --- src/Player.php | 3 ++- src/network/raknet/RakNetCodec.php | 34 +++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Player.php b/src/Player.php index 2473c9ba9..93b4a2c09 100644 --- a/src/Player.php +++ b/src/Player.php @@ -2315,7 +2315,8 @@ class Player{ } $packet->messageIndex = $this->counter[3]++; - $this->buffer->data[] .= $packet; + $packet->reliability = 2; + $this->buffer->data[] = $packet; $this->bufferLen += 6 + $len; return array(); } diff --git a/src/network/raknet/RakNetCodec.php b/src/network/raknet/RakNetCodec.php index cad6868ff..758c23231 100644 --- a/src/network/raknet/RakNetCodec.php +++ b/src/network/raknet/RakNetCodec.php @@ -77,7 +77,7 @@ class RakNetCodec{ case RakNetInfo::DATA_PACKET_F: $this->putLTriad($this->seqNumber); foreach($this->data as $pk){ - $this->buffer .= $this->encodeDataPacket($pk); + $this->encodeDataPacket($pk); } break; case RakNetInfo::NACK: @@ -120,6 +120,38 @@ class RakNetCodec{ } } + + private function encodeDataPacket(RakNetDataPacket $pk){ + $this->putByte(($pk->reliability << 5) | ($pk->hasSplit > 0 ? 0b00010000:0)); + $this->putShort((strlen($pk->buffer) + 1) << 3); + if($pk->reliability === 2 + or $pk->reliability === 3 + or $pk->reliability === 4 + or $pk->reliability === 6 + or $pk->reliability === 7){ + $this->putLTriad($pk->messageIndex); + } + + if($pk->reliability === 1 + or $pk->reliability === 3 + or $pk->reliability === 4 + or $pk->reliability === 7){ + $this->putLTriad($pk->orderIndex); + $this->putByte($pk->orderChannel); + } + + if($pk->hasSplit === true){ + $this->putInt($pk->splitCount); + $this->putShort($pk->splitID); + $this->putInt($pk->splitIndex); + if($pk->splitIndex === 0){ + $this->putByte($pk->pid()); + } + }else{ + $this->putByte($pk->pid()); + } + $this->buffer .= $pk->buffer; + } protected function put($str){ $this->buffer .= $str;