Skip to content

Commit

Permalink
Show status when errors occurs
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
tltneon committed Jun 22, 2024
1 parent d6108c6 commit 0704bd6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
Binary file removed src/icons/warsowold/warsowold.gif
Binary file not shown.
1 change: 1 addition & 0 deletions src/languages/english.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
$lgsl_config['text']['nei'] = "NO EXTRA INFO";
$lgsl_config['text']['ehs'] = "Setting";
$lgsl_config['text']['ehv'] = "Value";
$lgsl_config['text']['err'] = "ERROR";
$lgsl_config['text']['onl'] = "ONLINE";
$lgsl_config['text']['onp'] = "ONLINE WITH PASSWORD";
$lgsl_config['text']['nrs'] = "NO RESPONSE";
Expand Down
1 change: 0 additions & 1 deletion src/lgsl_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ function drawServerRow(array $row, bool $isNew = false) {
if ($isNew) {
$row = ['type' => $this->lastType, 'ip' => '', 'c_port' => '', 'q_port' => '', 's_port' => '', 'zone' => 0, 'disabled' => '', 'comment' => ''];
}
$zone_list = [0,2,3];
$isDisabled = function($check) {
return $check ? 'readonly onclick="return false;" style="background: #777; cursor: not-allowed;"' : '';
};
Expand Down
19 changes: 12 additions & 7 deletions src/lgsl_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ class Server {
public const OFFLINE = "nrs";
public const PASSWORDED = "pwd";
public const PENDING = "pen";
public const ERROR = "err";
private $_base;
private $_extra = [];
private $_other;
Expand Down Expand Up @@ -971,6 +972,7 @@ public function getGameIcon($path = '') {
public function getStatusIcon($path = '') {
switch ($this->getStatus()) {
case self::PENDING: return "{$path}other/icon_unknown.gif";
case self::ERROR: return "{$path}other/icon_unknown.gif";
case self::OFFLINE: return "{$path}other/icon_no_response.gif";
case self::PASSWORDED: return "{$path}other/icon_online_password.gif";
default: return "{$path}other/icon_online.gif";
Expand All @@ -983,16 +985,16 @@ public function getLocationFormatted() {
public function getLocation() {
return $this->_other['location'] ?? "XX";
}
public function getTimestamp($type = 's') {
public function getTimestamp($type = Timestamp::SERVER) {
return $this->_server['cache_time']->get($type);
}
public function getTimestampFormatted($type = 's') {
public function getTimestampFormatted($type = Timestamp::SERVER) {
$time = $this->getTimestamp($type);
if ($time > 0) {
global $lgsl_config;
if ($time > 0) {
return Date($lgsl_config['text']['tzn'], $time);
}
return 'not queried';
return $lgsl_config['text']['pen'];
}
public function setTimestamp($type, $time) {
$this->_server['cache_time']->set($type, $time);
Expand All @@ -1003,9 +1005,9 @@ public function getTimestamps() {
public function checkTimestamps($request = "") {
global $lgsl_config;
$needed = "";
if (LGSL::requestHas($request, "s") && time() > ($this->getTimestamp(Timestamp::SERVER) + $lgsl_config['cache_time'])) { $needed .= "s"; }
if (LGSL::requestHas($request, "e") && time() > ($this->getTimestamp(Timestamp::EXTRAS) + $lgsl_config['cache_time'])) { $needed .= "e"; }
if (LGSL::requestHas($request, "p") && time() > ($this->getTimestamp(Timestamp::PLAYERS) + $lgsl_config['cache_time'])) { $needed .= "p"; }
foreach ([Timestamp::SERVER, Timestamp::EXTRAS, Timestamp::PLAYERS] as $stamp) {
if (LGSL::requestHas($request, $stamp) && time() > ($this->getTimestamp($stamp) + $lgsl_config['cache_time'])) { $needed .= $stamp; }
}
return $needed;
}
public function getZone() {
Expand All @@ -1027,6 +1029,9 @@ public function getStatus() {
if ($this->_server['password']) {
return self::PASSWORDED;
}
if (isset($this->_extra['_error'])) {
return self::ERROR;
}
if ($this->_base['status']) {
return self::ONLINE;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lgsl_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</tr>";

foreach ($server_list as $server) {
$lastupd = $server->getTimestamp(Timestamp::SERVER);
$lastupd = $server->getTimestampFormatted(Timestamp::SERVER);
$gamelink= LGSL::buildLink($uri, ["game" => $server->getGame()]);

$output .= "
Expand Down
14 changes: 7 additions & 7 deletions src/lgsl_protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -3044,19 +3044,19 @@ public function open(&$server = null) {
public function readRaw($length = 4096) {
if ($this->_isHttp()) {
$result = curl_exec($this->_stream);
$resultStatus = curl_getinfo($this->_stream, CURLINFO_HTTP_CODE);
if ($resultStatus != 200) {
$err = "Request failed: HTTP status code {$resultStatus}";
}
if (curl_errno($this->_stream)) {
$msg = "{$err}<br>" . curl_error($this->_stream);
if ($this->_server) {
$this->_server->setExtraValue('_error', 'Couldn\'t send request: ' . curl_error($this->_stream));
$this->_server->setExtraValue('_error', $msg);
$this->_server->setStatus(false);
return false;
} else {
return 'Couldn\'t send request: ' . curl_error($this->_stream);
return $msg;
}
} else {
$resultStatus = curl_getinfo($this->_stream, CURLINFO_HTTP_CODE);
if ($resultStatus != 200) {
$this->_server->setExtraValue('_error', "Request failed: HTTP status code: {$resultStatus}");
}
}
return $result;
} else {
Expand Down

0 comments on commit 0704bd6

Please sign in to comment.