diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index a92bedf9a..69bb132a3 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -2186,22 +2186,55 @@ class Server{ $this->scheduler->scheduleAsyncTask($this->lastSendUsage); } + + public function getNetwork(){ + return $this->mainInterface; + } private function titleTick(){ if(!Terminal::hasFormattingCodes()){ return; } + + $usage = $this->getMemoryUsage(); + if($usage === null){ + $usage = round((memory_get_usage() / 1024) / 1024, 2) . + "/" . round((memory_get_usage(true) / 1024) / 1024, 2) . + " MB @ " . $this->getThreadCount() . " threads"; + }else{ + $usage = round(($usage / 1024) / 1024, 2) . " MB @ " . $this->getThreadCount() . " threads"; + } echo "\x1b]0;" . $this->getName() . " " . $this->getPocketMineVersion() . " | Online " . count($this->players) . "/" . $this->getMaxPlayers() . - " | RAM " . round((memory_get_usage() / 1024) / 1024, 2) . - "/" . round((memory_get_usage(true) / 1024) / 1024, 2) . - " MB | U " . round($this->mainInterface->getUploadUsage() / 1024, 2) . + " | RAM " . $usage . + " | U " . round($this->mainInterface->getUploadUsage() / 1024, 2) . " D " . round($this->mainInterface->getDownloadUsage() / 1024, 2) . " kB/s | TPS " . $this->getTicksPerSecond() . " | Load " . $this->getTickUsage() . "%\x07"; } + + public function getMemoryUsage(){ + if(Utils::getOS() === "linux" or Utils::getOS() === "bsd"){ + if(preg_match("/VmSize:[ \t]+([0-9]+) kB/", file_get_contents("/proc/self/status"), $matches) > 0){ + return $matches[1] * 1024; + } + } + + return memory_get_usage(true); + } + + public function getThreadCount(){ + if(Utils::getOS() === "linux" or Utils::getOS() === "bsd"){ + + if(preg_match("/Threads:[ \t]+([0-9]+)/", file_get_contents("/proc/self/status"), $matches) > 0){ + return (int) $matches[1]; + } + } + + return count(ThreadManager::getInstance()->getAll()) + 2; + } /** diff --git a/src/pocketmine/command/defaults/StatusCommand.php b/src/pocketmine/command/defaults/StatusCommand.php index e5e638940..e73aae953 100644 --- a/src/pocketmine/command/defaults/StatusCommand.php +++ b/src/pocketmine/command/defaults/StatusCommand.php @@ -23,6 +23,7 @@ namespace pocketmine\command\defaults; use pocketmine\command\CommandSender; use pocketmine\utils\TextFormat; +use pocketmine\ThreadManager; class StatusCommand extends VanillaCommand{ @@ -44,10 +45,10 @@ class StatusCommand extends VanillaCommand{ $sender->sendMessage(TextFormat::GREEN . "---- " . TextFormat::WHITE . "Server status" . TextFormat::GREEN . " ----"); $sender->sendMessage(TextFormat::GOLD . "TPS: " . TextFormat::WHITE . $server->getTicksPerSecond()); $sender->sendMessage(TextFormat::GOLD . "TPS Load: " . TextFormat::WHITE . $server->getTickUsage() . "%"); - //TODO: implement network speed - //$sender->sendMessage(TextFormat::GOLD . "Upload: " . TextFormat::WHITE . round($server->getNetwork()->getUploadSpeed() / 1024, 2) . " kB/s"); - //$sender->sendMessage(TextFormat::GOLD . "Download: " . TextFormat::WHITE . round($server->getNetwork()->getDownloadSpeed() / 1024, 2) . " kB/s"); - $sender->sendMessage(TextFormat::GOLD . "Memory: " . TextFormat::WHITE . round((memory_get_usage() / 1024) / 1024, 2) . TextFormat::YELLOW . "/" . TextFormat::WHITE . round((memory_get_usage(true) / 1024) / 1024, 2) . " MB"); + $sender->sendMessage(TextFormat::GOLD . "Upload: " . TextFormat::WHITE . round($server->getNetwork()->getUploadUsage() / 1024, 2) . " kB/s"); + $sender->sendMessage(TextFormat::GOLD . "Download: " . TextFormat::WHITE . round($server->getNetwork()->getDownloadUsage() / 1024, 2) . " kB/s"); + $sender->sendMessage(TextFormat::GOLD . "Memory: " . TextFormat::WHITE . round(($server->getMemoryUsage() / 1024) / 1024, 2) . " MB"); + $sender->sendMessage(TextFormat::GOLD . "Threads: " . TextFormat::WHITE . $server->getThreadCount()); return true; } diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index 082a63927..adabdee78 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -77,7 +77,10 @@ class Effect{ * @return $this */ public static function getEffect($id){ - return clone self::$effects[(int) $id]; + if(isset(self::$effects[$id])){ + return clone self::$effects[(int) $id]; + } + return null; } public static function getEffectByName($name){ @@ -184,4 +187,4 @@ class Effect{ break; } } -} \ No newline at end of file +} diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index f3ed25249..fd0136a1e 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -30,6 +30,7 @@ namespace pocketmine\utils; class Utils{ public static $online = true; public static $ip = false; + public static $os; /** * Generates an unique identifier to a callable @@ -149,27 +150,31 @@ class Utils{ * * @return string */ - public static function getOS(){ - $uname = php_uname("s"); - if(stripos($uname, "Darwin") !== false){ - if(strpos(php_uname("m"), "iP") === 0){ - return "ios"; + public static function getOS($recalculate = false){ + if(self::$os === null or $recalculate){ + $uname = php_uname("s"); + if(stripos($uname, "Darwin") !== false){ + if(strpos(php_uname("m"), "iP") === 0){ + self::$os = "ios"; + }else{ + self::$os = "mac"; + } + }elseif(stripos($uname, "Win") !== false or $uname === "Msys"){ + self::$os = "win"; + }elseif(stripos($uname, "Linux") !== false){ + if(@file_exists("/system/build.prop")){ + self::$os = "android"; + }else{ + self::$os = "linux"; + } + }elseif(stripos($uname, "BSD") !== false or $uname === "DragonFly"){ + self::$os = "bsd"; }else{ - return "mac"; + self::$os = "other"; } - }elseif(stripos($uname, "Win") !== false or $uname === "Msys"){ - return "win"; - }elseif(stripos($uname, "Linux") !== false){ - if(@file_exists("/system/build.prop")){ - return "android"; - }else{ - return "linux"; - } - }elseif(stripos($uname, "BSD") !== false or $uname === "DragonFly"){ - return "bsd"; - }else{ - return "other"; } + + return self::$os; } /**