get() public method

public get ( $build = false )
Exemplo n.º 1
0
 public function __construct(Server $server, $type, $playerList = [])
 {
     $endpoint = "http://" . $server->getProperty("anonymous-statistics.host", "stats.pocketmine.net") . "/";
     $data = [];
     $data["uniqueServerId"] = $server->getServerUniqueId()->toString();
     $data["uniqueMachineId"] = Utils::getMachineUniqueId()->toString();
     $data["uniqueRequestId"] = UUID::fromData($server->getServerUniqueId(), microtime(true))->toString();
     switch ($type) {
         case self::TYPE_OPEN:
             $data["event"] = "open";
             $version = new VersionString();
             $data["server"] = ["port" => $server->getPort(), "software" => $server->getName(), "fullVersion" => $version->get(true), "version" => $version->get(), "build" => $version->getBuild(), "api" => $server->getApiVersion(), "minecraftVersion" => $server->getVersion(), "protocol" => Info::CURRENT_PROTOCOL];
             $data["system"] = ["operatingSystem" => Utils::getOS(), "cores" => Utils::getCoreCount(), "phpVersion" => PHP_VERSION, "machine" => php_uname("a"), "release" => php_uname("r"), "platform" => php_uname("i")];
             $data["players"] = ["count" => 0, "limit" => $server->getMaxPlayers()];
             $plugins = [];
             foreach ($server->getPluginManager()->getPlugins() as $p) {
                 $d = $p->getDescription();
                 $plugins[$d->getName()] = ["name" => $d->getName(), "version" => $d->getVersion(), "enabled" => $p->isEnabled()];
             }
             $data["plugins"] = $plugins;
             break;
         case self::TYPE_STATUS:
             $data["event"] = "status";
             $data["server"] = ["ticksPerSecond" => $server->getTicksPerSecondAverage(), "tickUsage" => $server->getTickUsageAverage(), "ticks" => $server->getTick()];
             //This anonymizes the user ids so they cannot be reversed to the original
             foreach ($playerList as $k => $v) {
                 $playerList[$k] = md5($v);
             }
             $players = [];
             foreach ($server->getOnlinePlayers() as $p) {
                 if ($p->isOnline()) {
                     $players[] = md5($p->getUniqueId()->toBinary());
                 }
             }
             $data["players"] = ["count" => count($players), "limit" => $server->getMaxPlayers(), "currentList" => $players, "historyList" => array_values($playerList)];
             $info = Utils::getMemoryUsage(true);
             $data["system"] = ["mainMemory" => $info[0], "totalMemory" => $info[1], "availableMemory" => $info[2], "threadCount" => Utils::getThreadCount()];
             break;
         case self::TYPE_CLOSE:
             $data["event"] = "close";
             $data["crashing"] = $server->isRunning();
             break;
     }
     $this->endpoint = $endpoint . "api/post";
     $this->data = json_encode($data);
 }
Exemplo n.º 2
0
 protected function checkUpdate()
 {
     if ($this->updateInfo === \null) {
         return;
     }
     $currentVersion = new VersionString($this->server->getPocketMineVersion());
     $newVersion = new VersionString($this->updateInfo["version"]);
     if ($currentVersion->compare($newVersion) > 0 and ($currentVersion->get() !== $newVersion->get() or $currentVersion->getBuild() > 0)) {
         $this->hasUpdate = \true;
     } else {
         $this->hasUpdate = \false;
     }
 }
Exemplo n.º 3
0
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     $fcmd = strtolower($cmd->getName());
     switch ($fcmd) {
         case "update":
             if ($sender->hasPermission("autoupdater.update")) {
                 $query = $this->plugin->getQuery($this->plugin->getChannel());
                 $version = new VersionString();
                 //Checking query
                 if (isset($query["version"]) && isset($query["api_version"]) && isset($query["build"]) && isset($query["date"]) && isset($query["details_url"]) && isset($query["download_url"])) {
                     //Checking Build
                     if ($version->getBuild() < $query["build"]) {
                         $filename = $this->plugin->getFileName();
                         $sender->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&aUpdating PocketMine..."));
                         $sender->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&eDetails: PocketMine " . $version->get() . " (Build #" . $query["build"] . ") API " . $query["api_version"] . " was released on " . date("d/m/Y h:i:s", $query["date"])));
                         $this->plugin->getServer()->getScheduler()->scheduleAsyncTask(new Downloader($query["download_url"], $this->plugin->getDataFolder() . "/" . $filename));
                         //Do Timeout
                         sleep($this->plugin->getTimeout());
                         //Checking status
                         if (file_exists($this->plugin->getDataFolder() . "/" . $filename)) {
                             $sender->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&aPocketMine updated. Restarting server now..."));
                             $this->plugin->getServer()->forceShutdown();
                             sleep(1);
                             copy($this->plugin->getDataFolder() . "/" . $filename, $this->plugin->getServer()->getDataPath() . "/" . $filename);
                             unlink($this->plugin->getDataFolder() . "/" . $filename);
                             shell_exec($this->plugin->getStartScript());
                         } else {
                             $sender->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&cCan't update PocketMine, an error has occurred"));
                         }
                     } else {
                         $sender->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&aYour PocketMine version is already up to date."));
                     }
                 } else {
                     $sender->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&cCan't update PocketMine, an error has occurred"));
                 }
             } else {
                 $sender->sendMessage($this->plugin->translateColors("&", "&cYou don't have permissions to use this command"));
                 break;
             }
     }
 }
Exemplo n.º 4
0
 public function onRun($currentTick)
 {
     $this->plugin = $this->getOwner();
     $this->cfg = $this->plugin->getConfig()->getAll();
     $query = $this->plugin->getQuery($this->plugin->getChannel());
     $version = new VersionString();
     $server = Server::getInstance();
     $logger = $server->getLogger();
     //Checking query
     if (isset($query["version"]) && isset($query["api_version"]) && isset($query["build"]) && isset($query["date"]) && isset($query["details_url"]) && isset($query["download_url"])) {
         //Checking Build
         if ($version->getBuild() < $query["build"]) {
             $filename = $this->plugin->getFileName();
             $logger->info($this->plugin->translateColors("&", Main::PREFIX . "&aA new PocketMine update is available!"));
             $logger->info($this->plugin->translateColors("&", Main::PREFIX . "&eDetails: PocketMine " . $version->get() . " (Build #" . $query["build"] . ") API " . $query["api_version"] . " was released on " . date("d/m/Y h:i:s", $query["date"])));
             $logger->info($this->plugin->translateColors("&", Main::PREFIX . "&eDownload URL: " . $query["download_url"]));
             //Check auto-update
             if ($this->cfg["auto-update"] == true) {
                 $logger->info($this->plugin->translateColors("&", Main::PREFIX . "&aUpdating PocketMine..."));
                 $this->plugin->getServer()->getScheduler()->scheduleAsyncTask(new Downloader($query["download_url"], $this->plugin->getDataFolder() . "/" . $filename));
                 //Do Timeout
                 sleep($this->plugin->getTimeout());
                 //Checking status
                 if (file_exists($this->plugin->getDataFolder() . "/" . $filename)) {
                     $logger->info($this->plugin->translateColors("&", Main::PREFIX . "&aPocketMine updated. Restarting server now..."));
                     $this->plugin->getServer()->forceShutdown();
                     sleep(1);
                     copy($this->plugin->getDataFolder() . "/" . $this->plugin->getFileName(), $this->plugin->getServer()->getDataPath() . "/" . $filename);
                     unlink($this->plugin->getDataFolder() . "/" . $filename);
                     shell_exec($this->plugin->getStartScript());
                 } else {
                     $logger->info($this->plugin->translateColors("&", Main::PREFIX . "&cCan't update PocketMine, an error has occurred"));
                 }
             }
         }
     } else {
         $logger->info($this->plugin->translateColors("&", Main::PREFIX . "&cCan't update PocketMine, an error has occurred"));
     }
 }
Exemplo n.º 5
0
 /**
  * @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($dataPath . "CrashDump/")) {
         mkdir($dataPath . "CrashDump/", 0777);
     }
     if (!file_exists($pluginPath)) {
         mkdir($pluginPath, 0777);
     }
     $this->dataPath = realpath($dataPath) . DIRECTORY_SEPARATOR;
     $this->pluginPath = realpath($pluginPath) . DIRECTORY_SEPARATOR;
     $this->console = new CommandReader();
     $version = new VersionString($this->getPocketMineVersion());
     $this->logger->info(TextFormat::GREEN . "  ____            _        _   __  __ _                     " . TextFormat::AQUA . " _____ _ _ _       ");
     $this->logger->info(TextFormat::GREEN . " |  _ \\ ___   ___| | _____| |_|  \\/  (_)_ __   ___          " . TextFormat::AQUA . "| ____| (_) |_ ___ ");
     $this->logger->info(TextFormat::GREEN . " | |_) / _ \\ / __| |/ / _ \\ __| |\\/| | | '_ \\ / _ \\  _____  " . TextFormat::AQUA . "|  _| | | | __/ _ \\ ");
     $this->logger->info(TextFormat::GREEN . " |  __/ (_) | (__|   <  __/ |_| |  | | | | | |  __/ |_____| " . TextFormat::AQUA . "| |___| | | ||  __/");
     $this->logger->info(TextFormat::GREEN . " |_|   \\___/ \\___|_|\\_\\___|\\__|_|  |_|_|_| |_|\\___|         " . TextFormat::AQUA . "|_____|_|_|\\__\\___|");
     $this->logger->info(TextFormat::GREEN . "                               Version: " . TextFormat::AQUA . $version);
     $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, "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]);
     $this->forceLanguage = $this->getProperty("settings.force-language", false);
     $this->baseLang = new BaseLang($this->getProperty("settings.language", BaseLang::FALLBACK_LANGUAGE));
     $this->logger->info($this->getLanguage()->translateString("language.selected", [$this->getLanguage()->getName(), $this->getLanguage()->getLang()]));
     $this->memoryManager = new MemoryManager($this);
     $this->logger->info($this->getLanguage()->translateString("pocketmine.server.start", [TextFormat::AQUA . $this->getVersion()]));
     if (($poolSize = $this->getProperty("settings.async-workers", "auto")) === "auto") {
         $poolSize = ServerScheduler::$WORKERS;
         $processors = Utils::getCoreCount() - 2;
         if ($processors > 0) {
             $poolSize = max(1, $processors);
         }
     }
     ServerScheduler::$WORKERS = $poolSize;
     if ($this->getProperty("network.batch-threshold", 256) >= 0) {
         Network::$BATCH_THRESHOLD = (int) $this->getProperty("network.batch-threshold", 256);
     } else {
         Network::$BATCH_THRESHOLD = -1;
     }
     $this->networkCompressionLevel = $this->getProperty("network.compression-level", 7);
     $this->networkCompressionAsync = $this->getProperty("network.async-compression", true);
     $this->autoTickRate = (bool) $this->getProperty("level-settings.auto-tick-rate", true);
     $this->autoTickRateLimit = (int) $this->getProperty("level-settings.auto-tick-rate-limit", 20);
     $this->alwaysTickPlayers = (int) $this->getProperty("level-settings.always-tick-players", false);
     $this->baseTickRate = (int) $this->getProperty("level-settings.base-tick-rate", 1);
     $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 ($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);
     }
     if (\pocketmine\DEBUG >= 0) {
         @cli_set_process_title($this->getName() . " " . $this->getPocketMineVersion());
     }
     $this->logger->info($this->getLanguage()->translateString("pocketmine.server.networkStart", [$this->getIp() === "" ? "*" : $this->getIp(), $this->getPort()]));
     define("BOOTUP_RANDOM", @Utils::getRandomBytes(16));
     $this->serverID = Utils::getMachineUniqueId($this->getIp() . $this->getPort());
     $this->getLogger()->debug("Server unique id: " . $this->getServerUniqueId());
     $this->getLogger()->debug("Machine unique id: " . Utils::getMachineUniqueId());
     $this->network = new Network($this);
     $this->network->setName($this->getMotd());
     $this->logger->info($this->getLanguage()->translateString("pocketmine.server.info", [$this->getName(), ($version->isDev() ? TextFormat::YELLOW : "") . $version->get(true) . TextFormat::WHITE, $this->getCodename(), $this->getApiVersion()]));
     $this->logger->info($this->getLanguage()->translateString("pocketmine.server.license", [$this->getName()]));
     Timings::init();
     $this->consoleSender = new ConsoleCommandSender();
     $this->commandMap = new SimpleCommandMap($this);
     $this->registerEntities();
     $this->registerTiles();
     InventoryType::init();
     Block::init();
     Item::init();
     Biome::init();
     Effect::init();
     Enchantment::init();
     Attribute::init();
     /** TODO: @deprecated */
     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->profilingTickRate = (double) $this->getProperty("settings.profile-report-trigger", 20);
     $this->pluginManager->registerInterface(PharPluginLoader::class);
     $this->pluginManager->registerInterface(ScriptPluginLoader::class);
     set_exception_handler([$this, "exceptionHandler"]);
     register_shutdown_function([$this, "crashDump"]);
     $this->queryRegenerateTask = new QueryRegenerateEvent($this, 5);
     $this->network->registerInterface(new RakLibInterface($this));
     $this->pluginManager->loadPlugins($this->pluginPath);
     $this->updater = new AutoUpdater($this, $this->getProperty("auto-updater.host", "www.pocketmine.net"));
     $this->enablePlugins(PluginLoadOrder::STARTUP);
     LevelProviderManager::addProvider($this, Anvil::class);
     LevelProviderManager::addProvider($this, McRegion::class);
     if (extension_loaded("leveldb")) {
         $this->logger->debug($this->getLanguage()->translateString("pocketmine.debug.enable"));
         LevelProviderManager::addProvider($this, LevelDB::class);
     }
     Generator::addGenerator(Flat::class, "flat");
     Generator::addGenerator(Normal::class, "normal");
     Generator::addGenerator(Normal::class, "default");
     Generator::addGenerator(Nether::class, "hell");
     Generator::addGenerator(Nether::class, "nether");
     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(true);
     if (!$this->getDefaultLevel() instanceof Level) {
         $this->getLogger()->emergency($this->getLanguage()->translateString("pocketmine.level.defaultError"));
         $this->forceShutdown();
         return;
     }
     if ($this->getProperty("ticks-per.autosave", 6000) > 0) {
         $this->autoSaveTicks = (int) $this->getProperty("ticks-per.autosave", 6000);
     }
     $this->enablePlugins(PluginLoadOrder::POSTWORLD);
     $this->start();
 }
Exemplo n.º 6
0
 private function generalData()
 {
     $version = new VersionString();
     $this->data["general"] = [];
     $this->data["general"]["version"] = $version->get(false);
     $this->data["general"]["build"] = $version->getBuild();
     $this->data["general"]["protocol"] = Info::CURRENT_PROTOCOL;
     $this->data["general"]["api"] = \pocketmine\API_VERSION;
     $this->data["general"]["git"] = \pocketmine\GIT_COMMIT;
     $this->data["general"]["raklib"] = RakLib::VERSION;
     $this->data["general"]["uname"] = php_uname("a");
     $this->data["general"]["php"] = phpversion();
     $this->data["general"]["zend"] = zend_version();
     $this->data["general"]["php_os"] = PHP_OS;
     $this->data["general"]["os"] = Utils::getOS();
     $this->addLine("ImagicalMine version: " . $version->get(false) . " #" . $version->getBuild() . " [Protocol " . Info::CURRENT_PROTOCOL . "; API " . API_VERSION . "]");
     $this->addLine("Git commit: " . GIT_COMMIT);
     $this->addLine("uname -a: " . php_uname("a"));
     $this->addLine("PHP Version: " . phpversion());
     $this->addLine("Zend version: " . zend_version());
     $this->addLine("OS : " . PHP_OS . ", " . Utils::getOS());
 }
Exemplo n.º 7
0
 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("http://stats.pocketmine.net/usage.php", ["serverid" => 0, "port" => $this->getPort(), "os" => Utils::getOS(), "name" => $this->getName(), "memory_total" => $this->getConfigString("memory-limit"), "memory_usage" => memory_get_usage(), "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);
 }
 private function generalData()
 {
     $version = new VersionString();
     $this->data["general"] = [];
     $this->data["general"]["version"] = $version->get(false);
     $this->data["general"]["build"] = $version->getBuild();
     $this->data["general"]["protocol"] = Info::CURRENT_PROTOCOL;
     $this->data["general"]["api"] = \pocketmine\API_VERSION;
     $this->data["general"]["git"] = \pocketmine\GIT_COMMIT;
     $this->data["general"]["raklib"] = RakLib::VERSION;
     $this->data["general"]["uname"] = php_uname("a");
     $this->data["general"]["php"] = phpversion();
     $this->data["general"]["zend"] = zend_version();
     $this->data["general"]["php_os"] = PHP_OS;
     $this->data["general"]["os"] = Utils::getOS();
     $this->addLine("Genisys version: " . $version->get(false) . " #" . $version->getBuild() . " [Protocol " . Info::CURRENT_PROTOCOL . "; API " . API_VERSION . "]");
     $this->addLine("uname -a: " . php_uname("a"));
     $this->addLine("PHP version: " . phpversion());
     $this->addLine("Zend version: " . zend_version());
     $this->addLine("OS : " . PHP_OS . ", " . Utils::getOS());
     $this->addLine();
     $this->addLine("Server uptime: " . $this->server->getUptime());
     $this->addLine("Number of loaded worlds: " . count($this->server->getLevels()));
     $this->addLine("Players online: " . count($this->server->getOnlinePlayers()) . "/" . $this->server->getMaxPlayers());
 }