readLInt() публичный статический Метод

public static readLInt ( $str )
Пример #1
0
 private function readPacket($client, &$size, &$requestID, &$packetType, &$payload)
 {
     socket_set_nonblock($client);
     $d = socket_read($client, 4);
     if ($this->stop === true) {
         return false;
     } elseif ($d === false) {
         return null;
     } elseif ($d === "" or strlen($d) < 4) {
         return false;
     }
     socket_set_block($client);
     $size = Binary::readLInt($d);
     if ($size < 0 or $size > 65535) {
         return false;
     }
     $requestID = Binary::readLInt(socket_read($client, 4));
     $packetType = Binary::readLInt(socket_read($client, 4));
     $payload = rtrim(socket_read($client, $size + 2));
     //Strip two null bytes
     return true;
 }
Пример #2
0
 public function getLInt()
 {
     return Binary::readLInt($this->get(4));
 }
Пример #3
0
 public function parseChunk($X, $Z)
 {
     $X = (int) $X;
     $Z = (int) $Z;
     $offset = $this->getOffset($X, $Z);
     $len = Binary::readLInt(substr($this->raw, $offset, 4));
     $offset += 4;
     $chunk = [0 => [], 1 => [], 2 => [], 3 => []];
     foreach ($chunk as $section => &$data) {
         $l = $section === 0 ? 128 : 64;
         for ($i = 0; $i < 256; ++$i) {
             $data[$i] = substr($this->raw, $offset, $l);
             $offset += $l;
         }
     }
     return $chunk;
 }
Пример #4
0
 public function getInt()
 {
     return $this->endianness === self::BIG_ENDIAN ? Binary::readInt($this->get(4)) : Binary::readLInt($this->get(4));
 }
Пример #5
0
 /**
  * @param string        $data
  * @param LevelProvider $provider
  *
  * @return Chunk
  */
 public static function fromBinary($data, LevelProvider $provider = null)
 {
     try {
         $chunkX = Binary::readLInt(substr($data, 0, 4));
         $chunkZ = Binary::readLInt(substr($data, 4, 4));
         $chunkData = substr($data, 8, -1);
         $flags = ord(substr($data, -1));
         $entities = null;
         $tiles = null;
         if ($provider instanceof LevelDB) {
             $nbt = new NBT(NBT::LITTLE_ENDIAN);
             $entityData = $provider->getDatabase()->get(substr($data, 0, 8) . "2");
             if ($entityData !== false and strlen($entityData) > 0) {
                 $nbt->read($entityData, true);
                 $entities = $nbt->getData();
                 if (!is_array($entities)) {
                     $entities = [$entities];
                 }
             }
             $tileData = $provider->getDatabase()->get(substr($data, 0, 8) . "1");
             if ($tileData !== false and strlen($tileData) > 0) {
                 $nbt->read($tileData, true);
                 $tiles = $nbt->getData();
                 if (!is_array($tiles)) {
                     $tiles = [$tiles];
                 }
             }
         }
         $chunk = new Chunk($provider instanceof LevelProvider ? $provider : LevelDB::class, $chunkX, $chunkZ, $chunkData, $entities, $tiles);
         if ($flags & 0x1) {
             $chunk->setGenerated();
         }
         if ($flags & 0x2) {
             $chunk->setPopulated();
         }
         return $chunk;
     } catch (\Exception $e) {
         return null;
     }
 }
Пример #6
0
 public function getInt(bool $network = false)
 {
     if ($network === true) {
         return Binary::readVarInt($this);
     }
     return $this->endianness === self::BIG_ENDIAN ? Binary::readInt($this->get(4)) : Binary::readLInt($this->get(4));
 }