public function query($srv_arr) { // No GameQ type - try a basic TCP check if (empty($srv_arr[0]['gameq_name']) || $srv_arr[0]['gameq_name'] == 'none') { // Setup language require DOCROOT . '/lang.php'; $results = array(); // Offline / Not responding if (!fsockopen($srv_arr[0]['ip'], $srv_arr[0]['port'], $errno, $errstr, 4)) { $srv_status = strtolower($lang['offline']); } else { $srv_status = strtolower($lang['online']); } // Add status $srv_id = $srv_arr[0]['id']; $results[$srv_id]['gq_online'] = $srv_status; } else { require DOCROOT . '/includes/GameQ/GameQ.php'; // Have to specify query port for some servers if ($srv_arr[0]['gameq_name'] == 'mta') { $srv_arr[0]['port'] = '22126'; } $server = array('id' => $srv_arr[0]['id'], 'type' => $srv_arr[0]['gameq_name'], 'host' => $srv_arr[0]['ip'] . ':' . $srv_arr[0]['port']); // Call the class, and add your servers. $gq = new GameQ(); $gq->addServer($server); // You can optionally specify some settings $gq->setOption('timeout', 5); // Seconds #$gq->setOption('debug', TRUE); $gq->setFilter('normalise'); $results = $gq->requestData(); } return $results; }
/** * Create a new instance of this class */ public static function factory() { // Create a new instance self::$instance = new self(); // Return this new instance return self::$instance; }
protected function queryServer($server, &$response) { gameservers_include_library('GameQ.php', 'gameq'); $gq = new GameQ(); $gq->addServer($server->id, array($server->config['query']['gametype'], $server->hostname, $server->port)); //$gq->setOption('timeout', 200); // Send requests, and parse the data $gq->setFilter('normalise'); //$gq->setFilter('sortplayers', 'name'); $results = $gq->requestData(); if (isset($results[$server->id])) { $data = $results[$server->id]; $response['raw'] = $data; $response['address'] = $data['gq_address']; $response['port'] = $data['gq_port']; $response['online'] = $data['gq_online'] ? TRUE : FALSE; $response['protocol'] = $data['gq_prot']; $response['game'] = $data['gq_mod']; $response['servername'] = $data['gq_hostname']; $response['mapname'] = $data['gq_mapname']; $response['numplayers'] = $data['gq_numplayers']; $response['maxplayers'] = $data['gq_maxplayers']; $response['extra'] = array(); foreach ($data as $key => $value) { if (strpos($key, 'gq_') !== 0) { $response['extra'][$key] = $value; } } if (!empty($data['players'])) { foreach ($data['players'] as $player_info) { if ($name = $player_info['name']) { $player = new stdClass(); $player->name = check_plain($name); $player->score = 0; $player->time = 0; $response['players'][] = $player; } } } return TRUE; } return FALSE; }
function check_gs($servers) { $fp = fsockopen("www.google.com", 80, $errno, $errstr, 5); if ($fp) { $gq = new GameQ(); // or $gq = GameQ::factory(); $gq->setOption('timeout', 5); // Seconds $gq->setOption('debug', TRUE); $gq->setFilter('normalise'); $gq->addServers($servers); $results = $gq->requestData(); if ($results['serv']["gq_online"] == 1) { return $results; } else { $gq = new GameQ(); // or $gq = GameQ::factory(); $gq->setOption('timeout', 5); // Seconds $gq->setOption('debug', TRUE); $gq->setFilter('normalise'); $gq->addServers($servers); $results = $gq->requestData(); return $results; } } }
if ($num_of_servers < $numberservers_to_skip_query) { $query_cache_life = (isset($settings['query_cache_life']) and is_numeric($settings['query_cache_life'])) ? $settings['query_cache_life'] : 30; $ip_id = $server_home['ip_id']; $statusCache = $db->getServerStatusCache($ip_id, $port); if (!empty($statusCache) and date('YmdHis', $statusCache['date_timestamp'] + $query_cache_life) >= date('YmdHis')) { $results = $statusCache; } else { require_once 'protocol/GameQ/GameQ.php'; $port = $server_home['port']; if ($server_home['use_nat'] == 1) { $ip = $server_home['agent_ip']; } else { $ip = $server_home['ip']; } $query_port = get_query_port($server_xml, $port); $gq = new GameQ(); $servers = array(array('id' => 'server', 'type' => (string) $server_xml->gameq_query_name, 'host' => $ip . ":" . $query_port)); $gq->addServers($servers); $gq->setOption('timeout', 4); $gq->setOption('debug', FALSE); $gq->setFilter('normalise'); $results = $gq->requestData(); $db->saveServerStatusCache($ip_id, $port, $results); } if ($results['server']['gq_online'] == 1) { $xml_mod = xml_get_mod($server_xml, $results['server']['gq_mod']); $status = "online"; // Some functions to print the results $players = $results['server']['gq_numplayers']; $playersmax = $results['server']['gq_maxplayers']; $name = $results['server']['gq_hostname'];
<?php $yes = '<font color="#00AA00">' . $lang->get('yes') . '</font>'; $no = '<font color="#AA0000">' . $lang->get('no') . '</font>'; require_once './mod/default/server/gameq/GameQ.php'; $gq = new GameQ(); $servers[$_GET['gameq']] = array($_GET['gameq'], $_GET['ipadress'], $_GET['port']); $gq->addServers($servers); @($data = $gq->requestData()); if ($data[$_GET['gameq']]['gq_online']) { echo $yes; } else { echo $no; }
function exec_ogp_module() { global $db; global $view; $home_id = $_REQUEST['home_id']; $isAdmin = $db->isAdmin($_SESSION['user_id']); if ($isAdmin) { $home_info = $db->getGameHome($home_id); } else { $home_info = $db->getUserGameHome($_SESSION['user_id'], $home_id); } if ($home_info == FALSE) { print_failure(get_lang('no_rights_to_start_server')); echo "<table class='center'><tr><td><a href='?m=gamemanager&p=game_monitor&home_id-mod_id-ip-port=" . $home_info['home_id'] . "-" . $home_info['mod_id'] . "-" . $_REQUEST['ip'] . "-" . $_REQUEST['port'] . "'><< " . get_lang('back') . "</a></td></tr></table>"; return; } $mod_id = $_REQUEST['mod_id']; if (!array_key_exists($mod_id, $home_info['mods'])) { print_failure("Unable to retrieve mod information from database."); return; } echo "<h2>"; echo empty($home_info['home_name']) ? get_lang('not_available') : $home_info['home_name']; echo "</h2>"; require_once 'includes/lib_remote.php'; $remote = new OGPRemoteLibrary($home_info['agent_ip'], $home_info['agent_port'], $home_info['encryption_key']); $server_xml = read_server_config(SERVER_CONFIG_LOCATION . "/" . $home_info['home_cfg_file']); if (!$server_xml) { echo "<table class='center'><tr><td><a href='?m=gamemanager&p=game_monitor&home_id-mod_id-ip-port=" . $home_info['home_id'] . "-" . $home_info['mod_id'] . "-" . $_REQUEST['ip'] . "-" . $_REQUEST['port'] . "'><< " . get_lang('back') . "</a></td></tr></table>"; return; } // It compares ip and port on POST with the pair on DB for security reasons (URL HACKING) $home_id = $home_info['home_id']; $ip_info = $db->getHomeIpPorts($home_id); foreach ($ip_info as $ip_ports_row) { if ($ip_ports_row['ip'] == $_REQUEST['ip'] && $ip_ports_row['port'] == $_REQUEST['port']) { $ip = $ip_ports_row['ip']; $port = $ip_ports_row['port']; } } if (!isset($ip) or !isset($port)) { echo "<h2>" . get_lang_f('ip_port_pair_not_owned') . "</h2>"; echo "<table class='center'><tr><td><a href='?m=gamemanager&p=game_monitor&home_id-mod_id-ip-port={$home_id}-{$mod_id}-{$ip}-{$port}'><< " . get_lang('back') . "</a></td></tr></table>"; return; } if (isset($server_xml->console_log)) { $log_retval = $remote->remote_readfile($home_info['home_path'] . '/' . $server_xml->console_log, $home_log); } else { $log_retval = $remote->get_log(OGP_SCREEN_TYPE_HOME, $home_info['home_id'], clean_path($home_info['home_path'] . "/" . $server_xml->exe_location), $home_log); } function getLastLines($string, $n = 1) { $lines = explode("\n", $string); $lines = array_slice($lines, -$n); return implode("\n", $lines); } $home_log = getLastLines($home_log, 40); if ($log_retval > 0) { if ($log_retval == 2) { print_failure(get_lang('server_not_running_log_found')); } echo "<pre style='background:black;color:white;'>" . $home_log . "</pre>"; if ($log_retval == 2) { return; } } else { print_failure(get_lang_f('unable_to_get_log', $log_retval)); } // If game is not supported by lgsl we skip the lgsl checks and // assume successfull start. if ($home_info['use_nat'] == 1) { $query_ip = $home_info['agent_ip']; } else { $query_ip = $ip; } $running = $remote->is_screen_running(OGP_SCREEN_TYPE_HOME, $home_info['home_id']); if ($server_xml->lgsl_query_name) { require 'protocol/lgsl/lgsl_protocol.php'; $get_q_and_s = lgsl_port_conversion((string) $server_xml->lgsl_query_name, $port, "", ""); //Connection port $c_port = $get_q_and_s['0']; //query port $q_port = $get_q_and_s['1']; //software port $s_port = $get_q_and_s['2']; $data = lgsl_query_live((string) $server_xml->lgsl_query_name, $query_ip, $c_port, $q_port, $s_port, "sa"); if ($data['b']['status'] == "0") { $running = FALSE; } } elseif ($server_xml->gameq_query_name) { require 'protocol/GameQ/GameQ.php'; $query_port = get_query_port($server_xml, $port); $servers = array(array('id' => 'server', 'type' => (string) $server_xml->gameq_query_name, 'host' => $query_ip . ":" . $query_port)); $gq = new GameQ(); $gq->addServers($servers); $gq->setOption('timeout', 4); $gq->setOption('debug', FALSE); $gq->setFilter('normalise'); $game = $gq->requestData(); if (!$game['server']['gq_online']) { $running = FALSE; } } if (!$running) { if (!isset($_GET['retry'])) { $retry = 0; } else { $retry = $_GET['retry']; } if ($retry >= 5) { echo "<p>" . get_lang('server_running_not_responding') . "\n\t\t\t<a href=?m=gamemanager&p=stop&home_id=" . $home_info['home_id'] . "&ip=" . $ip . "&port=" . $port . ">" . get_lang('already_running_stop_server') . ".</a></p>"; echo "<table class='center'><tr><td><a href='?m=gamemanager&p=game_monitor&home_id-mod_id-ip-port={$home_id}-{$mod_id}-{$ip}-{$port}'><< " . get_lang('back') . "</a></td></tr></table>"; } echo "</b>Retry #" . $retry . ".</b>"; $retry++; print "<p class='note'>" . get_lang('starting_server') . "</p>"; $view->refresh("?m=gamemanager&p=start&refresh&ip={$ip}&port={$port}&home_id={$home_id}&mod_id={$mod_id}&retry=" . $retry, 3); return; } print_success(get_lang('server_started')); $ip_id = $db->getIpIdByIp($ip); $db->delServerStatusCache($ip_id, $port); $view->refresh("?m=gamemanager&p=game_monitor&home_id-mod_id-ip-port={$home_id}-{$mod_id}-{$ip}-{$port}"); return; }
function exec_ogp_module() { global $view, $db; $ip = $_REQUEST['ip']; $port = $_REQUEST['port']; $home_id = $_REQUEST['home_id']; $user_id = $_SESSION['user_id']; $home_id = $_REQUEST['home_id']; $isAdmin = $db->isAdmin($_SESSION['user_id']); if ($isAdmin) { $home_info = $db->getGameHome($home_id); } else { $home_info = $db->getUserGameHome($_SESSION['user_id'], $home_id); } require_once 'includes/lib_remote.php'; $remote = new OGPRemoteLibrary($home_info['agent_ip'], $home_info['agent_port'], $home_info['encryption_key']); $mod_id = $_REQUEST['mod_id']; if ($home_info === FALSE) { print_failure(get_lang('no_rights_to_stop_server')); return; } echo "<h2>"; echo empty($home_info['home_name']) ? get_lang('not_available') : $home_info['home_name']; echo "</h2>"; $server_xml = read_server_config(SERVER_CONFIG_LOCATION . "/" . $home_info['home_cfg_file']); if (!$server_xml) { echo create_back_button("gamemanager", "game_monitor"); return; } $rserver = $db->getRemoteServerById($home_info['remote_server_id']); if (empty($rserver)) { print_failure("" . get_lang('not_found_server') . " " . $home_info['remote_server_id'] . "."); } else { if (isset($_REQUEST['refresh'])) { if (isset($server_xml->console_log)) { $log_retval = $remote->remote_readfile($home_info['home_path'] . '/' . $server_xml->console_log, $home_log); } else { $log_retval = $remote->get_log(OGP_SCREEN_TYPE_HOME, $home_info['home_id'], clean_path($home_info['home_path'] . "/" . $server_xml->exe_location), $home_log); } function getLastLines($string, $n = 1) { $lines = explode("\n", $string); $lines = array_slice($lines, -$n); return implode("\n", $lines); } $home_log = getLastLines($home_log, 40); if ($log_retval > 0) { if ($log_retval == 2) { print_failure(get_lang('server_not_running_log_found')); } echo "<pre style='background:black;color:white;'>" . $home_log . "</pre>"; if ($log_retval == 2) { return; } } else { print_failure(get_lang_f('unable_to_get_log', $log_retval)); } // If game is not supported by lgsl we skip the lgsl checks and // assume successfull start. if ($home_info['use_nat'] == 1) { $query_ip = $home_info['agent_ip']; } else { $query_ip = $ip; } $running = TRUE; if ($server_xml->lgsl_query_name) { require 'protocol/lgsl/lgsl_protocol.php'; $get_q_and_s = lgsl_port_conversion((string) $server_xml->lgsl_query_name, $port, "", ""); //Connection port $c_port = $get_q_and_s['0']; //query port $q_port = $get_q_and_s['1']; //software port $s_port = $get_q_and_s['2']; $data = lgsl_query_live((string) $server_xml->lgsl_query_name, $query_ip, $c_port, $q_port, $s_port, "sa"); if ($data['b']['status'] == "0") { $running = FALSE; } } elseif ($server_xml->gameq_query_name) { require 'protocol/GameQ/GameQ.php'; $query_port = get_query_port($server_xml, $port); $servers = array(array('id' => 'server', 'type' => (string) $server_xml->gameq_query_name, 'host' => $query_ip . ":" . $query_port)); $gq = new GameQ(); $gq->addServers($servers); $gq->setOption('timeout', 4); $gq->setOption('debug', FALSE); $gq->setFilter('normalise'); $game = $gq->requestData(); if (!$game['server']['gq_online']) { $running = FALSE; } } if (!$running) { if (!isset($_GET['retry'])) { $retry = 0; } else { $retry = $_GET['retry']; } if ($retry >= 5) { echo "<p>" . get_lang('server_running_not_responding') . "\n\t\t\t\t\t<a href=?m=gamemanager&p=stop&home_id=" . $home_info['home_id'] . "&ip=" . $ip . "&port=" . $port . ">" . get_lang('already_running_stop_server') . ".</a></p>"; echo "<table class='center'><tr><td><a href='?m=gamemanager&p=game_monitor&home_id-mod_id-ip-port={$home_id}-{$mod_id}-{$ip}-{$port}'><< " . get_lang('back') . "</a></td></tr></table>"; } echo "</b>Retry #" . $retry . ".</b>"; $retry++; print "<p class='note'>" . get_lang('starting_server') . "</p>"; $view->refresh("?m=gamemanager&p=start&refresh&ip={$ip}&port={$port}&home_id={$home_id}&mod_id={$mod_id}&retry=" . $retry, 3); return; } print_success(get_lang_f('server_restarted', $home_info['home_name'])); $ip_id = $db->getIpIdByIp($ip); $db->delServerStatusCache($ip_id, $port); $view->refresh("?m=gamemanager&p=game_monitor&home_id-mod_id-ip-port=" . $home_info['home_id'] . "-" . $home_info['mod_id'] . "-" . $_REQUEST['ip'] . "-" . $_REQUEST['port']); echo "<p>" . get_lang('follow_server_status') . " <a href='?m=gamemanager&p=game_monitor&home_id-mod_id-ip-port=" . $home_info['home_id'] . "-" . $home_info['mod_id'] . "-" . $_REQUEST['ip'] . "-" . $_REQUEST['port'] . "'>" . get_lang('game_monitor') . "</a> " . get_lang('page') . ".</p>"; return; } else { if ($server_xml->replace_texts) { $server_home = $home_info; if (isset($server_xml->lgsl_query_name)) { require_once 'protocol/lgsl/lgsl_protocol.php'; } require_once "modules/gamemanager/cfg_text_replace.php"; } $control_type = isset($server_xml->control_protocol_type) ? $server_xml->control_protocol_type : ""; $run_dir = isset($server_xml->exe_location) ? $server_xml->exe_location : ""; $last_param = json_decode($home_info['last_param'], True); $cli_param_data['GAME_TYPE'] = $home_info['mods'][$mod_id]['mod_key']; $cli_param_data['IP'] = $ip; $cli_param_data['PORT'] = $port; $cli_param_data['HOSTNAME'] = $home_info['home_name']; $cli_param_data['PID_FILE'] = "ogp_game_startup.pid"; $os = $remote->what_os(); // Linux if (preg_match("/Linux/", $os)) { $cli_param_data['BASE_PATH'] = $home_info['home_path']; $cli_param_data['HOME_PATH'] = $home_info['home_path']; $cli_param_data['SAVE_PATH'] = $home_info['home_path']; $cli_param_data['OUTPUT_PATH'] = $home_info['home_path']; $cli_param_data['USER_PATH'] = $home_info['home_path']; } elseif (preg_match("/CYGWIN/", $os)) { $home_path_win = $remote->exec("cygpath -w " . $home_info['home_path']); $home_path_win = str_replace("\\", "\\\\", $home_path_win); $home_path_win = trim($home_path_win); $cli_param_data['BASE_PATH'] = $home_path_win; $cli_param_data['HOME_PATH'] = $home_path_win; $cli_param_data['SAVE_PATH'] = $home_path_win; $cli_param_data['OUTPUT_PATH'] = $home_path_win; $cli_param_data['USER_PATH'] = $home_path_win; } if ($server_xml->protocol == "gameq") { $cli_param_data['QUERY_PORT'] = get_query_port($server_xml, $port); } elseif ($server_xml->protocol == "lgsl") { require 'protocol/lgsl/lgsl_protocol.php'; $get_ports = lgsl_port_conversion((string) $server_xml->lgsl_query_name, $port, "", ""); $cli_param_data['QUERY_PORT'] = $get_ports['1']; } elseif ($server_xml->protocol == "teamspeak3") { $cli_param_data['QUERY_PORT'] = "10011"; } $cli_param_data['MAP'] = empty($last_param['map']) ? "" : $last_param['map']; $cli_param_data['PLAYERS'] = empty($last_param['players']) ? $home_info['mods'][$mod_id]['max_players'] : $last_param['players']; $start_cmd = ""; // If the template is empty then these are not needed. if ($server_xml->cli_template) { $start_cmd = $server_xml->cli_template; if ($server_xml->cli_params) { foreach ($server_xml->cli_params->cli_param as $cli) { // If s is found the param is seperated with space $add_space = preg_match("/s/", $cli['options']) > 0 ? " " : ""; $cli_value = $cli_param_data[(string) $cli['id']]; // If q is found we add quotes around the value. if (preg_match("/q/", $cli['options']) > 0) { $cli_value = "\"" . $cli_value . "\""; } $start_cmd = preg_replace("/%" . $cli['id'] . "%/", $cli['cli_string'] . $add_space . $cli_value, $start_cmd); } } } if ($isAdmin) { $home_info['access_rights'] = "ufpet"; } $param_access_enabled = preg_match("/p/", $home_info['access_rights']) > 0 ? TRUE : FALSE; if ($param_access_enabled && isset($last_param)) { foreach ($server_xml->server_params->param as $param) { foreach ($last_param as $paramKey => $paramValue) { if (!isset($paramValue)) { $paramValue = (string) $param->default; } if ($param['key'] == $paramKey) { if (0 == strlen($paramValue)) { continue; } if ($param['key'] == $paramValue) { // it's a checkbox $new_param = $paramKey; } elseif ($param->option == "ns" or $param->options == "ns") { $new_param = $paramKey . $paramValue; } else { $new_param = $paramKey . ' "' . $paramValue . '"'; } if ($param['id'] == NULL || $param['id'] == "") { $start_cmd .= ' ' . $new_param; } else { $start_cmd = preg_replace("/%" . $param['id'] . "%/", $new_param, $start_cmd); } } } $start_cmd = preg_replace("/%" . $param['id'] . "%/", '', $start_cmd); } } $extra_param_access_enabled = preg_match("/e/", $home_info['access_rights']) > 0 ? TRUE : FALSE; if (array_key_exists('extra', $last_param) && $extra_param_access_enabled) { $extra_default = $last_param['extra']; } else { $extra_default = $home_info['mods'][$mod_id]['extra_params']; } $start_cmd .= " " . $extra_default; $remote_retval = $remote->remote_restart_server($home_info['home_id'], $ip, $port, $server_xml->control_protocol, $home_info['control_password'], $control_type, $home_info['home_path'], $server_xml->server_exec_name, $run_dir, $start_cmd, $home_info['cpu_affinity'], $home_info['nice']); $db->logger(get_lang_f('server_restarted', $home_info['home_name']) . "({$ip}:{$port})"); if ($remote_retval === 1) { print "<p class='note'>" . get_lang('restarting_server') . "</p>"; $view->refresh("?m=gamemanager&p=restart&refresh&ip={$ip}&port={$port}&home_id={$home_id}&mod_id={$mod_id}", 3); return; } else { if ($remote_retval === -1) { print_failure(get_lang('server_cant_start')); $view->refresh("?m=gamemanager&p=game_monitor&home_id-mod_id-ip-port=" . $home_info['home_id'] . "-" . $home_info['mod_id'] . "-" . $ip . "-" . $port, 3); } else { if ($remote_retval === -2) { print_failure(get_lang('server_cant_stop')); $view->refresh("?m=gamemanager&p=game_monitor&home_id-mod_id-ip-port=" . $home_info['home_id'] . "-" . $home_info['mod_id'] . "-" . $ip . "-" . $port, 3); } else { $screen_running = $remote->is_screen_running(OGP_SCREEN_TYPE_HOME, $home_info['home_id']); if ($screen_running == 1) { print "<p class='note'>" . get_lang('restarting_server') . "</p>"; $view->refresh("?m=gamemanager&p=restart&refresh&ip={$ip}&port={$port}&home_id={$home_id}&mod_id={$mod_id}", 3); return; } else { print_failure("" . get_lang('error_occured_remote_host') . ".{$remote_retval}"); $view->refresh("?m=gamemanager&p=game_monitor&home_id-mod_id-ip-port=" . $home_info['home_id'] . "-" . $home_info['mod_id'] . "-" . $ip . "-" . $port, 3); } } } } } } }
<?php error_reporting(E_ALL); require_once 'GameQ.php'; // Define your servers, // see list.php for all supported games and identifiers. $servers = array('server 1' => array('quake3', '194.109.69.61'), 'server 2' => array('cssource', '88.191.89.15', 27015), 'server 3' => array('bf2142', '194.109.69.21'), 'server 4' => array('ts3', 'voice.planetteamspeak.com')); // Call the class, and add your servers. $gq = new GameQ(); $gq->addServers($servers); // You can optionally specify some settings $gq->setOption('timeout', 200); // You can optionally specify some output filters, // these will be applied to the results obtained. $gq->setFilter('normalise'); $gq->setFilter('sortplayers', 'gq_ping'); // Send requests, and parse the data $results = $gq->requestData(); // Some functions to print the results function print_results($results) { foreach ($results as $id => $data) { printf("<h2>%s</h2>\n", $id); print_table($data); } } function print_table($data) { $gqs = array('gq_online', 'gq_address', 'gq_port', 'gq_prot', 'gq_type'); if (!$data['gq_online']) { printf("<p>The server did not respond within the specified time.</p>\n");
$allServersArray[] = $serverBatchArray; $serverBatchArray = array(); $i = 1; } $totalCount++; } else { print "No GameQ found for {$row2['shorten']}\r\n"; } } // Set and used in order to prevent that GS from different roots are checked together $rootID = $row['root_id']; } $allServersArray[] = $serverBatchArray; print "Checking {$totalCount} server(s) with GameQ query\r\n"; foreach ($allServersArray as $servers) { $gq = new GameQ(); $gq->setOption('timeout', 60); if (isset($dbConnect['debug']) and $dbConnect['debug'] == 1) { $gq->setOption('debug', true); } $gq->setFilter('normalise'); $gq->addServers($servers); foreach ($gq->requestData() as $switchID => $v) { unset($userid, $resellerid, $lendserver, $stopserver, $doNotRestart); $lid = 0; $elapsed = 0; $shutdownemptytime = 0; $notified = 0; $query = $sql->prepare("SELECT s.`id` AS `serverID`,t.`description`,t.`gamebinary`,l.`id` AS `lend_id`,l.`started` AS `lend_started`,g.* FROM `gsswitch` g INNER JOIN `serverlist` s ON g.`serverid`=s.`id` INNER JOIN `servertypes` t ON s.`servertype`=t.`id` LEFT JOIN `lendedserver` AS l ON l.`serverid`=s.`id` WHERE g.`id`=? LIMIT 1"); $query->execute(array($switchID)); while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
<th class="corner-topleft"></th> <td class="border-top"> </td> <th class="corner-topright"></th> <th rowspan="3"><img src="images/forms/side_shadowright.jpg" width="20" height="300" alt="" /></th> </tr> <tr> <td class="border-left"></td> <td> <div id="content-table-inner"> <table border="0" width="100%" cellpadding="0" cellspacing="0"> <tr> <td width="40%"> <?php require_once 'modules/lib/class.gameq.php'; $server = array('gq' => array('armedassault2', $serverip, $serverport)); $gq = new GameQ(); $gq->addServers($server); $gq->setFilter('normalise'); foreach ($gq->requestData() as $data) { if ($data['gq_online']) { $name = $data['gq_hostname']; $mod = str_replace("Expansion;beta", "", preg_replace("/^[^@]*/", "", $data['gq_mod'])); // Mod cleanup regex by Crosire $maxplayers = $data['gq_maxplayers']; $numplayers = $data['gq_numplayers']; } else { $name = "Server is currently offline."; $mod = $servermodlist; $maxplayers = "-"; $numplayers = "-"; }
exit; } } } else { if (!strstr($_SERVER['REQUEST_URI'], "index")) { ?> <script type="text/javascript"> window.location = "index.php" </script><?php exit; } } require_once 'GameQ.php'; $serverList = array(); $handle = fopen("servers.php", "r"); if ($handle) { while (($line = fgets($handle)) !== false) { if (strstr($line, ",")) { array_push($serverList, explode(",", $line)); } } fclose($handle); } else { echo 'ERROR: Can\'t read serverinfo.php'; } $servers = array(); $publicIP = trim(shell_exec("dig +short myip.opendns.com @resolver1.opendns.com")); foreach ($serverList as $s) { array_push($servers, array($s[0] => $s[1], $publicIP, $s[2])); } $gq = new GameQ(); $gq->addServers($servers); //print_r($servers);
function QueryServer($block, $server_id) { global $sitename, $prefix, $db, $module_name, $admin, $GSdownloads, $GSdebug, $module_name, $GSremote, $GSremotepath, $GScode, $GSTags, $GSfailcount, $GSbcachetime; if ($_GET['do'] != "bquery") { include 'header.php'; } $sql = "SELECT ip, port, longname, engine, active, failstring, failcounts FROM " . $prefix . "_gameservers WHERE server_id='" . $_GET['server_id'] . "'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $GSip = $row[ip]; $GSport = $row[port]; $GSlongname = $row[longname]; $GSactive = $row[active]; $GSgame = $row[engine]; $GSfailstring = $row[failstring]; $GSfailcounts = $row[failcounts]; if ($_GET['do'] != "bquery") { title($sitename . " : " . _MODULENAME . " : " . $GSlongname); echo "<br />"; OpenTable(); echo "<center><a href=\"" . getlink("GameServers") . "\">.:: Display All Servers ::.</a><br />"; CloseTable(); echo "<br />"; OpenTable(); } if ($GSip) { if ($GSactive or is_admin($admin)) { $servers[$GSgame] = array($GSgame, $GSip, $GSport); if ($_GET['do'] == "bquery") { $sql2 = "SELECT server_id, sname, numplayers, maxplayers, map, stamp, ping FROM " . $prefix . "_gameservers_statcache WHERE server_id='" . $server_id . "' ORDER BY `stamp` ASC LIMIT 1"; $result2 = $db->sql_query($sql2); $stats[$server_id] = $db->sql_fetchrow($result2); $eng[$server_id] = $servers[$server_id][0]; $time = time(); $oldtime = $time - gmmktime(0, $GSbcachetime, 0, 1, 1, 1970, 0); if ($stats[$server_id][stamp] > 0 and $oldtime < $stats[$server_id][stamp]) { $skipq = 1; } } if ($skipq != 1) { if ($GSremote) { $fc = file_get_contents($GSremotepath . '/remote.php?game=' . $GSgame . '&ip=' . $GSip . '&port=' . $GSport . '&code=' . $GScode); $data = @unserialize($fc); } else { define('CFG_FILE', 'modules/' . $module_name . '/gameq/class.gameq.cfg.php'); define('INC_PATH', 'modules/' . $module_name . '/gameq/inc/'); require_once 'modules/' . $module_name . '/gameq/class.gameq.php'; $query = new GameQ(); $data = $query->GetInfo($servers); } } if (CheckQuery($data, $GSgame) or $skipq == 1) { if ($data[$GSgame][custom][ping] != 200) { $ping = $data[$GSgame][custom][ping]; } else { $ping = 0; } if ($_GET['do'] != "bquery") { if (file_exists('modules/' . $module_name . '/output_templates/' . $GSgame . '.php')) { if ($GSTags and $data[$GSgame][custom][type] == 'q3') { echo "<LINK REL=\"StyleSheet\" HREF=\"modules/{$module_name}/q3col.css\" TYPE=\"text/css\">"; } include 'modules/' . $module_name . '/output_templates/' . $GSgame . '.php'; } else { echo '<pre><strong>Raw Data:</strong>'; print_r($data); echo '</pre>'; } } else { if ($skipq != 1) { $SSplayers = PlayerCount($servers, $GSgame, $data); $SSmap = CurrentMap($servers, $GSgame, $data); $SSname = ServerName($servers, $GSgame, $data); } else { $SSplayers = $stats[$server_id][numplayers] . "/" . $stats[$server_id][maxplayers]; $SSmap = $stats[$server_id][map]; $SSname = $stats[$server_id][sname]; $ping = $stats[$server_id][ping]; } include 'modules/' . $module_name . '/output_templates/SSblock.php'; } SaveStats($servers, $server_id, $GSgame, $data); } elseif ($data == "BADCODE") { echo _BADCODE; } else { echo _BADQUERY; if ($GSfailcount and !$block) { AddFail($server_id); } } } else { echo _INACTIVE; } } else { echo _INVALID; } if ($_GET['do'] != "bquery") { CloseTable(); } // display downloads section if enabled if ($GSdownloads and !$bquery) { ListDLs($GSgame); } // display admin tools if admin if (is_admin($admin) and $_GET['do'] != "bquery") { echo "<br>"; OpenTable(); echo '<center>[ <a href="' . adminlink() . '">' . _GSADMIN . '</a> | <a href="' . adminlink("&mode=GSConfig") . '">' . _GSADMINC . '</a> | <a href="' . adminlink("&mode=GSEdit&server_id=" . $_GET['server_id'] . "") . '">' . _GSEDIT . '</a> | <a href="' . adminlink("&mode=GSStatus&server_id=" . $_GET['server_id'] . "&GSactive=" . $GSactive . "") . '">'; switch ($GSactive) { case 1: echo _GSDEACTIVE; break; case 2: echo _DEACTIVATED . "(" . count(explode("|", $GSfailstring)) . ")"; break; case 0: echo _GSACTIVE; break; } echo '</a> | '; if ($GSremote) { echo '<a href="' . $GSremotepath . '/remote.php?game=' . $GSgame . '&ip=' . $GSip . '&port=' . $GSport . '&code=' . $GScode . '" target="_blank">' . _REMLINK . '</a> | '; } echo '<a href="' . adminlink("&mode=GSDelete&server_id=" . $_GET['server_id'] . "&ok=0") . '">' . _GSDEL . '</a> ]</center>'; CloseTable(); } // display degug if admin and debug is enabled if (is_admin($admin) and $GSdebug and $_GET['do'] != "bquery") { echo '<br>'; OpenTable(); echo '<pre><strong>You\'re an admin for this module and debug is enabled - here is the Raw Data for this query:</strong><br>'; print_r($data); echo '</pre>'; echo '<pre><strong>Errors:</strong>'; print_r($query->ErrorMsg); echo '</pre>'; CloseTable(); } if ($_GET['do'] != "bquery") { include 'footer.php'; } else { die; } }
<th>Servers <th>№ <th class="hidden-xxs">Map <th><i class="fa-circle"></i> </tr> </thead> <tbody> <?php flush(); /* visitor should get better indication that the page is actually loading now */ foreach ($Servers as $Server) { if (strlen($Server) > 11 and strrpos($Server, '#', -strlen($Server)) === False) { list($ServerHost[], $Ports[], $GameType[]) = preg_split("/(:|,)/", $Server); } } $gq = new GameQ(); foreach ($ServerHost as $Index => $Host) { $gq->addServer(array('type' => trim($GameType[$Index]), 'host' => trim($Host) . ":" . trim($Ports[$Index]))); } $results = $gq->setOption('timeout', 1)->setFilter('normalise')->requestData(); foreach ($results as $id => $data) { if (!$data['gq_online']) { $data['gq_address'] = preg_replace('/.steamlug.org/', '.steamlug.org', $data['gq_address'], 1); echo <<<SERVERSTRING \t\t\t<tr class="unresponsive"> \t\t\t\t<td></td> \t\t\t\t<td></td> \t\t\t\t<td></td> \t\t\t\t<td><em>Server Unresponsive</em></td> \t\t\t\t<td><em>{$data['gq_address']}:{$data['gq_port']}</em></td> \t\t\t\t<td><em>0 ⁄ 0</em></td>
// Get IP/Port from hostname (ip:port) $exp_host = explode(':', $key['host']); // Skip if IP or Port are missing if (empty($exp_host[0]) || empty($exp_host[1])) { continue; } else { $basic_tcp_ck[$cnt_basic]['id'] = $key['id']; $basic_tcp_ck[$cnt_basic]['ip'] = $exp_host[0]; $basic_tcp_ck[$cnt_basic]['port'] = $exp_host[1]; } } $cnt_basic++; } // Get GameQ status require DOCROOT . '/includes/GameQ/GameQ.php'; $gq = new GameQ(); $gq->addServers($json_data); $gq->setOption('timeout', 8); $gq->setFilter('normalise'); $gq_results = $gq->requestData(); $json_out = array(); $json_cnt = 0; #echo '<pre>'; #var_dump($gq_results); #echo '</pre>'; // GameQ response - make simple (id, status) foreach ($gq_results as $key => $value) { $gq_online = $value['gq_online']; $gq_numplayers = $value['gq_numplayers']; $gq_maxplayers = $value['gq_maxplayers']; if ($gq_online) {