From 586f2dcc305b4cc1b05e792dc37aea74743ce602 Mon Sep 17 00:00:00 2001 From: neonf Date: Wed, 11 Sep 2024 15:43:55 +0700 Subject: [PATCH] Added query limit (5) for unavailable servers --- src/lgsl_class.php | 11 +++++++---- src/lgsl_protocol.php | 10 ++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/lgsl_class.php b/src/lgsl_class.php index e8cdc78..0c4f96f 100644 --- a/src/lgsl_class.php +++ b/src/lgsl_class.php @@ -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}', @@ -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; @@ -669,7 +670,8 @@ function __construct($options = []) { ]; $this->_other = [ "zone" => null, - "comment" => '' + "comment" => '', + 'conn_tries' => 0 ]; } @@ -677,7 +679,6 @@ 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) { @@ -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}"; @@ -1214,4 +1218,3 @@ function toString() { $output .= " "; } - diff --git a/src/lgsl_protocol.php b/src/lgsl_protocol.php index f5836f1..5f2e475 100644 --- a/src/lgsl_protocol.php +++ b/src/lgsl_protocol.php @@ -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) { @@ -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; }