From 34287bb10146589de1d7aef63f3e28ef3565b2ff Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sat, 23 Jul 2022 02:31:28 +0300 Subject: [PATCH] QueryAPI --- src/API/ServerAPI.php | 6 +++--- src/network/query/QueryHandler.php | 25 ++++++++----------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 5f710b49..85493de4 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -28,8 +28,7 @@ class ServerAPI{ private $apiList = array(); private $asyncCnt = 0; private $rcon; - - public $query; + public $queryAPI; //TODO: Instead of hard-coding functions, use PHPDoc-compatible methods to load APIs. @@ -174,7 +173,7 @@ class ServerAPI{ $this->loadAPI("tile", "TileAPI"); $this->loadAPI("player", "PlayerAPI"); $this->loadAPI("time", "TimeAPI"); - + $this->loadAPI("queryAPI", "QueryAPI"); foreach($this->apiList as $ob){ if(is_callable(array($ob, "init"))){ $ob->init(); //Fails sometimes!!! @@ -182,6 +181,7 @@ class ServerAPI{ } $this->loadAPI("plugin", "PluginAPI"); //fix :( $this->plugin->init(); + } public function async(callable $callable, $params = array(), $remove = false){ diff --git a/src/network/query/QueryHandler.php b/src/network/query/QueryHandler.php index 938bc728..6aba49c1 100644 --- a/src/network/query/QueryHandler.php +++ b/src/network/query/QueryHandler.php @@ -41,7 +41,7 @@ class QueryHandler{ Then, the Query class handles itself sending the packets in raw form, because packets can conflict with the MCPE ones. */ - + $this->server->schedule(20 * 30, array($this, "regenerateToken"), array(), true); $this->regenerateToken(); $this->lastToken = $this->token; @@ -62,22 +62,13 @@ class QueryHandler{ $plist = substr($plist, 0, -1); } } - $KVdata = array( - "splitnum" => chr(128), - "hostname" => $this->server->name, - "gametype" => ($this->server->gamemode & 0x01) === 0 ? "SMP":"CMP", - "game_id" => "MINECRAFTPE", - "version" => CURRENT_MINECRAFT_VERSION, - "server_engine" => "NostalgiaCore ".MAJOR_VERSION, - "plugins" => $plist, - "map" => $this->server->api->level->getDefault()->getName(), - "numplayers" => count($this->server->clients), - "maxplayers" => $this->server->maxClients, - "whitelist" => $this->server->api->getProperty("white-list") === true ? "on":"off", - "hostport" => $this->server->api->getProperty("server-port"), - //"hostip" => $this->server->api->getProperty("server-ip", "0.0.0.0") - "tps" => $this->server->debugInfo()["tps"], - ); + $this->server->api->queryAPI->updateQueryData("plugins", $plist); + $this->server->api->queryAPI->updateQueryData("map", $this->server->api->level->getDefault()->getName()); + $this->server->api->queryAPI->updateQueryData("numplayers", count($this->server->clients)); + $this->server->api->queryAPI->updateQueryData("tps", $this->server->debugInfo()["tps"]); + $this->server->api->dhandle("query.update", null); + $KVdata = $this->server->api->queryAPI->getQueryData(); + foreach($KVdata as $key => $value){ $str .= $key."\x00".$value."\x00"; }