diff --git a/modules/gamemanager/server_monitor.php b/modules/gamemanager/server_monitor.php index 030acb82..98f9a4b8 100644 --- a/modules/gamemanager/server_monitor.php +++ b/modules/gamemanager/server_monitor.php @@ -29,6 +29,18 @@ require_once("modules/config_games/server_config_parser.php"); require_once("includes/refreshed.php"); require_once('includes/lib_remote.php'); +if (!function_exists('game_monitor_log')) { + function game_monitor_log($message, array $context = array()) + { + $prefix = '[GameMonitor] '; + if (!empty($context)) { + $context_json = json_encode($context, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + $message .= ' | context=' . $context_json; + } + error_log($prefix . $message); + } +} + function renderParam($param, $last_param, $param_access_enabled, $home_id) { global $db; @@ -148,7 +160,13 @@ function get_sync_name($server_xml) function exec_ogp_module() { global $db, $settings, $loggedInUserInfo; - echo "

". get_lang("game_monitor") ."

"; + $isAdminUser = $db->isAdmin( $_SESSION['user_id'] ); + game_monitor_log('Rendering game monitor', array( + 'user_id' => $_SESSION['user_id'], + 'is_admin' => $isAdminUser, + 'get' => $_GET, + )); + echo "

". get_lang("game_monitor") ."

"; $refresh = new refreshed(); set_time_limit(0); $stats_servers_online = 0; @@ -170,7 +188,7 @@ $home_info = $db->getGameHomeWithoutMods($home_id); $home_limit = $loggedInUserInfo["users_page_limit"]; } - $isAdmin = $db->isAdmin( $_SESSION['user_id'] ); + $isAdmin = $isAdminUser; if ( $isAdmin ) { @@ -192,6 +210,12 @@ $home_info = $db->getGameHomeWithoutMods($home_id); if( $server_homes === FALSE ) { + game_monitor_log('No server homes returned', array( + 'user_id' => $_SESSION['user_id'], + 'query_scope' => $isAdmin ? 'admin' : 'user_and_group', + 'home_cfg_id' => $home_cfg_id, + 'search' => $search_field, + )); // If there are no games, then there can not be any mods either. if (!empty($search_field)) { @@ -294,8 +318,17 @@ echo " isset($server_home['home_id']) ? $server_home['home_id'] : null, + 'mod_id' => isset($server_home['mod_id']) ? $server_home['mod_id'] : null, + 'ip' => isset($server_home['ip']) ? $server_home['ip'] : null, + 'home_cfg_file' => isset($server_home['home_cfg_file']) ? $server_home['home_cfg_file'] : null, + )); if( ( $show_all or isset($_GET['home_cfg_id']) ) AND ( !isset($server_home['ip']) or !isset($server_home['mod_id']) ) ){ $j++; + game_monitor_log('Skipping server home due to missing ip or mod_id', array( + 'home_id' => $server_home['home_id'] + )); continue; } // Count the number of servers. @@ -352,7 +385,12 @@ echo "
$server_home['home_id'], + 'config_path' => $config_path + )); + $server_xml = read_server_config($config_path); $mod = $server_home['mod_key']; // If query name does not exist use mod key instead. @@ -408,6 +446,12 @@ echo "
status_chk(); + game_monitor_log('Agent status check', array( + 'home_id' => $server_home['home_id'], + 'agent_ip' => $server_home['agent_ip'], + 'agent_port' => $server_home['agent_port'], + 'status' => $host_stat + )); if( $host_stat === 1) { @@ -498,6 +542,11 @@ echo "
Agent Offline"; + game_monitor_log('Agent offline', array( + 'home_id' => $server_home['home_id'], + 'agent_ip' => $server_home['agent_ip'], + 'agent_port' => $server_home['agent_port'] + )); } $user = $db->getUserById($server_home['user_id_main']); @@ -534,6 +583,11 @@ echo "
$_SESSION['user_id'], + 'total_servers' => $stats_servers, + 'online_servers' => $stats_servers_online + )); echo " @@ -590,5 +644,3 @@ echo "
Put the log file here
"; - -