From db67bb0b98fdf50340a564a44f3b94e18593e92c Mon Sep 17 00:00:00 2001 From: slawkens Date: Fri, 1 Jun 2018 18:23:48 +0200 Subject: [PATCH] * new configurable: status_interval (how often to fetch status from server) --- config.php | 5 +++++ system/status.php | 22 ++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/config.php b/config.php index 002fd3c4..255898e1 100644 --- a/config.php +++ b/config.php @@ -235,6 +235,11 @@ $config = array( 'status_port' => '', 'status_timeout' => 2, // how long to wait for the initial response from the server (default: 2 seconds) + // how often to connect to server and update status (default: every minute) + // if your status timeout in config.lua is bigger, that it will be used instead + // when server is offline, it will be checked every time web refreshes, ignoring this variable + 'status_interval' => 60, + // other 'anonymous_usage_statistics' => true, 'email_lai_sec_interval' => 60, // time in seconds between e-mails to one account from lost account interface, block spam diff --git a/system/status.php b/system/status.php index 3f15e99d..8a8124a7 100644 --- a/system/status.php +++ b/system/status.php @@ -29,16 +29,23 @@ else if(isset($config['lua']['status_port'])) { $status_port = $config['lua']['status_port']; } -$status_port = $config['lua']['statusPort']; - +// ip check if(isset($config['status_ip'][0])) { $status_ip = $config['status_ip']; - $status_port = $config['status_port']; } -else if(!isset($status_ip[0])) // try localhost if no ip specified +elseif(!isset($status_ip[0])) // try localhost if no ip specified { $status_ip = '127.0.0.1'; +} + +// port check +$status_port = $config['lua']['statusPort']; +if(isset($config['status_port'][0])) { + $status_port = $config['status_port']; +} +elseif(!isset($status_port[0])) // try 7171 if no ip specified +{ $status_port = 7171; } @@ -74,6 +81,9 @@ if(isset($config['lua']['statustimeout'])) // get status timeout from server config $status_timeout = eval('return ' . $config['lua']['statusTimeout'] . ';') / 1000 + 1; +if($status_timeout < $config['status_interval']) { + $status_timeout = $config['status_interval']; +} if($status['lastCheck'] + $status_timeout < time()) { updateStatus(); @@ -81,7 +91,7 @@ if($status['lastCheck'] + $status_timeout < time()) { function updateStatus() { global $db, $cache, $config, $status, $status_ip, $status_port; - + // get server status and save it to database $serverInfo = new OTS_ServerInfo($status_ip, $status_port); $serverStatus = $serverInfo->status(); @@ -109,7 +119,7 @@ function updateStatus() { else { $query = $db->query('SELECT COUNT(`id`) AS `playersTotal` FROM `players` WHERE `online` > 0'); } - + $status['playersTotal'] = 0; if($query->rowCount() > 0) {