mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-12 04:45:12 +00:00
Cached Utils::getIP() method
This commit is contained in:
parent
838e7ad010
commit
6d54495402
@ -102,9 +102,7 @@ class ServerAPI{
|
||||
console("[INFO] [UPnP] Trying to port forward...");
|
||||
UPnP_PortForward($this->getProperty("server-port"));
|
||||
}
|
||||
if(($ip = Utils::getIP()) !== false){
|
||||
console("[INFO] External IP: ".$ip);
|
||||
}
|
||||
|
||||
if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){
|
||||
console("[INFO] Checking for new server version");
|
||||
console("[INFO] Last check: \x1b[36m".date("Y-m-d H:i:s", $this->getProperty("last-update"))."\x1b[0m");
|
||||
@ -144,7 +142,6 @@ class ServerAPI{
|
||||
console("[INFO] \x1b[36mThis is the latest STABLE version");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? BIG_ENDIAN:LITTLE
|
||||
|
||||
class Utils{
|
||||
public static $online = true;
|
||||
public static $ip = false;
|
||||
public function run(){
|
||||
|
||||
}
|
||||
@ -39,31 +40,34 @@ class Utils{
|
||||
return ((@fsockopen("google.com", 80) !== false or @fsockopen("www.linux.org", 80) !== false or @fsockopen("www.php.net", 80) !== false) ? true:false);
|
||||
}
|
||||
|
||||
public static function getIP(){
|
||||
public static function getIP($force = false){
|
||||
if(Utils::$online === false){
|
||||
return false;
|
||||
}elseif(Utils::$ip !== false and $force !== true){
|
||||
return Utils::$ip;
|
||||
}
|
||||
$ip = trim(strip_tags(Utils::curl_get("http://checkip.dyndns.org/")));
|
||||
if(preg_match('#Current IP Address\: ([0-9a-fA-F\:\.]*)#', $ip, $matches) > 0){
|
||||
return $matches[1];
|
||||
Utils::$ip = $matches[1];
|
||||
}else{
|
||||
$ip = Utils::curl_get("http://www.checkip.org/");
|
||||
if(preg_match('#">([0-9a-fA-F\:\.]*)</span>#', $ip, $matches) > 0){
|
||||
return $matches[1];
|
||||
Utils::$ip = $matches[1];
|
||||
}else{
|
||||
$ip = Utils::curl_get("http://checkmyip.org/");
|
||||
if(preg_match('#Your IP address is ([0-9a-fA-F\:\.]*)#', $ip, $matches) > 0){
|
||||
return $matches[1];
|
||||
Utils::$ip = $matches[1];
|
||||
}else{
|
||||
$ip = trim(Utils::curl_get("http://ifconfig.me/ip"));
|
||||
if($ip != ""){
|
||||
return $ip;
|
||||
Utils::$ip = $ip;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Utils::$ip;
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user