diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 133d83026..a0546d71a 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -346,6 +346,10 @@ class Server{ return $this->getConfigString("motd", "Minecraft: PE Server"); } + public function getServerUniqueId(){ + return $this->serverID; + } + /** * @return bool */ @@ -1638,7 +1642,10 @@ class Server{ $this->logger->info($this->getLanguage()->translateString("pocketmine.server.networkStart", [$this->getIp() === "" ? "*" : $this->getIp(), $this->getPort()])); define("BOOTUP_RANDOM", @Utils::getRandomBytes(16)); - $this->serverID = Utils::getServerUniqueId($this->getIp() . $this->getPort()); + $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()); diff --git a/src/pocketmine/command/defaults/GarbageCollectorCommand.php b/src/pocketmine/command/defaults/GarbageCollectorCommand.php index ef0ce367c..bbb63ccd6 100644 --- a/src/pocketmine/command/defaults/GarbageCollectorCommand.php +++ b/src/pocketmine/command/defaults/GarbageCollectorCommand.php @@ -45,6 +45,8 @@ class GarbageCollectorCommand extends VanillaCommand{ $entitiesCollected = 0; $tilesCollected = 0; + $memory = memory_get_usage(); + foreach($sender->getServer()->getLevels() as $level){ $diff = [count($level->getChunks()), count($level->getEntities()), count($level->getTiles())]; $level->doChunkGarbageCollection(); @@ -62,6 +64,7 @@ class GarbageCollectorCommand extends VanillaCommand{ $sender->sendMessage(TextFormat::GOLD . "Tiles: " . TextFormat::RED . number_format($tilesCollected)); $sender->sendMessage(TextFormat::GOLD . "Cycles: " . TextFormat::RED . number_format($cyclesCollected)); + $sender->sendMessage(TextFormat::GOLD . "Memory freed: " . TextFormat::RED . number_format(round((($memory - memory_get_usage()) / 1024) / 1024, 2))." MB"); return true; } } diff --git a/src/pocketmine/scheduler/SendUsageTask.php b/src/pocketmine/scheduler/SendUsageTask.php index 2ec40a6d8..04b75c8d6 100644 --- a/src/pocketmine/scheduler/SendUsageTask.php +++ b/src/pocketmine/scheduler/SendUsageTask.php @@ -40,8 +40,9 @@ class SendUsageTask extends AsyncTask{ $path = "post"; $data = []; - $data["uniqueServerId"] = Utils::getServerUniqueId(); - $data["uniqueRequestId"] = Utils::dataToUUID(Utils::getServerUniqueId(), microtime(true)); + $data["uniqueServerId"] = $server->getServerUniqueId(); + $data["uniqueMachineId"] = Utils::getMachineUniqueId(); + $data["uniqueRequestId"] = Utils::dataToUUID($server->getServerUniqueId(), microtime(true)); switch($type){ case self::TYPE_OPEN: diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index 15fd8bf45..ca05b1676 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -78,13 +78,13 @@ class Utils{ * * @return string */ - public static function getServerUniqueId($extra = ""){ - if(self::$serverUniqueId !== null){ + public static function getMachineUniqueId($extra = ""){ + if(self::$serverUniqueId !== null and $extra === ""){ return self::$serverUniqueId; } $machine = php_uname("a"); - $machine .= file_exists("/proc/cpuinfo") ? implode(preg_grep("/model name/", file("/proc/cpuinfo"))) : ""; + $machine .= file_exists("/proc/cpuinfo") ? implode(preg_grep("/(model name|Processor|Serial)/", file("/proc/cpuinfo"))) : ""; $machine .= sys_get_temp_dir(); $machine .= $extra; $os = Utils::getOS(); @@ -110,6 +110,11 @@ class Utils{ } $machine .= implode(" ", $matches[1]); //Mac Addresses } + $machine .= file_exists("/etc/machine-id") ? file_get_contents("/etc/machine-id") : ""; + }elseif($os === "android"){ + $machine .= @file_get_contents("/system/build.prop"); + }elseif($os === "mac"){ + $machine .= `system_profiler SPHardwareDataType | grep UUID`; } $data = $machine . PHP_MAXPATHLEN; $data .= PHP_INT_MAX; @@ -119,7 +124,13 @@ class Utils{ $data .= $ext . ":" . phpversion($ext); } - return self::$serverUniqueId = Utils::dataToUUID($machine, $data); + $uuid = Utils::dataToUUID($machine, $data); + + if($extra === ""){ + self::$serverUniqueId = $uuid; + } + + return $uuid; } /** @@ -245,8 +256,15 @@ class Utils{ return count(ThreadManager::getInstance()->getAll()) + 3; //RakLib + MainLogger + Main Thread } - public static function getCoreCount(){ - $processors = 0; + 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": @@ -256,13 +274,16 @@ class Utils{ ++$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": - $processors = (int) `sysctl hw.ncpu | awk '{ print $2+1 }'`; - break; case "mac": - $processors = (int) `sysctl hw.availcpu | awk '{ print $2+1 }'`; + $processors = (int) `sysctl -n hw.ncpu`; + $processors = (int) `sysctl -n hw.ncpu`; break; case "win": $processors = (int) getenv("NUMBER_OF_PROCESSORS");