diff --git a/PocketMine-MP.php b/PocketMine-MP.php index 09b9fea55..64da055b5 100644 --- a/PocketMine-MP.php +++ b/PocketMine-MP.php @@ -33,6 +33,6 @@ require_once(FILE_PATH."/src/dependencies.php"); /***REM_END***/ $server = new ServerAPI(); -$server->run(); +$server->start(); exit(0); \ No newline at end of file diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 95be42725..45a08c3e8 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -28,14 +28,20 @@ the Free Software Foundation, either version 3 of the License, or class ServerAPI{ var $restart = false; private static $serverRequest = false; + private $asyncCalls = array(); private $server; private $config; private $apiList = array(); + private $asyncCnt = 0; public static function request(){ return self::$serverRequest; } + public function start(){ + return $this->run(); + } + public function run(){ $this->load(); return $this->init(); @@ -223,13 +229,29 @@ class ServerAPI{ $this->server->loadEntities(); } + public function async(callable $callable, $params = array()){ + $cnt = $this->asyncCnt++; + $this->asyncCalls[$cnt] = new Async($callable, $params); + return $cnt; + } + + public function getAsync($id){ + if(!isset($this->asyncCalls[$id])){ + return false; + } + $ob = $this->asyncCalls[$id]; + $this->asyncCalls[$id] = null; + unset($this->asyncCalls[$id]); + return $ob; + } + public function sendUsage(){ console("[INTERNAL] Sending usage data...", true, true, 3); $plist = ""; foreach($this->plugin->getList() as $p){ $plist .= str_replace(array(";", ":"), "", $p["name"]).":".str_replace(array(";", ":"), "", $p["version"]).";"; } - Async::call("Utils::curl_post", array( + $this->async("Utils::curl_post", array( 0 => "http://stats.pocketmine.net/usage.php", 1 => array( "serverid" => $this->server->serverID, diff --git a/src/utils/Utils.php b/src/utils/Utils.php index c4a0aabc1..2a1ea264f 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -35,7 +35,7 @@ define("BIG_ENDIAN", 0x00); define("LITTLE_ENDIAN", 0x01); define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? BIG_ENDIAN:LITTLE_ENDIAN)); -class Utils extends Thread{ +class Utils{ public static $online = true; public function run(){