mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 02:09:42 +00:00
Improved unique id generation for server
This commit is contained in:
parent
cde2d39029
commit
46f20d36b3
@ -346,6 +346,10 @@ class Server{
|
|||||||
return $this->getConfigString("motd", "Minecraft: PE Server");
|
return $this->getConfigString("motd", "Minecraft: PE Server");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getServerUniqueId(){
|
||||||
|
return $this->serverID;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -1638,7 +1642,10 @@ class Server{
|
|||||||
|
|
||||||
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.networkStart", [$this->getIp() === "" ? "*" : $this->getIp(), $this->getPort()]));
|
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.networkStart", [$this->getIp() === "" ? "*" : $this->getIp(), $this->getPort()]));
|
||||||
define("BOOTUP_RANDOM", @Utils::getRandomBytes(16));
|
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 = new Network($this);
|
||||||
$this->network->setName($this->getMotd());
|
$this->network->setName($this->getMotd());
|
||||||
|
@ -45,6 +45,8 @@ class GarbageCollectorCommand extends VanillaCommand{
|
|||||||
$entitiesCollected = 0;
|
$entitiesCollected = 0;
|
||||||
$tilesCollected = 0;
|
$tilesCollected = 0;
|
||||||
|
|
||||||
|
$memory = memory_get_usage();
|
||||||
|
|
||||||
foreach($sender->getServer()->getLevels() as $level){
|
foreach($sender->getServer()->getLevels() as $level){
|
||||||
$diff = [count($level->getChunks()), count($level->getEntities()), count($level->getTiles())];
|
$diff = [count($level->getChunks()), count($level->getEntities()), count($level->getTiles())];
|
||||||
$level->doChunkGarbageCollection();
|
$level->doChunkGarbageCollection();
|
||||||
@ -62,6 +64,7 @@ class GarbageCollectorCommand extends VanillaCommand{
|
|||||||
$sender->sendMessage(TextFormat::GOLD . "Tiles: " . TextFormat::RED . number_format($tilesCollected));
|
$sender->sendMessage(TextFormat::GOLD . "Tiles: " . TextFormat::RED . number_format($tilesCollected));
|
||||||
|
|
||||||
$sender->sendMessage(TextFormat::GOLD . "Cycles: " . TextFormat::RED . number_format($cyclesCollected));
|
$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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,9 @@ class SendUsageTask extends AsyncTask{
|
|||||||
$path = "post";
|
$path = "post";
|
||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
$data["uniqueServerId"] = Utils::getServerUniqueId();
|
$data["uniqueServerId"] = $server->getServerUniqueId();
|
||||||
$data["uniqueRequestId"] = Utils::dataToUUID(Utils::getServerUniqueId(), microtime(true));
|
$data["uniqueMachineId"] = Utils::getMachineUniqueId();
|
||||||
|
$data["uniqueRequestId"] = Utils::dataToUUID($server->getServerUniqueId(), microtime(true));
|
||||||
|
|
||||||
switch($type){
|
switch($type){
|
||||||
case self::TYPE_OPEN:
|
case self::TYPE_OPEN:
|
||||||
|
@ -78,13 +78,13 @@ class Utils{
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function getServerUniqueId($extra = ""){
|
public static function getMachineUniqueId($extra = ""){
|
||||||
if(self::$serverUniqueId !== null){
|
if(self::$serverUniqueId !== null and $extra === ""){
|
||||||
return self::$serverUniqueId;
|
return self::$serverUniqueId;
|
||||||
}
|
}
|
||||||
|
|
||||||
$machine = php_uname("a");
|
$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 .= sys_get_temp_dir();
|
||||||
$machine .= $extra;
|
$machine .= $extra;
|
||||||
$os = Utils::getOS();
|
$os = Utils::getOS();
|
||||||
@ -110,6 +110,11 @@ class Utils{
|
|||||||
}
|
}
|
||||||
$machine .= implode(" ", $matches[1]); //Mac Addresses
|
$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 = $machine . PHP_MAXPATHLEN;
|
||||||
$data .= PHP_INT_MAX;
|
$data .= PHP_INT_MAX;
|
||||||
@ -119,7 +124,13 @@ class Utils{
|
|||||||
$data .= $ext . ":" . phpversion($ext);
|
$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
|
return count(ThreadManager::getInstance()->getAll()) + 3; //RakLib + MainLogger + Main Thread
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getCoreCount(){
|
public static function getCoreCount($recalculate = false){
|
||||||
$processors = 0;
|
static $processors = 0;
|
||||||
|
|
||||||
|
if($processors > 0 and !$recalculate){
|
||||||
|
return $processors;
|
||||||
|
}else{
|
||||||
|
$processors = 0;
|
||||||
|
}
|
||||||
|
|
||||||
switch(Utils::getOS()){
|
switch(Utils::getOS()){
|
||||||
case "linux":
|
case "linux":
|
||||||
case "android":
|
case "android":
|
||||||
@ -256,13 +274,16 @@ class Utils{
|
|||||||
++$processors;
|
++$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;
|
break;
|
||||||
case "bsd":
|
case "bsd":
|
||||||
$processors = (int) `sysctl hw.ncpu | awk '{ print $2+1 }'`;
|
|
||||||
break;
|
|
||||||
case "mac":
|
case "mac":
|
||||||
$processors = (int) `sysctl hw.availcpu | awk '{ print $2+1 }'`;
|
$processors = (int) `sysctl -n hw.ncpu`;
|
||||||
|
$processors = (int) `sysctl -n hw.ncpu`;
|
||||||
break;
|
break;
|
||||||
case "win":
|
case "win":
|
||||||
$processors = (int) getenv("NUMBER_OF_PROCESSORS");
|
$processors = (int) getenv("NUMBER_OF_PROCESSORS");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user