public function onRun() { try { Utils::postURL($this->endpoint, $this->data, 5, ["Content-Type: application/json", "Content-Length: " . strlen($this->data)]); } catch (\Exception $e) { } }
public function execute(CommandSender $sender, $currentAlias, array $args) { if (!$this->testPermission($sender)) { return true; } $rUsage = Utils::getRealMemoryUsage(); $mUsage = Utils::getMemoryUsage(true); $server = $sender->getServer(); $sender->sendMessage(TextFormat::GREEN . "---- " . TextFormat::WHITE . "%BukkitPE.command.status.title" . TextFormat::GREEN . " ----"); $sender->sendMessage(TextFormat::GOLD . "%BukkitPE.command.status.player" . TextFormat::GREEN . \count($sender->getServer()->getOnlinePlayers()) . "/" . $sender->getServer()->getMaxPlayers()); $time = microtime(true) - \BukkitPE\START_TIME; $seconds = floor($time % 60); $minutes = null; $hours = null; $days = null; if ($time >= 60) { $minutes = floor($time % 3600 / 60); if ($time >= 3600) { $hours = floor($time % (3600 * 24) / 3600); if ($time >= 3600 * 24) { $days = floor($time / (3600 * 24)); } } } $uptime = ($minutes !== null ? ($hours !== null ? ($days !== null ? "{$days} %BukkitPE.command.status.days " : "") . "{$hours} %BukkitPE.command.status.hours " : "") . "{$minutes} %BukkitPE.command.status.minutes " : "") . "{$seconds} %BukkitPE.command.status.seconds"; $sender->sendMessage(TextFormat::GOLD . "%BukkitPE.command.status.uptime " . TextFormat::RED . $uptime); $tpsColor = TextFormat::GREEN; if ($server->getTicksPerSecondAverage() < 10) { $tpsColor = TextFormat::GOLD; } elseif ($server->getTicksPerSecondAverage() < 1) { $tpsColor = TextFormat::RED; } $tpsColour = TextFormat::GREEN; if ($server->getTicksPerSecond() < 10) { $tpsColour = TextFormat::GOLD; } elseif ($server->getTicksPerSecond() < 1) { $tpsColour = TextFormat::RED; } $sender->sendMessage(TextFormat::GOLD . "%BukkitPE.command.status.AverageTPS " . $tpsColor . $server->getTicksPerSecondAverage() . " (" . $server->getTickUsageAverage() . "%)"); $sender->sendMessage(TextFormat::GOLD . "%BukkitPE.command.status.CurrentTPS " . $tpsColour . $server->getTicksPerSecond() . " (" . $server->getTickUsage() . "%)"); $sender->sendMessage(TextFormat::GOLD . "%BukkitPE.command.status.Networkupload " . TextFormat::RED . \round($server->getNetwork()->getUpload() / 1024, 2) . " kB/s"); $sender->sendMessage(TextFormat::GOLD . "%BukkitPE.command.status.Networkdownload " . TextFormat::RED . \round($server->getNetwork()->getDownload() / 1024, 2) . " kB/s"); $sender->sendMessage(TextFormat::GOLD . "%BukkitPE.command.status.Threadcount " . TextFormat::RED . Utils::getThreadCount()); $sender->sendMessage(TextFormat::GOLD . "%BukkitPE.command.status.Mainmemory " . TextFormat::RED . number_format(round($mUsage[0] / 1024 / 1024, 2)) . " MB."); $sender->sendMessage(TextFormat::GOLD . "%BukkitPE.command.status.Totalmemory " . TextFormat::RED . number_format(round($mUsage[1] / 1024 / 1024, 2)) . " MB."); $sender->sendMessage(TextFormat::GOLD . "%BukkitPE.command.status.Totalvirtualmemory " . TextFormat::RED . number_format(round($mUsage[2] / 1024 / 1024, 2)) . " MB."); $sender->sendMessage(TextFormat::GOLD . "%BukkitPE.command.status.Heapmemory " . TextFormat::RED . number_format(round($rUsage[0] / 1024 / 1024, 2)) . " MB."); $sender->sendMessage(TextFormat::GOLD . "%BukkitPE.command.status.Maxmemorysystem " . TextFormat::RED . number_format(round($mUsage[2] / 1024 / 1024, 2)) . " MB."); if ($server->getProperty("memory.global-limit") > 0) { $sender->sendMessage(TextFormat::GOLD . "%BukkitPE.command.status.Maxmemorymanager " . TextFormat::RED . number_format(round($server->getProperty("memory.global-limit"), 2)) . " MB."); } foreach ($server->getLevels() as $level) { $sender->sendMessage(TextFormat::GOLD . "%BukkitPE.command.status.World \"" . $level->getFolderName() . "\"" . ($level->getFolderName() !== $level->getName() ? " (" . $level->getName() . ")" : "") . ": " . TextFormat::RED . number_format(count($level->getChunks())) . TextFormat::GREEN . " %BukkitPE.command.status.chunks " . TextFormat::RED . number_format(count($level->getEntities())) . TextFormat::GREEN . " %BukkitPE.command.status.entities " . TextFormat::RED . number_format(count($level->getTiles())) . TextFormat::GREEN . " %BukkitPE.command.status.tiles " . "%BukkitPE.command.status.Time " . (($level->getTickRate() > 1 or $level->getTickRateTime() > 40) ? TextFormat::RED : TextFormat::YELLOW) . round($level->getTickRateTime(), 2) . "%BukkitPE.command.status.ms" . ($level->getTickRate() > 1 ? " (tick rate " . $level->getTickRate() . ")" : "")); } return true; }
public function __debugInfo() { $data = []; foreach ($this as $k => $v) { if ($k === "buffer") { $data[$k] = bin2hex($v); } elseif (is_string($v) or is_object($v) and method_exists($v, "__toString")) { $data[$k] = Utils::printable((string) $v); } else { $data[$k] = $v; } } return $data; }
public static function RemovePortForward($port) { if (Utils::$online === false) { return false; } if (Utils::getOS() != "win" or !class_exists("COM")) { return false; } $port = (int) $port; try { $com = new \COM("HNetCfg.NATUPnP") or false; if ($com === false or !is_object($com->StaticPortMappingCollection)) { return false; } $com->StaticPortMappingCollection->Remove($port, "UDP"); } catch (\Exception $e) { return false; } return true; }
public static function getCoreCount($recalculate = false) { static $processors = 0; if ($processors > 0 and !$recalculate) { return $processors; } else { $processors = 0; } switch (Utils::getOS()) { case "linux": case "android": if (file_exists("/proc/cpuinfo")) { foreach (file("/proc/cpuinfo") as $l) { if (preg_match('/^processor[ \\t]*:[ \\t]*[0-9]+$/m', $l) > 0) { ++$processors; } } } else { if (preg_match("/^([0-9]+)\\-([0-9]+)\$/", trim(@file_get_contents("/sys/devices/system/cpu/present")), $matches) > 0) { $processors = (int) ($matches[2] - $matches[1]); } } break; case "bsd": case "mac": $processors = (int) `sysctl -n hw.ncpu`; $processors = (int) `sysctl -n hw.ncpu`; break; case "win": $processors = (int) getenv("NUMBER_OF_PROCESSORS"); break; } return $processors; }
private function networkFunctions() { $config = new Config(\BukkitPE\DATA . "server.properties", Config::PROPERTIES); echo "[!] " . $this->lang->query_warning1 . "\n"; echo "[!] " . $this->lang->query_warning2 . "\n"; echo "[?] " . $this->lang->query_disable . " (y/N): "; if (strtolower($this->getInput("n")) === "y") { $config->set("enable-query", false); } else { $config->set("enable-query", true); } echo "[*] " . $this->lang->rcon_info . "\n"; echo "[?] " . $this->lang->rcon_enable . " (y/N): "; if (strtolower($this->getInput("n")) === "y") { $config->set("enable-rcon", true); $password = substr(base64_encode(@Utils::getRandomBytes(20, false)), 3, 10); $config->set("rcon.password", $password); echo "[*] " . $this->lang->rcon_password . ": " . $password . "\n"; } else { $config->set("enable-rcon", false); } /*echo "[*] " . $this->lang->usage_info . "\n"; echo "[?] " . $this->lang->usage_disable . " (y/N): "; if(strtolower($this->getInput("n")) === "y"){ $config->set("send-usage", false); }else{ $config->set("send-usage", true); }*/ $config->save(); echo "[*] " . $this->lang->ip_get . "\n"; $externalIP = Utils::getIP(); $internalIP = gethostbyname(trim(`hostname`)); echo "[!] " . $this->lang->get("ip_warning", ["{{EXTERNAL_IP}}", "{{INTERNAL_IP}}"], [$externalIP, $internalIP]) . "\n"; echo "[!] " . $this->lang->ip_confirm; $this->getInput(); }
/** * Amount of memory already freed * * @return int */ public function getMemoryFreed() { return $this->getMemory() - ($this->isGlobal() ? Utils::getMemoryUsage(true)[1] : Utils::getMemoryUsage(true)[0]); }
function getTrace($start = 1, $trace = null) { if ($trace === null) { if (function_exists("xdebug_get_function_stack")) { $trace = array_reverse(xdebug_get_function_stack()); } else { $e = new \Exception(); $trace = $e->getTrace(); } } $messages = []; $j = 0; for ($i = (int) $start; isset($trace[$i]); ++$i, ++$j) { $params = ""; if (isset($trace[$i]["args"]) or isset($trace[$i]["params"])) { if (isset($trace[$i]["args"])) { $args = $trace[$i]["args"]; } else { $args = $trace[$i]["params"]; } foreach ($args as $name => $value) { $params .= (is_object($value) ? get_class($value) . " " . (method_exists($value, "__toString") ? $value->__toString() : "object") : gettype($value) . " " . (is_array($value) ? "Array()" : Utils::printable(@strval($value)))) . ", "; } } $messages[] = "#{$j} " . (isset($trace[$i]["file"]) ? cleanPath($trace[$i]["file"]) : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" or $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . Utils::printable(substr($params, 0, -2)) . ")"; } return $messages; }
private function continueDump($from, &$data, &$objects, &$refCounts, $recursion, $maxNesting, $maxStringSize) { if ($maxNesting <= 0) { $data = "(error) NESTING LIMIT REACHED"; return; } --$maxNesting; if (is_object($from)) { if (!isset($objects[$hash = spl_object_hash($from)])) { $objects[$hash] = $from; $refCounts[$hash] = 0; } ++$refCounts[$hash]; $data = "(object) {$hash}@" . get_class($from); } elseif (is_array($from)) { if ($recursion >= 5) { $data = "(error) ARRAY RECURSION LIMIT REACHED"; return; } $data = []; foreach ($from as $key => $value) { $this->continueDump($value, $data[$key], $objects, $refCounts, $recursion + 1, $maxNesting, $maxStringSize); } } elseif (is_string($from)) { $data = "(string) len(" . strlen($from) . ") " . substr(Utils::printable($from), 0, $maxStringSize); } elseif (is_resource($from)) { $data = "(resource) " . print_r($from, true); } else { $data = $from; } }
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"] = \BukkitPE\API_VERSION; $this->data["general"]["git"] = \BukkitPE\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("BukkitPE-MP 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 regenerateToken() { $this->lastToken = $this->token; $this->token = @Utils::getRandomBytes(16, false); }