From f476cf6943e8620e9c7b520c60ec4d61d8d61243 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Sat, 26 Jan 2013 20:50:34 +0100 Subject: [PATCH] Send optional usage data --- src/API/ServerAPI.php | 17 +++++++++++++++++ src/classes/utils/Utils.php | 22 +++++++++------------- src/protocol/current.php | 2 ++ src/protocol/dataName.php | 2 ++ 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index a45501737..8b29e3472 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -102,6 +102,7 @@ class ServerAPI{ "level-name" => false, "server-id" => false, "upnp-forwarding" => false, + "send-usage" => true, )); $this->parseProperties(); define("DEBUG", $this->getProperty("debug")); @@ -223,6 +224,18 @@ class ServerAPI{ $this->server->loadEntities(); } + + public function sendUsage(){ + console("[INTERNAL] Sending usage data...", true, true, 3); + Utils::curl_post("http://www.pocketmine.org/usage.php", array( + "serverid" => $this->server->serverID, + "os" => Utils::getOS(), + "version" => MAJOR_VERSION, + "protocol" => CURRENT_PROTOCOL, + "online" => count($this->clients), + "max" => $this->maxClients, + )); + } public function __destruct(){ foreach($this->apiList as $ob){ @@ -295,6 +308,10 @@ class ServerAPI{ } public function init(){ + if($this->getProperty("send-usage") !== false){ + $this->server->schedule(36000, array($this, "sendUsage"), array(), true); //Send usage data every 30 minutes + $this->sendUsage(); + } $this->server->init(); unregister_tick_function(array($this->server, "tick")); $this->__destruct(); diff --git a/src/classes/utils/Utils.php b/src/classes/utils/Utils.php index 6f0bc92a5..2c0be5f45 100644 --- a/src/classes/utils/Utils.php +++ b/src/classes/utils/Utils.php @@ -49,27 +49,23 @@ class Utils extends Thread{ if(Utils::$online === false){ return false; } - $ip = "";//trim(Utils::curl_get("http://automation.whatismyip.com/n09230945.asp")); - if($ip != ""){ - return $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]; }else{ - trim(strip_tags(Utils::curl_get("http://checkip.dyndns.org/"))); - if(preg_match('#Current IP Address\: ([0-9a-fA-F\:\.]*)#', $ip, $matches) > 0){ + $ip = Utils::curl_get("http://www.checkip.org/"); + if(preg_match('#">([0-9a-fA-F\:\.]*)#', $ip, $matches) > 0){ return $matches[1]; }else{ - $ip = Utils::curl_get("http://www.checkip.org/"); - if(preg_match('#">([0-9a-fA-F\:\.]*)#', $ip, $matches) > 0){ + $ip = Utils::curl_get("http://checkmyip.org/"); + if(preg_match('#Your IP address is ([0-9a-fA-F\:\.]*)#', $ip, $matches) > 0){ return $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]; - }else{ - return false; - } + return false; } } } + } public static function getOS(){ diff --git a/src/protocol/current.php b/src/protocol/current.php index 5b3d60c03..0d0752333 100644 --- a/src/protocol/current.php +++ b/src/protocol/current.php @@ -60,6 +60,8 @@ define("MC_UPDATE_BLOCK", 0x97); define("MC_EXPLOSION", 0x99); +define("MC_LEVEL_EVENT", 0x9a); + define("MC_ENTITY_EVENT", 0x9c); define("MC_REQUEST_CHUNK", 0x9d); define("MC_CHUNK_DATA", 0x9e); diff --git a/src/protocol/dataName.php b/src/protocol/dataName.php index 9b5069ecd..6fed0a57c 100644 --- a/src/protocol/dataName.php +++ b/src/protocol/dataName.php @@ -61,6 +61,8 @@ $dataName = array( MC_UPDATE_BLOCK => "UpdateBlock", MC_EXPLOSION => "Explosion", + + MC_LEVEL_EVENT => "LevelEvent", MC_ENTITY_EVENT => "EntityEvent", MC_REQUEST_CHUNK => "RequestChunk",