mirror of
https://github.com/Znote/ZnoteAAC.git
synced 2025-04-29 10:49:23 +02:00
serverinfo cleanup, fix cache, query optimizations
This commit is contained in:
parent
8f5487db2b
commit
0e941b2c1e
@ -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)!
|
||||
|
@ -1,34 +1,27 @@
|
||||
<?php
|
||||
$cache = new Cache('engine/cache/asideServerInfo');
|
||||
if ($cache->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();
|
||||
}
|
||||
?>
|
||||
<div class="well widget">
|
||||
<div class="header">
|
||||
Server Information
|
||||
</div>
|
||||
<div class="body">
|
||||
<ul>
|
||||
<?php
|
||||
$status = true;
|
||||
if ($config['status']['status_check']) {
|
||||
@$sock = fsockopen ($config['status']['status_ip'], $config['status']['status_port'], $errno, $errstr, 1);
|
||||
if(!$sock) {
|
||||
echo "<span style='color:red;font-weight:bold;'><center>Server Offline!</center></span><br/>";
|
||||
$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 "<span style='color:green;font-weight:bold;'><center>Server Online!</center></span><br />";
|
||||
}
|
||||
}
|
||||
if ($status) {
|
||||
?>
|
||||
<li><a href="onlinelist.php">Players online:
|
||||
<?php echo user_count_online(); ?></a></li>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<li>Registered accounts: <?php echo user_count_accounts();?></li>
|
||||
<li><a href="onlinelist.php">Players online: <?php echo $asideServerInfo['online']; ?></a></li>
|
||||
<li>Registered accounts: <?php echo $asideServerInfo['accounts'];?></li>
|
||||
<li>Registered players: <?php echo $asideServerInfo['players'];?></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -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 "<p><strong>Logged in as admin, loading engine/XML/stages.xml file and updating cache.</strong></p>";
|
||||
@ -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;
|
||||
<h1>Server Information</h1>
|
||||
<p>Here you will find all basic information about <b><?php echo $config['site_title']; ?></b></p>
|
||||
|
||||
<?php if (($stagesData && isset($stagesData['enabled']) && $stagesData['enabled']) || (isset($luaConfig['experienceStages']) && $luaConfig['experienceStages'] === true)): $stages = true; ?>
|
||||
<?php
|
||||
if (
|
||||
($stagesData && isset($stagesData['enabled']) && $stagesData['enabled'])
|
||||
|| (isset($luaConfig['experienceStages']) && $luaConfig['experienceStages'] === true)
|
||||
):
|
||||
$stages = true; ?>
|
||||
<h2>Server rates</h2>
|
||||
<table class="table tbl-hover">
|
||||
<tbody>
|
||||
|
Loading…
x
Reference in New Issue
Block a user