protected function readPacket() { if (strlen($packet = $this->thread->readMainToThreadPacket()) > 0) { $pid = ord($packet[0]); $offset = 1; if ($pid === self::PACKET_REQUEST_CHUNK) { $levelID = Binary::readInt(substr($packet, $offset, 4)); $offset += 4; $chunkX = Binary::readInt(substr($packet, $offset, 4)); $offset += 4; $chunkZ = Binary::readInt(substr($packet, $offset, 4)); $this->enqueueChunk($levelID, $chunkX, $chunkZ); } elseif ($pid === self::PACKET_SEND_CHUNK) { $levelID = Binary::readInt(substr($packet, $offset, 4)); $offset += 4; $len = ord($packet[$offset++]); /** @var FullChunk $class */ $class = substr($packet, $offset, $len); $offset += $len; $chunk = $class::fromBinary(substr($packet, $offset)); $this->receiveChunk($levelID, $chunk); } elseif ($pid === self::PACKET_OPEN_LEVEL) { $levelID = Binary::readInt(substr($packet, $offset, 4)); $offset += 4; $seed = Binary::readInt(substr($packet, $offset, 4)); $offset += 4; $len = Binary::readShort(substr($packet, $offset, 2)); $offset += 2; $class = substr($packet, $offset, $len); $offset += $len; $options = unserialize(substr($packet, $offset)); $this->openLevel($levelID, $seed, $class, $options); } elseif ($pid === self::PACKET_CLOSE_LEVEL) { $levelID = Binary::readInt(substr($packet, $offset, 4)); $this->closeLevel($levelID); } elseif ($pid === self::PACKET_ADD_NAMESPACE) { $len = Binary::readShort(substr($packet, $offset, 2)); $offset += 2; $namespace = substr($packet, $offset, $len); $offset += $len; $path = substr($packet, $offset); $this->loader->addPath($path); } elseif ($pid === self::PACKET_SHUTDOWN) { foreach ($this->levels as $level) { $level->shutdown(); } $this->levels = []; $this->shutdown = true; } } elseif (count($this->thread->getInternalQueue()) === 0) { $this->thread->synchronized(function () { $this->thread->wait(50000); }); } }
public function getShort() { return Binary::readShort($this->get(2)); }
public function readShort($signed = true) { return Binary::readShort($this->read(2), $signed); }
public function getShort() { return $this->endianness === self::BIG_ENDIAN ? Binary::readShort($this->get(2)) : Binary::readLShort($this->get(2)); }
private function upgrade_From0_To1() { MainLogger::getLogger()->notice("Old PMF Level format version #0 detected, upgrading to version #1"); for ($index = 0; $index < 256; ++$index) { $X = $index & 0xf; $Z = $index >> 4; $bitflags = Binary::readShort($this->read(2)); $oldPath = dirname($this->file) . "/chunks/" . $Z . "." . $X . ".pmc"; $chunkOld = gzopen($oldPath, "rb"); $newPath = dirname($this->file) . "/chunks/" . (($X ^ $Z) & 0xff) . "/" . $Z . "." . $X . ".pmc"; @mkdir(dirname($newPath)); $chunkNew = gzopen($newPath, "wb1"); gzwrite($chunkNew, chr($bitflags) . ""); while (gzeof($chunkOld) === false) { gzwrite($chunkNew, gzread($chunkOld, 65535)); } gzclose($chunkNew); gzclose($chunkOld); @unlink($oldPath); } $this->levelData["version"] = 1; $this->levelData["generator"] = "default"; $this->levelData["generatorSettings"] = ""; }
protected function getShort($signed = true) { return $signed ? Binary::readSignedShort($this->get(2)) : Binary::readShort($this->get(2)); }
protected function getShort($signed = true) { return Binary::readShort($this->get(2), $signed); }