Skip to content

Commit

Permalink
fix: misleading error in server status widget if server is offline
Browse files Browse the repository at this point in the history
  • Loading branch information
samerton committed Mar 31, 2024
1 parent 91763a2 commit 3da15ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
19 changes: 10 additions & 9 deletions custom/templates/DefaultRevamp/widgets/server_status.tpl
Expand Up @@ -6,15 +6,16 @@
<div class="ui relaxed">
<div class="content">
{if $SERVER.status_value eq 1}
<span class="ui label large green">{$ONLINE}
{else}
<span class="ui label large green">{$ONLINE}
{else}
<span class="ui label large red">{$OFFLINE}
{/if}
<div class="detail">{$SERVER.name}</div>
</span>
{/if}
<div class="detail">{$SERVER.name}</div>
</span>

{if $SERVER.status_value eq 1}
<div class="ui divider"></div>
<div class="ui divider"></div>

{if $SERVER.status_value eq 1}
<p>{$ONLINE}: <strong>{$SERVER.player_count} / {$SERVER.player_count_max}</strong></p>
{if isset($SERVER.format_player_list) && count($SERVER.format_player_list) && ($SERVER.player_count > 0)}
<p>
Expand All @@ -27,8 +28,8 @@
{if isset($VERSION)}
<p>{$VERSION}</p>
{/if}
<p>{$IP}: <strong>{$SERVER.join_at}</strong></p>
{/if}
{/if}
<p>{$IP}: <strong>{$SERVER.join_at}</strong></p>
</div>
</div>
{else}
Expand Down
18 changes: 13 additions & 5 deletions modules/Core/widgets/ServerStatusWidget.php
Expand Up @@ -34,11 +34,12 @@ public function initialise(): void {
if ($this->_cache->isCached('server_status')) {
$server_array = $this->_cache->retrieve('server_status');
} else {
$server = DB::getInstance()->query('SELECT * FROM nl2_mc_servers WHERE is_default = 1')->results();
$server = $server[0];
$server = DB::getInstance()->query('SELECT * FROM nl2_mc_servers WHERE is_default = 1');

if ($server != null) {
if ($server->count()) {
$server = $server->first();
$server_array_request = HttpClient::get(rtrim(URL::getSelfURL(), '/') . URL::build('/queries/server/', 'id=' . $server->id));

if (!$server_array_request->hasError()) {
$server_array = $server_array_request->json(true);
foreach ($server_array as $key => $value) {
Expand All @@ -49,10 +50,17 @@ public function initialise(): void {
$server_array[$key] = Output::getClean($value);
}
}
$server_array['name'] = $server->name;
$server_array['join_at'] = $server->ip;
} else {
$server_array = [
'status_value' => 0,
'status' => $this->_language->get('general', 'offline'),
'server_offline' => $this->_language->get('general', 'server_offline'),
];
}

$server_array['name'] = Output::getCLean($server->name);
$server_array['join_at'] = Output::getClean($server->ip);

$this->_cache->store('server_status', $server_array, 120);
}
}
Expand Down

0 comments on commit 3da15ea

Please sign in to comment.