From 1ac08ce40415d1d9791cae5712a42506fc14f339 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 20 Sep 2014 12:39:57 +0200 Subject: [PATCH] Fixed Utils::getUniqueID() on Linux due to /proc/cpuinfo --- src/pocketmine/Server.php | 2 +- src/pocketmine/utils/Utils.php | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 85af30592..5f61aadfb 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -2008,7 +2008,7 @@ class Server{ $version = new VersionString(); $this->lastSendUsage = new SendUsageTask("http://stats.pocketmine.net/usage.php", [ - "serverid" => Binary::readLong(substr(Utils::getUniqueID(true, $this->getIp() . ":" . $this->getPort()), 0, 8)), + "serverid" => $this->serverID, "port" => $this->getPort(), "os" => Utils::getOS(), "name" => $this->getName(), diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index 40d4275f1..796420b2c 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -59,13 +59,14 @@ class Utils{ */ public static function getUniqueID($raw = false, $extra = ""){ $machine = php_uname("a"); - $machine .= file_exists("/proc/cpuinfo") ? file_get_contents("/proc/cpuinfo") : ""; + $machine .= file_exists("/proc/cpuinfo") ? `cat /proc/cpuinfo | grep "model name"`: ""; $machine .= sys_get_temp_dir(); $machine .= $extra; - if(Utils::getOS() == "win"){ - exec("ipconfig /ALL", $mac); + $os = Utils::getOS(); + if($os === "win"){ + @exec("ipconfig /ALL", $mac); $mac = implode("\n", $mac); - if(preg_match_all("#Physical Address[. ]{1,}: ([0-9A-F\-]{17})#", $mac, $matches)){ + if(preg_match_all("#Physical Address[. ]{1,}: ([0-9A-F\\-]{17})#", $mac, $matches)){ foreach($matches[1] as $i => $v){ if($v == "00-00-00-00-00-00"){ unset($matches[1][$i]); @@ -73,6 +74,17 @@ class Utils{ } $machine .= implode(" ", $matches[1]); //Mac Addresses } + }elseif($os === "linux"){ + @exec("ifconfig /ALL", $mac); + $mac = implode("\n", $mac); + if(preg_match_all("#HWaddr[ \t]{1,}([0-9a-f:]{17})#", $mac, $matches)){ + foreach($matches[1] as $i => $v){ + if($v == "00:00:00:00:00:00"){ + unset($matches[1][$i]); + } + } + $machine .= implode(" ", $matches[1]); //Mac Addresses + } } $data = $machine . PHP_MAXPATHLEN; $data .= PHP_INT_MAX;