From a8a2c72381a6f1b0a487676344dcb88c41a45230 Mon Sep 17 00:00:00 2001 From: slawkens Date: Thu, 20 Jul 2023 18:12:22 +0200 Subject: [PATCH] Move status config to settings --- config.php | 14 -------- system/libs/Settings.php | 4 ++- system/libs/pot/OTS_ServerInfo.php | 2 +- system/settings.php | 57 +++++++++++++++++++++++++++++- system/status.php | 20 ++++++----- 5 files changed, 71 insertions(+), 26 deletions(-) diff --git a/config.php b/config.php index c9abe001..50c333f1 100644 --- a/config.php +++ b/config.php @@ -166,23 +166,9 @@ $config = array( // gifts/shop system 'gifts_system' => false, - // support/system - 'bug_report' => true, // this configurable has no effect, its always enabled - // last kills 'last_kills_limit' => 50, // max. number of deaths shown on the last kills page - // status, took automatically from config file if empty - 'status_enabled' => true, // you can disable status checking by settings this to "false" - 'status_ip' => '', - 'status_port' => '', - 'status_timeout' => 2.0, // 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, - // admin panel 'admin_plugins_manage_enable' => 'yes', // you can disable possibility to upload and uninstall plugins, for security // enable support for plain php pages in admin panel, for security diff --git a/system/libs/Settings.php b/system/libs/Settings.php index 3244069a..eb29667b 100644 --- a/system/libs/Settings.php +++ b/system/libs/Settings.php @@ -426,7 +426,9 @@ class Settings implements ArrayAccess break; case 'number': - $ret['value'] = (int)$ret['value']; + if (!isset($ret['step']) || (int)$ret['step'] == 1) { + $ret['value'] = (int)$ret['value']; + } break; default: diff --git a/system/libs/pot/OTS_ServerInfo.php b/system/libs/pot/OTS_ServerInfo.php index fd06749e..4a1a932a 100644 --- a/system/libs/pot/OTS_ServerInfo.php +++ b/system/libs/pot/OTS_ServerInfo.php @@ -57,7 +57,7 @@ class OTS_ServerInfo private function send(OTS_Buffer $packet) { // connects to server - $socket = @fsockopen($this->server, $this->port, $error, $message, config('status_timeout')); + $socket = @fsockopen($this->server, $this->port, $error, $message, setting('core.status_timeout')); // if connected then checking statistics if($socket) diff --git a/system/settings.php b/system/settings.php index 5a8e19de..13a342f3 100644 --- a/system/settings.php +++ b/system/settings.php @@ -118,7 +118,7 @@ return [ 'desc' => 'Time To Live for Visitors Counter. In other words - how long user will be marked as online. In Minutes', 'default' => 10, 'show_if' => [ - 'visitors_counter'=> '=', 'true' + 'visitors_counter', '=', 'true' ] ], 'views_counter' => [ @@ -787,5 +787,60 @@ Sent by MyAAC,
'type' => 'boolean', 'default' => false, ], + [ + 'type' => 'category', + 'title' => 'Status', + ], + [ + 'type' => 'section', + 'title' => 'Server Status' + ], + 'status_enabled' => [ + 'name' => 'Enable Server Status', + 'type' => 'boolean', + 'desc' => 'You can disable status checking here', + 'default' => true, + ], + 'status_ip' => [ + 'name' => 'Status IP', + 'type' => 'text', + 'desc' => 'Leave empty to get automatically from config', + 'default' => '127.0.0.1', + 'show_if' => [ + 'status_enabled', '=', 'true', + ] + ], + 'status_port' => [ + 'name' => 'Status Port', + 'type' => 'number', + 'min' => 0, + 'desc' => 'Leave empty to get automatically from config', + 'default' => 7171, + 'show_if' => [ + 'status_enabled', '=', 'true', + ] + ], + 'status_timeout' => [ + 'name' => 'Status Timeout', + 'type' => 'number', + 'min' => 0, + 'max' => 10, // more than 10 seconds waiting makes no sense + 'step' => 0.1, + 'desc' => 'How long to wait for the initial response from the server', + 'default' => 2.0, + 'show_if' => [ + 'status_enabled', '=', 'true', + ] + ], + 'status_interval' => [ + 'name' => 'Status Interval', + 'type' => 'number', + 'min' => 0, + 'desc' => 'How often to connect to server and update status.
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', + 'default' => 60, + 'show_if' => [ + 'status_enabled', '=', 'true', + ] + ], ], ]; diff --git a/system/status.php b/system/status.php index 86cba2ed..310e4127 100644 --- a/system/status.php +++ b/system/status.php @@ -17,7 +17,7 @@ $status['lastCheck'] = 0; $status['uptime'] = '0h 0m'; $status['monsters'] = 0; -if(config('status_enabled') === false) { +if(setting('core.status_enabled') === false) { return; } @@ -37,9 +37,10 @@ else if(isset($config['lua']['status_port'])) { } // ip check -if(isset($config['status_ip'][0])) +$settingIP = setting('core.status_ip'); +if(isset($settingIP[0])) { - $status_ip = $config['status_ip']; + $status_ip = $settingIP; } elseif(!isset($status_ip[0])) // try localhost if no ip specified { @@ -48,10 +49,11 @@ elseif(!isset($status_ip[0])) // try localhost if no ip specified // port check $status_port = $config['lua']['statusPort']; -if(isset($config['status_port'][0])) { - $status_port = $config['status_port']; +$settingPort = setting('core.status_port'); +if(isset($settingPort[0])) { + $status_port = $settingPort; } -elseif(!isset($status_port[0])) // try 7171 if no ip specified +elseif(!isset($status_port[0])) // try 7171 if no port specified { $status_port = 7171; } @@ -94,9 +96,9 @@ if(isset($config['lua']['statustimeout'])) // get status timeout from server config $status_timeout = eval('return ' . $config['lua']['statusTimeout'] . ';') / 1000 + 1; -$status_interval = @$config['status_interval']; -if($status_interval && $status_timeout < $config['status_interval']) { - $status_timeout = $config['status_interval']; +$status_interval = setting('core.status_interval'); +if($status_interval && $status_timeout < $status_interval) { + $status_timeout = $status_interval; } if($status['lastCheck'] + $status_timeout < time()) {