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; } }
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); }
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; } } }
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")); } }
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()); }
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()); }