public function decode() { $this->eid = Binary::readLong($this->get(8)); $this->x = \unpack("N", $this->get(4))[1]; $this->z = \unpack("N", $this->get(4))[1]; $this->y = \ord($this->get(1)); }
public function decode() { $this->eid = Binary::readLong($this->get(8)); $this->x = \PHP_INT_SIZE === 8 ? \unpack("N", $this->get(4))[1] << 32 >> 32 : \unpack("N", $this->get(4))[1]; $this->z = \PHP_INT_SIZE === 8 ? \unpack("N", $this->get(4))[1] << 32 >> 32 : \unpack("N", $this->get(4))[1]; $this->y = \ord($this->get(1)); }
public function decode() { $this->eid = Binary::readLong($this->get(8)); $this->item = $this->getSlot(); $this->slot = \ord($this->get(1)); $this->selectedSlot = \ord($this->get(1)); }
public function onPkt(DataPacketReceiveEvent $e) { if ($e->getPacket()->pid() !== 0x0) { return; } $this->lastPing[strtolower($e->getPlayer()->getName())] = Binary::readLong($e->getPacket()->buffer) / 1000.0; }
public function decode() { Binary::readLong($this->get(8)); //TODO: remove $this->x = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1]; $this->y = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1]; $this->z = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1]; }
public function decode() { $this->eid = Binary::readLong($this->get(8)); $this->item = \unpack("n", $this->get(2))[1]; $this->meta = \unpack("n", $this->get(2))[1]; $this->slot = \ord($this->get(1)); $this->selectedSlot = \ord($this->get(1)); }
public function decode() { $this->eid = Binary::readLong($this->get(8)); $this->slots[0] = $this->getSlot(); $this->slots[1] = $this->getSlot(); $this->slots[2] = $this->getSlot(); $this->slots[3] = $this->getSlot(); }
public function __construct(DynamicHub $hub) { $this->hub = $hub; $this->dir = $hub->getDataFolder() . "data/json/"; $this->playerDir = $this->dir . "players/"; $this->nextIdFile = $this->dir . "nextId.txt"; $this->nextId = is_file($this->dir) ? Binary::readLong(file_get_contents($this->dir . $this->nextIdFile)) : 0; }
public function decode() { $this->eid = Binary::readLong($this->get(8)); $this->action = \unpack("N", $this->get(4))[1] << 32 >> 32; $this->x = \unpack("N", $this->get(4))[1] << 32 >> 32; $this->y = \unpack("N", $this->get(4))[1] << 32 >> 32; $this->z = \unpack("N", $this->get(4))[1] << 32 >> 32; $this->face = \unpack("N", $this->get(4))[1] << 32 >> 32; }
public function decode() { $this->eid = Binary::readLong($this->get(8)); $this->x = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1]; $this->y = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1]; $this->z = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1]; $this->yaw = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1]; $this->bodyYaw = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1]; $this->pitch = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1]; $this->mode = \ord($this->get(1)); }
public function decode() { $this->username = $this->getString(); $this->protocol1 = \PHP_INT_SIZE === 8 ? \unpack("N", $this->get(4))[1] << 32 >> 32 : \unpack("N", $this->get(4))[1]; $this->protocol2 = \PHP_INT_SIZE === 8 ? \unpack("N", $this->get(4))[1] << 32 >> 32 : \unpack("N", $this->get(4))[1]; $this->clientId = Binary::readLong($this->get(8)); $this->clientUUID = $this->getUUID(); $this->serverAddress = $this->getString(); $this->clientSecret = $this->getString(); $this->slim = $this->getByte() > 0; $this->isTransparent = $this->getByte() > 0; $this->skin = $this->getString(); }
public function decode() { $this->x = \PHP_INT_SIZE === 8 ? \unpack("N", $this->get(4))[1] << 32 >> 32 : \unpack("N", $this->get(4))[1]; $this->y = \PHP_INT_SIZE === 8 ? \unpack("N", $this->get(4))[1] << 32 >> 32 : \unpack("N", $this->get(4))[1]; $this->z = \PHP_INT_SIZE === 8 ? \unpack("N", $this->get(4))[1] << 32 >> 32 : \unpack("N", $this->get(4))[1]; $this->face = \ord($this->get(1)); $this->item = \unpack("n", $this->get(2))[1]; $this->meta = \unpack("n", $this->get(2))[1]; $this->eid = Binary::readLong($this->get(8)); $this->fx = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1]; $this->fy = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1]; $this->fz = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1]; $this->posX = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1]; $this->posY = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1]; $this->posZ = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1]; }
public function decode() { $this->username = $this->getString(); $this->protocol1 = \unpack("N", $this->get(4))[1] << 32 >> 32; $this->protocol2 = \unpack("N", $this->get(4))[1] << 32 >> 32; if ($this->protocol1 < Info::CURRENT_PROTOCOL) { //New fields! $this->setBuffer(\null, 0); //Skip batch packet handling return; } $this->clientId = Binary::readLong($this->get(8)); $this->clientUUID = $this->getUUID(); $this->serverAddress = $this->getString(); $this->clientSecret = $this->getString(); $this->slim = \ord($this->get(1)) > 0; $this->skin = $this->getString(); }
public function decode() { $this->username = $this->getString(); $this->protocol1 = \PHP_INT_SIZE === 8 ? \unpack("N", $this->get(4))[1] << 32 >> 32 : \unpack("N", $this->get(4))[1]; $this->protocol2 = \PHP_INT_SIZE === 8 ? \unpack("N", $this->get(4))[1] << 32 >> 32 : \unpack("N", $this->get(4))[1]; if ($this->protocol1 < Info::CURRENT_PROTOCOL) { //New fields! $this->setBuffer(\null, 0); //Skip batch packet handling return; } $this->clientId = Binary::readLong($this->get(8)); $this->clientUUID = $this->getUUID(); $this->serverAddress = $this->getString(); $this->clientSecret = $this->getString(); $this->getByte(); //extra byte being sent, not sure what it's for yet $this->slim = \ord($this->get(1)) > 0; $this->skin = $this->getString(); }
public function decode() { $this->eid = Binary::readLong($this->get(8)); $this->unknown = \ord($this->get(1)); $this->item = $this->getSlot(); }
public function getLong() { return Binary::readLong($this->get(8)); }
/** * @param \ClassLoader $autoloader * @param \ThreadedLogger $logger * @param string $filePath * @param string $dataPath * @param string $pluginPath */ public function __construct(\ClassLoader $autoloader, \ThreadedLogger $logger, $filePath, $dataPath, $pluginPath) { self::$instance = $this; $this->autoloader = $autoloader; $this->logger = $logger; $this->filePath = $filePath; if (!file_exists($dataPath . "worlds/")) { mkdir($dataPath . "worlds/", 0777); } if (!file_exists($dataPath . "players/")) { mkdir($dataPath . "players/", 0777); } if (!file_exists($pluginPath)) { mkdir($pluginPath, 0777); } $this->dataPath = realpath($dataPath) . DIRECTORY_SEPARATOR; $this->pluginPath = realpath($pluginPath) . DIRECTORY_SEPARATOR; $this->consoleThreaded = new \Threaded(); $this->console = new CommandReader($this->consoleThreaded); $version = new VersionString($this->getPocketMineVersion()); $this->logger->info("Starting Minecraft: PE server version " . TextFormat::AQUA . $this->getVersion()); $this->logger->info("Loading pocketmine.yml..."); if (!file_exists($this->dataPath . "pocketmine.yml")) { $content = file_get_contents($this->filePath . "src/pocketmine/resources/pocketmine.yml"); if ($version->isDev()) { $content = str_replace("preferred-channel: stable", "preferred-channel: beta", $content); } @file_put_contents($this->dataPath . "pocketmine.yml", $content); } $this->config = new Config($this->dataPath . "pocketmine.yml", Config::YAML, []); $this->logger->info("Loading server properties..."); $this->properties = new Config($this->dataPath . "server.properties", Config::PROPERTIES, ["motd" => "Minecraft: PE Server", "server-port" => 19132, "memory-limit" => "256M", "white-list" => false, "announce-player-achievements" => true, "spawn-protection" => 16, "max-players" => 20, "allow-flight" => false, "spawn-animals" => true, "spawn-mobs" => true, "gamemode" => 0, "force-gamemode" => false, "hardcore" => false, "pvp" => true, "difficulty" => 1, "generator-settings" => "", "level-name" => "world", "level-seed" => "", "level-type" => "DEFAULT", "enable-query" => true, "enable-rcon" => false, "rcon.password" => substr(base64_encode(@Utils::getRandomBytes(20, false)), 3, 10), "auto-save" => true]); ServerScheduler::$WORKERS = $this->getProperty("settings.async-workers", ServerScheduler::$WORKERS); $this->scheduler = new ServerScheduler(); if ($this->getConfigBoolean("enable-rcon", false) === true) { $this->rcon = new RCON($this, $this->getConfigString("rcon.password", ""), $this->getConfigInt("rcon.port", $this->getPort()), ($ip = $this->getIp()) != "" ? $ip : "0.0.0.0", $this->getConfigInt("rcon.threads", 1), $this->getConfigInt("rcon.clients-per-thread", 50)); } $this->entityMetadata = new EntityMetadataStore(); $this->playerMetadata = new PlayerMetadataStore(); $this->levelMetadata = new LevelMetadataStore(); $this->operators = new Config($this->dataPath . "ops.txt", Config::ENUM); $this->whitelist = new Config($this->dataPath . "white-list.txt", Config::ENUM); if (file_exists($this->dataPath . "banned.txt") and !file_exists($this->dataPath . "banned-players.txt")) { @rename($this->dataPath . "banned.txt", $this->dataPath . "banned-players.txt"); } @touch($this->dataPath . "banned-players.txt"); $this->banByName = new BanList($this->dataPath . "banned-players.txt"); $this->banByName->load(); @touch($this->dataPath . "banned-ips.txt"); $this->banByIP = new BanList($this->dataPath . "banned-ips.txt"); $this->banByIP->load(); $this->maxPlayers = $this->getConfigInt("max-players", 20); $this->setAutoSave($this->getConfigBoolean("auto-save", true)); if (($memory = str_replace("B", "", strtoupper($this->getConfigString("memory-limit", "256M")))) !== false) { $value = ["M" => 1, "G" => 1024]; $real = (int) substr($memory, 0, -1) * $value[substr($memory, -1)]; if ($real < 128) { $this->logger->warning($this->getName() . " may not work right with less than 128MB of RAM", true, true, 0); } @ini_set("memory_limit", $memory); } else { $this->setConfigString("memory-limit", "256M"); } if ($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3) { $this->setConfigInt("difficulty", 3); } define("pocketmine\\DEBUG", (int) $this->getProperty("debug.level", 1)); if ($this->logger instanceof MainLogger) { $this->logger->setLogDebug(\pocketmine\DEBUG > 1); } define("ADVANCED_CACHE", $this->getProperty("settings.advanced-cache", false)); if (ADVANCED_CACHE == true) { $this->logger->info("Advanced cache enabled"); } Level::$COMPRESSION_LEVEL = $this->getProperty("chunk-sending.compression-level", 8); if (defined("pocketmine\\DEBUG") and \pocketmine\DEBUG >= 0) { @cli_set_process_title($this->getName() . " " . $this->getPocketMineVersion()); } $this->logger->info("Starting Minecraft PE server on " . ($this->getIp() === "" ? "*" : $this->getIp()) . ":" . $this->getPort()); define("BOOTUP_RANDOM", @Utils::getRandomBytes(16)); $this->serverID = Binary::readLong(substr(Utils::getUniqueID(true, $this->getIp() . $this->getPort()), 0, 8)); $this->addInterface($this->mainInterface = new RakLibInterface($this)); $this->logger->info("This server is running " . $this->getName() . " version " . ($version->isDev() ? TextFormat::YELLOW : "") . $version->get(true) . TextFormat::WHITE . " \"" . $this->getCodename() . "\" (API " . $this->getApiVersion() . ")"); $this->logger->info($this->getName() . " is distributed under the LGPL License"); PluginManager::$pluginParentTimer = new TimingsHandler("** Plugins"); Timings::init(); $this->consoleSender = new ConsoleCommandSender(); $this->commandMap = new SimpleCommandMap($this); $this->registerEntities(); $this->registerTiles(); InventoryType::init(); Block::init(); Item::init(); TextWrapper::init(); $this->craftingManager = new CraftingManager(); $this->pluginManager = new PluginManager($this, $this->commandMap); $this->pluginManager->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender); $this->pluginManager->setUseTimings($this->getProperty("settings.enable-profiling", false)); $this->pluginManager->registerInterface(PharPluginLoader::class); set_exception_handler([$this, "exceptionHandler"]); register_shutdown_function([$this, "crashDump"]); $this->pluginManager->loadPlugins($this->pluginPath); $this->updater = new AutoUpdater($this, $this->getProperty("auto-updater.host", "www.pocketmine.net")); $this->enablePlugins(PluginLoadOrder::STARTUP); if ($this->getProperty("chunk-generation.use-async", true)) { $this->generationManager = new GenerationRequestManager($this); } else { $this->generationManager = new GenerationInstanceManager($this); } LevelProviderManager::addProvider($this, Anvil::class); LevelProviderManager::addProvider($this, McRegion::class); if (extension_loaded("leveldb")) { $this->logger->debug("Enabling LevelDB support"); LevelProviderManager::addProvider($this, LevelDB::class); } Generator::addGenerator(Flat::class, "flat"); Generator::addGenerator(Normal::class, "normal"); Generator::addGenerator(Normal::class, "default"); foreach ((array) $this->getProperty("worlds", []) as $name => $worldSetting) { if ($this->loadLevel($name) === false) { $seed = $this->getProperty("worlds.{$name}.seed", time()); $options = explode(":", $this->getProperty("worlds.{$name}.generator", Generator::getGenerator("default"))); $generator = Generator::getGenerator(array_shift($options)); if (count($options) > 0) { $options = ["preset" => implode(":", $options)]; } else { $options = []; } $this->generateLevel($name, $seed, $generator, $options); } } if ($this->getDefaultLevel() === null) { $default = $this->getConfigString("level-name", "world"); if (trim($default) == "") { $this->getLogger()->warning("level-name cannot be null, using default"); $default = "world"; $this->setConfigString("level-name", "world"); } if ($this->loadLevel($default) === false) { $seed = $this->getConfigInt("level-seed", time()); $this->generateLevel($default, $seed === 0 ? time() : $seed); } $this->setDefaultLevel($this->getLevelByName($default)); } $this->properties->save(); if (!$this->getDefaultLevel() instanceof Level) { $this->getLogger()->emergency("No default level has been loaded"); $this->forceShutdown(); return; } $this->scheduler->scheduleDelayedRepeatingTask(new CallbackTask([Cache::class, "cleanup"]), $this->getProperty("ticks-per.cache-cleanup", 900), $this->getProperty("ticks-per.cache-cleanup", 900)); if ($this->getAutoSave() and $this->getProperty("ticks-per.autosave", 6000) > 0) { $this->scheduler->scheduleDelayedRepeatingTask(new CallbackTask([$this, "doAutoSave"]), $this->getProperty("ticks-per.autosave", 6000), $this->getProperty("ticks-per.autosave", 6000)); } if ($this->getProperty("chunk-gc.period-in-ticks", 600) > 0) { $this->scheduler->scheduleDelayedRepeatingTask(new CallbackTask([$this, "doLevelGC"]), $this->getProperty("chunk-gc.period-in-ticks", 600), $this->getProperty("chunk-gc.period-in-ticks", 600)); } $this->scheduler->scheduleRepeatingTask(new GarbageCollectionTask(), 900); $this->enablePlugins(PluginLoadOrder::POSTWORLD); $this->start(); }
public function read(NBT $nbt) { $this->value = $nbt->endianness === 1 ? Binary::readLong($nbt->get(8)) : Binary::readLLong($nbt->get(8)); }
public function decode() { $this->action = \ord($this->get(1)); $this->eid = Binary::readLong($this->get(8)); }
public function readLong($signed = true) { return Binary::readLong($this->read(8), $signed); }
public function getLong() { return $this->endianness === self::BIG_ENDIAN ? Binary::readLong($this->get(8)) : Binary::readLLong($this->get(8)); }
public function sendUsage() { if ($this->lastSendUsage instanceof SendUsageTask) { if (!$this->lastSendUsage->isGarbage()) { //do not call multiple times return; } } $plist = ""; foreach ($this->getPluginManager()->getPlugins() as $p) { $d = $p->getDescription(); $plist .= str_replace([";", ":"], "", $d->getName()) . ":" . str_replace([";", ":"], "", $d->getVersion()) . ";"; } $version = new VersionString(); $this->lastSendUsage = new SendUsageTask("https://stats.pocketmine.net/usage.php", ["serverid" => Binary::readLong(substr(hex2bin(str_replace("-", "", $this->serverID)), 0, 8)), "port" => $this->getPort(), "os" => Utils::getOS(), "name" => $this->getName(), "memory_total" => $this->getConfigString("memory-limit"), "memory_usage" => Utils::getMemoryUsage(), "php_version" => PHP_VERSION, "version" => $version->get(true), "build" => $version->getBuild(), "mc_version" => \pocketmine\MINECRAFT_VERSION, "protocol" => \pocketmine\network\protocol\Info::CURRENT_PROTOCOL, "online" => count($this->players), "max" => $this->getMaxPlayers(), "plugins" => $plist]); $this->scheduler->scheduleAsyncTask($this->lastSendUsage); }
public static function decompressName($compressed) { $int = substr($compressed, 0, 4); $long = substr($compressed, 4, 8); /** @var int $value */ $value = Binary::readInt($int, false); $value <<= 32; $value += Binary::readLong($long, false); $out = ""; for ($offset = 0; $offset <= 16; $offset++) { $ord = $value & 0b111111; if (0 <= $ord and $ord <= 9) { $chr = chr(ord("0") + $ord); } else { $ord -= 10; if ($ord <= 25) { $chr = chr(ord("a") + $ord); } else { $chr = "_"; } // corrupted databases will lead to a large amount of underscores } $out = $chr . $out; } return $out; }
protected function getLong() { return Binary::readLong($this->get(8)); }