Skip to content

Commit

Permalink
Fixed error & sorting #228
Browse files Browse the repository at this point in the history
  • Loading branch information
tltneon committed Dec 27, 2024
1 parent 99f84f7 commit 2dc84ee
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 36 deletions.
2 changes: 1 addition & 1 deletion admin.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
require "src/lgsl_config.php";
require_once "src/lgsl_config.php";

if (empty($lgsl_config['admin']['user']) || empty($lgsl_config['admin']['pass'])) {
exit($lgsl_config['text']['aum']);
Expand Down
4 changes: 2 additions & 2 deletions src/lgsl_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

if (!defined("LGSL_ADMIN")) { header('HTTP/1.0 404 Not Found'); exit(); }

require "lgsl_class.php";
require "lgsl_language.php";
require_once "lgsl_class.php";
require_once "lgsl_language.php";
$lang = new Lang($_COOKIE['lgsl_lang'] ?? Lang::EN);

if (!function_exists("fsockopen") && !$lgsl_config['feed']['method']) {
Expand Down
29 changes: 16 additions & 13 deletions src/lgsl_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,10 @@ function &unserializeData(array &$data): array {
$server['e'] = $cache['e'];
$server['p'] = $cache['p'];
if (isset($cache['h'])) $server['h'] = $cache['h'];
if (isset($cache['o']['location'])) $server['o']['location'] = $cache['o']['location'];
if (isset($cache['o']['conn_tries'])) $server['o']['conn_tries'] = $cache['o']['conn_tries'];
foreach (['location', 'conn_tries', 'colored_name'] as $i) {
if (isset($cache['o'][$i]))
$server['o'][$i] = $cache['o'][$i];
}
$server['s']['cache_time'] = new Timestamp($data['cache_time']);
}
return $server;
Expand Down Expand Up @@ -678,7 +680,8 @@ function __construct($options = []) {
$this->_other = [
"zone" => null,
"comment" => '',
'conn_tries' => 0
'conn_tries' => 0,
'colored_name' => null
];
}

Expand All @@ -700,11 +703,11 @@ public function queryLive($request = 'seph') {
$protocol = new Protocol($this, $request);
$protocol->query();

global $lgsl_config;
if ($lgsl_config['history'] && LGSL::requestHas($request, "h") && !$this->isPending()) {
$config = new Config();
if ($config['history'] && LGSL::requestHas($request, "h") && !$this->isPending()) {
$last = end($this->_history);
if (!$last || time() - $last['t'] >= 60 * 15) { // RECORD IF 15 MINS IS PASSED
$history_limit = $lgsl_config['history_hours'] * 3600;
$history_limit = $config['history_hours'] * 3600;
foreach ($this->_history as $key => $value) {
if (time() - $this->_history[$key]['t'] > $history_limit) { // NOT OLDER THAN $lgsl_config['history_hours'] HOURS
unset($this->_history[$key]);
Expand All @@ -721,7 +724,7 @@ public function queryLive($request = 'seph') {
}
}

if ($lgsl_config['locations'] && empty($this->_other['location'])) {
if ($config['locations'] && empty($this->_other['location'])) {
$this->_other['location'] = $this->queryLocation();
}
}
Expand Down Expand Up @@ -821,15 +824,15 @@ public function getName($htmlSafe = false) {
if ($this->isPending()) {
return LGSL::NONE;
}
$name = Helper::lgslHtmlColor($this->_server['name'], true);
if ($htmlSafe) {
$name = preg_replace('/([\x{0001F000}-\x{0001FAFF}])/mu', '', $name);
$name = preg_replace('/([\x{0001F000}-\x{0001FAFF}])/mu', '', $this->_server['name']);
return htmlspecialchars($name, ENT_QUOTES);
}
return $name;
return $this->_server['name'];
}
public function getColoredName() {
return Helper::lgslHtmlColor($this->_server['name']);
if (isset($this->_other['colored_name'])) return Helper::lgslHtmlColor($this->_other['colored_name']);
return $this->_server['name'];
}
public function setName($name) {
$this->_server['name'] = $name;
Expand Down Expand Up @@ -1199,8 +1202,8 @@ function toString() {

$lgsl_file_path = LGSL::filePath();

require "{$lgsl_file_path}lgsl_config.php";
require "{$lgsl_file_path}lgsl_protocol.php";
require_once "{$lgsl_file_path}lgsl_config.php";
require_once "{$lgsl_file_path}lgsl_protocol.php";

$auth = md5(($_SERVER['REMOTE_ADDR'] ?? "").md5($lgsl_config['admin']['user'].md5($lgsl_config['admin']['pass'])));
$cookie = $_COOKIE['lgsl_admin_auth'] ?? "";
Expand Down
35 changes: 18 additions & 17 deletions src/lgsl_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
require "lgsl_language.php";
$lang = new Lang($_COOKIE['lgsl_lang'] ?? Lang::EN);
global $output;
$config = new Config();

$type = $_GET['type'] ?? '';
$game = $_GET['game'] ?? '';
$mode = $_GET['mode'] ?? '';
$sort = $_GET['sort'] ?? '';
$sort = $_GET['sort'] ?? $config['sort']['servers'];
$order= (isset($_GET['order']) ? $_GET['order'] == "ASC" ? "DESC" : 'ASC' : "ASC");

$page = ($lgsl_config['pagination_mod'] && isset($_GET['page']) ? (int)$_GET['page'] : 1);
$page = ($config['pagination_mod'] && isset($_GET['page']) ? (int)$_GET['page'] : 1);

$uri = $_SERVER['REQUEST_URI'];

if ($lgsl_config['preloader']) {
if ($config['preloader']) {
$uri = $_SERVER['HTTP_REFERER'];
}

Expand All @@ -47,11 +48,11 @@
<table id='server_list_table'>
<tr id='server_list_table_top'>
<th class='status_cell'>{$lgsl_config['text']['sts']}:</th>
<th class='connectlink_cell'><a href='{$ipsort}'>{$lgsl_config['text']['adr']}:</a></th>
<th class='servername_cell'><a href='{$namesort}'>{$lgsl_config['text']['tns']}:</a></th>
<th class='map_cell'><a href='{$mapsort}'>{$lgsl_config['text']['map']}:</a></th>
<th class='players_cell'><a href='{$playersort}'>{$lgsl_config['text']['plr']}:</a></th>
<th class='details_cell'>{$lgsl_config['text']['dtl']}:</th>
<th class='connectlink_cell'><a href='{$ipsort}'>{$config['text']['adr']}:</a></th>
<th class='servername_cell'><a href='{$namesort}'>{$config['text']['tns']}:</a></th>
<th class='map_cell'><a href='{$mapsort}'>{$config['text']['map']}:</a></th>
<th class='players_cell'><a href='{$playersort}'>{$config['text']['plr']}:</a></th>
<th class='details_cell'>{$config['text']['dtl']}:</th>
</tr>";

foreach ($server_list as $server) {
Expand All @@ -62,13 +63,13 @@
<tr class='server_{$server->getStatus()}'>
<td class='status_cell'>
<span title='{$lgsl_config['text'][$server->getStatus()]} | {$lgsl_config['text']['lst']}: {$lastupd}' class='status_icon_{$server->getStatus()}'></span>
<span title='{$config['text'][$server->getStatus()]} | {$config['text']['lst']}: {$lastupd}' class='status_icon_{$server->getStatus()}'></span>
<a href='{$gamelink}'>
<img alt='{$server->getName()}' src='{$server->addUrlPath($server->getGameIcon())}' title='{$server->getGameFormatted()}' class='game_icon' />
</a>
</td>
<td title='{$lgsl_config['text']['slk']}' class='connectlink_cell'>
<td title='{$config['text']['slk']}' class='connectlink_cell'>
<a href='{$server->getConnectionLink()}'>
{$server->getAddress()}
</a>
Expand Down Expand Up @@ -117,12 +118,12 @@
$output .= "
</table>";

if ($lgsl_config['pagination_mod'] && ((int)($servers / $lgsl_config['pagination_lim']) > 0 || $page > 1)) {
if ($config['pagination_mod'] && ((int)($servers / $config['pagination_lim']) > 0 || $page > 1)) {
$output .= "
<div id='pages'>
" . ($page > 1 ? "<a href='" . LGSL::buildLink($uri, ["page" => $page - 1]) . "'> < </a>" : "") . "
<span>{$lgsl_config['text']['pag']} {$page}</span>
" . ($servers < $lgsl_config['pagination_lim'] ?
<span>{$config['text']['pag']} {$page}</span>
" . ($servers < $config['pagination_lim'] ?
"" :
(isset($_GET['page']) ?
"<a href='" . LGSL::buildLink($uri, ["page" => $page + 1]) . "'> > </a>" :
Expand All @@ -136,9 +137,9 @@

$output .= "
<div id='totals'>
<div> {$lgsl_config['text']['tns']}: {$total['servers']} </div>
<div> {$lgsl_config['text']['tnp']}: {$total['players']} </div>
<div> {$lgsl_config['text']['tmp']}: {$total['playersmax']} </div>
<div> {$config['text']['tns']}: {$total['servers']} </div>
<div> {$config['text']['tnp']}: {$total['players']} </div>
<div> {$config['text']['tmp']}: {$total['playersmax']} </div>
</div>";
}

Expand All @@ -147,5 +148,5 @@
//------ WANNA BE HERE? https://github.com/tltneon/lgsl/wiki/Who-uses-LGSL -> LET CREDITS STAY :P --------------------------------------------------------------------------------------------------+
$output .= "<div style='text-align:center; font-family:tahoma; font-size:9px; padding: 33px 0px 11px 0px;'><a href='https://github.com/tltneon/lgsl' style='text-decoration:none'>".lgsl_version()."</a></div>";
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
if ($lgsl_config['preloader'])
if ($config['preloader'])
echo $output;
8 changes: 5 additions & 3 deletions src/lgsl_protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,9 @@ public function process() {
}
}

$this->_data['s']['name'] = $this->_data['e']['hostname'] ?? $this->_data['e']['sv_hostname'] ?? LGSL::NONE;
if (isset($this->_data['e']['sv_hostname'])) { $this->_data['e']['sv_hostname'] = strtolower(Helper::lgslHtmlColor($this->_data['e']['sv_hostname'], "1", true)); }
$this->_data['s']['name'] = Helper::lgslHtmlColor($this->_data['e']['hostname'] ?? $this->_data['e']['sv_hostname'] ?? LGSL::NONE, "1", true);
$this->_data['o']['colored_name'] = $this->_data['e']['hostname'] ?? $this->_data['e']['sv_hostname'] ?? LGSL::NONE;
if (isset($this->_data['e']['sv_hostname'])) { $this->_data['e']['sv_hostname'] = $this->_data['s']['name']; }
if (isset($this->_data['e']['protocol']) && $type === PROTOCOL::CALLOFDUTYIW) {
$games = ['1' => 'IW6', '2' => 'H1', '6' => 'IW3', '7' => 'T7', '20604' => 'IW5', '151' => 'IW4', '101' => 'T4'];
$this->_data['s']['game'] = $games[$this->_data['e']['protocol']] ?? "Unknown {$this->_data['e']['protocol']}";
Expand Down Expand Up @@ -2414,7 +2415,8 @@ class Query35 extends QueryJson { // FiveM / RedM
public function process() {
$buffer = $this->fetch("http://{$this->_server->getIp()}:{$this->_server->getQueryPort()}/dynamic.json");
if (!$buffer) return $this::NO_RESPOND;
$this->_data['s']['name'] = Helper::lgslParseColor($buffer['hostname'], 'fivem', false);
$this->_data['s']['name'] = Helper::lgslParseColor($buffer['hostname'], 'fivem');
$this->_data['o']['colored_name'] = Helper::lgslParseColor($buffer['hostname'], 'fivem', false);
$this->_data['s']['players'] = $buffer['clients'];
$this->_data['s']['playersmax'] = $buffer['sv_maxclients'];
$this->_data['s']['map'] = $buffer['mapname'];
Expand Down

0 comments on commit 2dc84ee

Please sign in to comment.