Move status config to settings

This commit is contained in:
slawkens 2023-07-20 18:12:22 +02:00
parent 55a5ccdd1e
commit a8a2c72381
5 changed files with 71 additions and 26 deletions

View File

@ -166,23 +166,9 @@ $config = array(
// gifts/shop system // gifts/shop system
'gifts_system' => false, 'gifts_system' => false,
// support/system
'bug_report' => true, // this configurable has no effect, its always enabled
// last kills // last kills
'last_kills_limit' => 50, // max. number of deaths shown on the last kills page '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 panel
'admin_plugins_manage_enable' => 'yes', // you can disable possibility to upload and uninstall plugins, for security '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 // enable support for plain php pages in admin panel, for security

View File

@ -426,7 +426,9 @@ class Settings implements ArrayAccess
break; break;
case 'number': case 'number':
$ret['value'] = (int)$ret['value']; if (!isset($ret['step']) || (int)$ret['step'] == 1) {
$ret['value'] = (int)$ret['value'];
}
break; break;
default: default:

View File

@ -57,7 +57,7 @@ class OTS_ServerInfo
private function send(OTS_Buffer $packet) private function send(OTS_Buffer $packet)
{ {
// connects to server // 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 connected then checking statistics
if($socket) if($socket)

View File

@ -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', 'desc' => 'Time To Live for Visitors Counter. In other words - how long user will be marked as online. In Minutes',
'default' => 10, 'default' => 10,
'show_if' => [ 'show_if' => [
'visitors_counter'=> '=', 'true' 'visitors_counter', '=', 'true'
] ]
], ],
'views_counter' => [ 'views_counter' => [
@ -787,5 +787,60 @@ Sent by MyAAC,<br/>
'type' => 'boolean', 'type' => 'boolean',
'default' => false, '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.<br/>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',
]
],
], ],
]; ];

View File

@ -17,7 +17,7 @@ $status['lastCheck'] = 0;
$status['uptime'] = '0h 0m'; $status['uptime'] = '0h 0m';
$status['monsters'] = 0; $status['monsters'] = 0;
if(config('status_enabled') === false) { if(setting('core.status_enabled') === false) {
return; return;
} }
@ -37,9 +37,10 @@ else if(isset($config['lua']['status_port'])) {
} }
// ip check // 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 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 // port check
$status_port = $config['lua']['statusPort']; $status_port = $config['lua']['statusPort'];
if(isset($config['status_port'][0])) { $settingPort = setting('core.status_port');
$status_port = $config['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; $status_port = 7171;
} }
@ -94,9 +96,9 @@ if(isset($config['lua']['statustimeout']))
// get status timeout from server config // get status timeout from server config
$status_timeout = eval('return ' . $config['lua']['statusTimeout'] . ';') / 1000 + 1; $status_timeout = eval('return ' . $config['lua']['statusTimeout'] . ';') / 1000 + 1;
$status_interval = @$config['status_interval']; $status_interval = setting('core.status_interval');
if($status_interval && $status_timeout < $config['status_interval']) { if($status_interval && $status_timeout < $status_interval) {
$status_timeout = $config['status_interval']; $status_timeout = $status_interval;
} }
if($status['lastCheck'] + $status_timeout < time()) { if($status['lastCheck'] + $status_timeout < time()) {