Skip to content

Commit

Permalink
Added query limit (5) for unavailable servers
Browse files Browse the repository at this point in the history
  • Loading branch information
tltneon committed Sep 11, 2024
1 parent 2804900 commit 586f2dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lgsl_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ static public function getStatistics() {
function saveServer(&$server) {
global $lgsl_config;
$packed_cache = $this->escape_string(base64_encode(serialize($server->toArray())));
$status = (int) ($server->getStatus() === Server::ONLINE);
$status = (int) $server->isOnline();
$this->execute("
UPDATE `{$lgsl_config['db']['prefix']}{$lgsl_config['db']['table']}`
SET `status`='{$status}',
Expand Down Expand Up @@ -458,6 +458,7 @@ function &unserializeData(array &$data): array {
$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'];
$server['s']['cache_time'] = new Timestamp($data['cache_time']);
}
return $server;
Expand Down Expand Up @@ -669,15 +670,15 @@ function __construct($options = []) {
];
$this->_other = [
"zone" => null,
"comment" => ''
"comment" => '',
'conn_tries' => 0
];
}

public function queryCached($request = 'seph') {
$request = "{$request}c"; // cached by default
$db = LGSL::db();
$db->loadServer($this);
global $lgsl_config;
$needed = $this->checkTimestamps($request);
if (LGSL::requestHas($request, "h")) { $needed .= "h"; }
if ($needed) {
Expand Down Expand Up @@ -1049,6 +1050,9 @@ public function checkTimestamps($request = "") {
public function getZone() {
return isset($this->_other['zone']) ? $this->_other['zone'] : "";
}
public function getConnectionTries() {
return isset($this->_other['conn_tries']) ? $this->_other['conn_tries'] : 0;
}
public function addOption($name, $value) {
if (isset($this->_extra[$name])) {
$this->_extra[$name] .= "\n{$value}";
Expand Down Expand Up @@ -1214,4 +1218,3 @@ function toString() {
$output .= "
</select>";
}

10 changes: 10 additions & 0 deletions src/lgsl_protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,14 @@ public function execute(): int {
];
$this->_server->setTimestamp("sep", time());
}
$this->_data['o']['conn_tries'] = 0;
} else {
$this->_data['o']['conn_tries'] = $this->_server->getConnectionTries() + 1;
if ($this->_data['o']['conn_tries'] > 4) {
$this->_server->setTimestamp("sep", time());
$this->_data['o']['conn_tries'] = 5;
}
$this->_server->updateValues($this->_data);
}
$this->_data['o']['time_execution'] = $time - microtime(true);
if ($status !== $this::NO_RESPOND) {
Expand All @@ -511,6 +519,8 @@ public function execute(): int {
$this->_server->addOption("_error", "Probably protocol mistake: " . static::class);
}
$this->_server->updateValues($this->_data);
} else {
$this->_server->addOption("_error", "Successful ping but no correct answer");
}
return $status;
}
Expand Down

0 comments on commit 586f2dc

Please sign in to comment.