0 ? TRUE : FALSE; $extra_param_access_enabled = preg_match("/e/",$server_home['access_rights']) > 0 ? TRUE:FALSE; $last_param = json_decode($server_home['last_param'], True); $isAdmin = $db->isAdmin($_SESSION['user_id']); if (!function_exists('processParamValue')) { function processParamValue($paramKey, $paramValue){ // Set globals global $save_param, $start_cmd, $param; if (0 == strlen($paramValue)) return false; if ($paramKey == $paramValue) // it's a checkbox { $new_param = $paramKey; $save_param[$paramKey] = True; } elseif($param->option == "ns" or $param->options == "ns") { $new_param = $paramKey.clean_server_param_value($paramValue, $server_xml->cli_allow_chars); $save_param[$paramKey] = $paramValue; } elseif($param->option == "q" or $param->options == "q"){ $new_param = $paramKey . '"' . clean_server_param_value($paramValue, $server_xml->cli_allow_chars) . '"'; $save_param[$paramKey] = $paramValue; } elseif($param->option == "s" or $param->options == "s"){ $new_param = $paramKey . ' ' . clean_server_param_value($paramValue, $server_xml->cli_allow_chars); $save_param[$paramKey] = $paramValue; } else { $new_param = $paramKey.' "'.clean_server_param_value($paramValue, $server_xml->cli_allow_chars).'"'; $save_param[$paramKey] = $paramValue; } if ($param['id'] == NULL || $param['id'] == "") { $start_cmd .= ' '.$new_param; } else { $start_cmd = preg_replace( "/%".$param['id']."%/", $new_param, $start_cmd ); } } } if( !isset( $_POST['start_server'] ) ) { $server_exec = clean_path($server_home['home_path']."/".$server_xml->exe_location."/".$server_xml->server_exec_name); $r = $remote->rfile_exists($server_exec); if($r === 0) { print_failure(get_lang_f('game_exec_not_found',$server_exec)); return; } else if($r === -1) { print_failure( agent_offline ); return; } // If the result is something else than 1 here then there unexpected retval was received. else if ($r !== 1 ) { print_failure( unexpected_result_libremote ); return; } $ip_info = $db->getHomeIpPorts($server_home['home_id']); if ( empty($ip_info) ) { print_failure( no_ip_port_pairs_assigned ); return; } echo get_lang_f('select_params_and_start', start_server ); echo "
"; return; } // Starting the server elseif($server_home['home_id'] == $_POST['home_id']) { // Maxplayers on POST compares with maxplayers on DB for security reasons (FORM HACKING) if( isset( $_POST['max_players'] ) and is_numeric( $_POST['max_players'] ) ) { if ( $_POST['max_players'] <= $server_home['max_players'] ) $cli_param_data['PLAYERS'] = $_POST['max_players']; else { echo "" . get_lang_f('unsuitable_maxplayers_value_maximum_reachable_number_of_slots_has_been_set') . "
"; $cli_param_data['PLAYERS'] = $server_home['max_players']; } } if ( $server_xml->map_list OR $server_xml->maps_location ) $cli_param_data['MAP'] = $_POST['map']; else $cli_param_data['MAP'] = ""; $ip_port = $_POST['ip_port']; list($ip, $port) = explode(":", $ip_port); if($server_home['ip'] == $ip && $server_home['port'] == $port) { $cli_param_data['IP'] = $server_home['ip']; $cli_param_data['PORT'] = $server_home['port']; } If ( !isset($cli_param_data['IP']) OR !isset($cli_param_data['PORT']) ) { echo "".get_lang_f('server_already_running')."".get_lang_f('already_running_stop_server')."
"; return; } if ($server_xml->protocol == "gameq") { $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, "", ""); $query_port = $get_ports['1']; } elseif ($server_xml->protocol == "teamspeak3") { $query_port = "10011"; } $cli_param_data['QUERY_PORT'] = $query_port; // Check if the game is supported by lgsl or not. if ( $server_xml->lgsl_query_name ) { //error_reporting(E_ERROR); $data = lgsl_query_live((string)$server_xml->lgsl_query_name, $ip, $port, $query_port, $port, "s"); //error_reporting(E_ALL); if($data['b']['status'] == '1') { print_failure("".get_lang_f('error_server_already_running')." $port."); return; } } $cli_param_data['GAME_TYPE'] = $server_home['mod_key']; $cli_param_data['CONTROL_PASSWORD'] = $server_home['control_password']; $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 ( $server_xml->reserve_ports ) { foreach ( $server_xml->reserve_ports->port as $reserve_port ) { // If s is found the param is seperated with space $add_space = preg_match( "/s/", $reserve_port['options'] ) > 0 ? " " : ""; $cli_value = $reserve_port['type'] == "add" ? $server_home['port'] + (string) $reserve_port: $server_home['port'] - (string) $reserve_port; // If q is found we add quotes around the value. if ( preg_match( "/q/", $reserve_port['options'] ) > 0 ) { $cli_value = "\"".$cli_value."\""; } $start_cmd = preg_replace( "/%".$reserve_port['id']."%/", $reserve_port['cli_string'].$add_space.$cli_value, $start_cmd ); } } } $save_param = array(); if( isset($server_xml->server_params->param) ) { if ( $param_access_enabled && isset($_REQUEST['params']) ) { foreach($server_xml->server_params->param as $param) { // Get the last saved value of this param or its default value if (array_key_exists((string)$param['key'], $last_param)){ $origValue = (string)$last_param[(string)$param['key']]; }else{ $origValue = ""; } // Loop through each posted param and process them $found = 0; foreach ( $_REQUEST['params'] as $paramKey => $paramValue ) { // Dependency fields... if(stripos($paramKey, "{DEPENDS") !== false){ $dependsSection = strrpos($paramKey, "{DEPENDS"); $realKey = substr($paramKey, 0, $dependsSection); $dependsSection = substr($paramKey, $dependsSection); $dependsKey = str_replace("{DEPENDS:", "", $dependsSection); $dependsKey = str_replace("}", "", $dependsKey); if(hasValue($_REQUEST['params'][$dependsKey])){ $paramValue .= $_REQUEST['params'][$dependsKey]; } $paramKey = $realKey; } if ($param['key'] == $paramKey) { // If locked by an admin, ignore the value posted by the user $lockedByAdmin = false; if(property_exists($param, 'access') && $param->access == "admin") { $lockedByAdmin = true; if(!$isAdmin){ $paramValue = $origValue; // Set it to the old saved value (which was last set by an admin) or set it to its default value } } // Process the param value for the start command and for the save params processParamValue($paramKey, $paramValue); $found++; break; // More efficient } } // If the parameter wasn't posted (because it may have been disabled due to access param) or a sneaky user deleted it to circumvent security if($found == 0){ processParamValue((string)$param['key'], $origValue); } if ($param['id'] != NULL && $param['id'] != ""){ $start_cmd = preg_replace( "/%".$param['id']."%/", '', $start_cmd ); } } } elseif( !$param_access_enabled ) { foreach($server_xml->server_params->param as $param) { foreach ( $last_param as $paramKey => $paramValue ) { if ($param['key'] == $paramKey) { if (0 == strlen($paramValue)) continue; if ($paramKey == $paramValue) // it's a checkbox { $new_param = $paramKey; $save_param[$paramKey] = True; } elseif($param->option == "ns" or $param->options == "ns") { $new_param = $paramKey.clean_server_param_value($paramValue, $server_xml->cli_allow_chars); $save_param[$paramKey] = $paramValue; } elseif($param->option == "q" or $param->options == "q"){ $new_param = $paramKey . '"' . clean_server_param_value($paramValue, $server_xml->cli_allow_chars) . '"'; $save_param[$paramKey] = $paramValue; } elseif($param->option == "s" or $param->options == "s"){ $new_param = $paramKey . ' ' . clean_server_param_value($paramValue, $server_xml->cli_allow_chars); $save_param[$paramKey] = $paramValue; } else { $new_param = $paramKey.' "'.clean_server_param_value($paramValue, $server_xml->cli_allow_chars).'"'; $save_param[$paramKey] = $paramValue; } if ($param['id'] == NULL || $param['id'] == "") { $start_cmd .= ' '.$new_param; } else { $start_cmd = preg_replace( "/%".$param['id']."%/", $new_param, $start_cmd ); } } } if ($param['id'] != NULL && $param['id'] != ""){ $start_cmd = preg_replace( "/%".$param['id']."%/", '', $start_cmd ); } } } } $save_param['map'] = $cli_param_data['MAP']; $save_param['players'] = $cli_param_data['PLAYERS']; if ( $extra_param_access_enabled ) { if(isset($_REQUEST['extra_params']) and $_REQUEST['extra_params'] != "") { $start_cmd .= " ".str_replace("\\\\", "\\", clean_server_param_value($_REQUEST['extra_params'], $server_xml->cli_allow_chars)); $save_param['extra'] = $_REQUEST['extra_params']; } } else { // If user does not have access to modify extra params then we use // the last param or default set by admins. $extra = ($last_param !== NULL and array_key_exists('extra', $last_param) and $last_param['extra'] != "") ? $last_param['extra'] : $server_home['extra_params']; $start_cmd .= " ".str_replace("\\\\", "\\", clean_server_param_value($extra, $server_xml->cli_allow_chars)); $save_param['extra'] = $extra; } //Save the param used to the database $db->changeLastParam($server_home['home_id'],json_encode($save_param)); echo "| ". ogp_agent_ip . ": | ".$server_home['agent_ip']." | |
| ". game_home . ": | ".$server_home['home_path']." | |
| ". startup_cpu . ": | ".$server_home['cpu_affinity']." | |
| ". startup_nice . ": | ".$server_home['nice']." | |
| ". startup_params . ": | ".strip_real_escape_string($start_cmd)." | |
".get_lang_f('server_already_running')."".get_lang_f('already_running_stop_server')."
"; return; } else { print_failure(get_lang_f('failed_start_server_code',$start_retval)); return; } } echo "| ". map . ": | ".$cli_param_data['MAP']." | |
| ". max_players . ": | ".$cli_param_data['PLAYERS']." | |
| ". server_ip_port . ": | $ip:$port | |
| ". game_type . ": | ".$server_xml->mods->mod['key']." |
". starting_server ."
"); global $view; $view->refresh("?m=gamemanager&p=start&refresh&home_id=".$server_home['home_id']."&ip=".$ip."&port=".$port."&mod_id=".$server_home['mod_id'],3); return; } ?>