/**
  * @param string $binary
  * @param bool	 $internal
  * @param int		&$offset
  *
  * @return EncapsulatedPacket
  */
 public static function fromBinary($binary, $internal = false, &$offset = null)
 {
     $packet = new EncapsulatedPacket();
     $flags = ord($binary[0]);
     $packet->reliability = $reliability = ($flags & 0b11100000) >> 5;
     $packet->hasSplit = $hasSplit = ($flags & 0b10000) > 0;
     if ($internal) {
         $length = Binary::readInt(substr($binary, 1, 4));
         $packet->identifierACK = Binary::readInt(substr($binary, 5, 4));
         $offset = 9;
     } else {
         $length = (int) ceil(Binary::readShort(substr($binary, 1, 2)) / 8);
         $offset = 3;
         $packet->identifierACK = null;
     }
     /*
      * From http://www.jenkinssoftware.com/raknet/manual/reliabilitytypes.html
      *
      * Default: 0b010 (2) or 0b011 (3)
      *
      * 0: UNRELIABLE
      * 1: UNRELIABLE_SEQUENCED
      * 2: RELIABLE
      * 3: RELIABLE_ORDERED
      * 4: RELIABLE_SEQUENCED
      * 5: UNRELIABLE_WITH_ACK_RECEIPT
      * 6: RELIABLE_WITH_ACK_RECEIPT
      * 7: RELIABLE_ORDERED_WITH_ACK_RECEIPT
      */
     if ($reliability > 0) {
         if ($reliability >= 2 and $reliability !== 5) {
             $packet->messageIndex = Binary::readLTriad(substr($binary, $offset, 3));
             $offset += 3;
         }
         if ($reliability <= 4 and $reliability !== 2) {
             $packet->orderIndex = Binary::readLTriad(substr($binary, $offset, 3));
             $offset += 3;
             $packet->orderChannel = ord($binary[$offset++]);
         }
     }
     if ($hasSplit) {
         $packet->splitCount = Binary::readInt(substr($binary, $offset, 4));
         $offset += 4;
         $packet->splitID = Binary::readShort(substr($binary, $offset, 2));
         $offset += 2;
         $packet->splitIndex = Binary::readInt(substr($binary, $offset, 4));
         $offset += 4;
     }
     $packet->buffer = substr($binary, $offset, $length);
     $offset += $length;
     return $packet;
 }
Esempio n. 2
0
 public function getShort()
 {
     return Binary::readShort($this->get(2));
 }
Esempio n. 3
0
 public function getShort($signed = true)
 {
     return $signed ? Binary::readSignedShort($this->get(2)) : Binary::readShort($this->get(2));
 }