From 0e941b2c1e25b7e4c802e038a1bdd6debb1a5267 Mon Sep 17 00:00:00 2001 From: Znote Date: Sat, 24 Jul 2021 02:35:26 +0200 Subject: [PATCH] serverinfo cleanup, fix cache, query optimizations --- engine/function/users.php | 15 ++------ layout/widgets/serverinfo.php | 43 ++++++++++------------- serverinfo.php | 64 ++++++++++------------------------- 3 files changed, 38 insertions(+), 84 deletions(-) diff --git a/engine/function/users.php b/engine/function/users.php index 6fe57c6..d6aafad 100644 --- a/engine/function/users.php +++ b/engine/function/users.php @@ -1226,19 +1226,8 @@ function user_create_character($character_data) { // Returns counted value of all players online function user_count_online() { - if (config('ServerEngine') == 'TFS_10') { - $online = mysql_select_single("SELECT COUNT(`player_id`) AS `value` FROM `players_online`;"); - return ($online !== false) ? $online['value'] : 0; - } else { - $data = mysql_select_single("SELECT COUNT(`id`) AS `count` from `players` WHERE `online` = 1;"); - return ($data !== false) ? $data['count'] : 0; - } -} - -// Returns counted value of all accounts. -function user_count_accounts() { - $result = mysql_select_single("SELECT COUNT(`id`) AS `id` from `accounts`;"); - return ($result !== false) ? $result['id'] : 0; + $online = mysql_select_single("SELECT COUNT(`player_id`) AS `value` FROM `players_online`;"); + return ($online !== false) ? $online['value'] : 0; } /* user_character_data (fetches whatever data you want from players table)! diff --git a/layout/widgets/serverinfo.php b/layout/widgets/serverinfo.php index 324c5d8..7053c7d 100644 --- a/layout/widgets/serverinfo.php +++ b/layout/widgets/serverinfo.php @@ -1,34 +1,27 @@ +hasExpired()) { + $asideServerInfo = mysql_select_single(" + SELECT + (SELECT COUNT(`id`) FROM `accounts`) as `accounts`, + (SELECT COUNT(`id`) FROM `players`) as `players`, + (SELECT COUNT(`player_id`) FROM `players_online`) as `online` + "); + $cache->setContent($asideServerInfo); + $cache->save(); +} else { + $asideServerInfo = $cache->load(); +} +?>
Server Information
    -
    Server Offline!

    "; - $status = false; - } - else { - $info = chr(6).chr(0).chr(255).chr(255).'info'; - fwrite($sock, $info); - $data=''; - while (!feof($sock))$data .= fgets($sock, 1024); - fclose($sock); - echo "
    Server Online!

    "; - } - } - if ($status) { - ?> -
  • Players online: -
  • - -
  • Registered accounts:
  • +
  • Players online:
  • +
  • Registered accounts:
  • +
  • Registered players:
diff --git a/serverinfo.php b/serverinfo.php index 48b183e..8644faf 100644 --- a/serverinfo.php +++ b/serverinfo.php @@ -27,6 +27,7 @@ function toYesNo($bool) { } // Loading stage list $cache = new Cache('engine/cache/stages'); +$cache->useMemory(false); if (user_logged_in() && is_admin($user_data)) { if (isset($_GET['loadStages'])) { echo "

Logged in as admin, loading engine/XML/stages.xml file and updating cache.

"; @@ -35,34 +36,18 @@ if (user_logged_in() && is_admin($user_data)) { if ($stagesXML !== false) { $stagesData = array(); // Load config (stages enabled or disabled) - if ($config['ServerEngine'] == 'TFS_10') - foreach ($stagesXML->config->attributes() as $name => $value) - $stagesData["$name"] = "$value"; + foreach ($stagesXML->config->attributes() as $name => $value) + $stagesData["$name"] = "$value"; // Load stage levels // Each stage XML object - if ($config['ServerEngine'] == 'TFS_10') { - foreach ($stagesXML->stage as $stage) { - $rowData = array(); - // Each attribute name and values on current stage object - foreach ($stage->attributes() as $name => $value) { - $rowData["$name"] = "$value"; - } - // Populate XML assoc array - $stagesData['stages'][] = $rowData; - } - } else { - // TFS 0.3/4 - foreach ($stagesXML->world as $world) { - foreach ($world->stage as $stage) { - $rowData = array(); - // Each attribute name and values on current stage object - foreach ($stage->attributes() as $name => $value) { - $rowData["$name"] = "$value"; - } - // Populate XML assoc array - $stagesData['stages'][] = $rowData; - } + foreach ($stagesXML->stage as $stage) { + $rowData = array(); + // Each attribute name and values on current stage object + foreach ($stage->attributes() as $name => $value) { + $rowData["$name"] = "$value"; } + // Populate XML assoc array + $stagesData['stages'][] = $rowData; } $cache->setContent($stagesData); $cache->save(); @@ -83,6 +68,7 @@ if (user_logged_in() && is_admin($user_data)) { // Loading config.lua $cache = new Cache('engine/cache/luaconfig'); +$cache->useMemory(false); if (user_logged_in() && is_admin($user_data)) { if (isset($_POST['loadConfig']) && isset($_POST['configData'])) { // Whitelist for values we are interested in @@ -120,19 +106,6 @@ if (user_logged_in() && is_admin($user_data)) { 'staminaSystem', 'experienceStages' ); - // TFS 0.3/4 compatibility, convert config value names to TFS 1.0 values - $tfs03to10 = array( - // TFS 0.3/4 TFS 1.0 - 'rateExperience' => 'rateExp', - 'loginPort' => 'loginProtocolPort', - 'rateExperienceFromPlayers' => 'experienceByKillingPlayers', - 'dailyFragsToRedSkull' => 'killsToRedSkull', - 'dailyFragsToBlackSkull' => 'killsToBlackSkull', - 'removeRuneCharges' => 'removeChargesFromRunes', - 'stairhopDelay' => 'stairJumpExhaustion', - 'housePriceEachSquare' => 'housePriceEachSQM', - 'idleKickTime' => 'kickIdlePlayerAfterMinutes', - ); // This will be the populated array with filtered relevant data $luaConfig = array(); @@ -168,13 +141,7 @@ if (user_logged_in() && is_admin($user_data)) { // Remove unnecessary whitespace $data[0] = trim($data[0]); $data[1] = trim($data[1]); - // TFS 0.3/4 compatibility - if (isset($tfs03to10[$data[0]])) { - $data[0] = $tfs03to10[$data[0]]; - if (isset($tfs03to10[$data[1]])) { - $data[1] = $tfs03to10[$data[1]]; - } - } + if (in_array($data[0], $whitelist)) { // Type cast: boolean if (in_array(strtolower($data[1]), array('true', 'false'))) { @@ -227,7 +194,12 @@ $stages = false;

Server Information

Here you will find all basic information about

- +

Server rates