mini_start.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. $param_access_enabled = preg_match("/p/",$server_home['access_rights']) > 0 ? TRUE : FALSE;
  25. $extra_param_access_enabled = preg_match("/e/",$server_home['access_rights']) > 0 ? TRUE:FALSE;
  26. $last_param = !empty($server_home['last_param']) ? json_decode($server_home['last_param'], True) : array();
  27. $isAdmin = $db->isAdmin($_SESSION['user_id']);
  28. if (!function_exists('processParamValue')) {
  29. function processParamValue(&$param, &$server_xml, $paramKey, $paramValue, &$save_param, &$start_cmd){
  30. if (0 == strlen($paramValue))
  31. return false;
  32. if ($paramKey == $paramValue) // it's a checkbox
  33. {
  34. $new_param = $paramKey;
  35. $save_param[$paramKey] = $paramValue;
  36. }
  37. elseif($param->option == "ns" or $param->options == "ns")
  38. {
  39. $new_param = $paramKey.clean_server_param_value($paramValue, $server_xml->cli_allow_chars);
  40. $save_param[$paramKey] = $paramValue;
  41. }
  42. elseif($param->option == "q" or $param->options == "q"){
  43. $new_param = $paramKey . '"' . clean_server_param_value($paramValue, $server_xml->cli_allow_chars) . '"';
  44. $save_param[$paramKey] = $paramValue;
  45. }
  46. elseif($param->option == "s" or $param->options == "s"){
  47. $new_param = $paramKey . ' ' . clean_server_param_value($paramValue, $server_xml->cli_allow_chars);
  48. $save_param[$paramKey] = $paramValue;
  49. }
  50. else
  51. {
  52. $new_param = $paramKey.' "'.clean_server_param_value($paramValue, $server_xml->cli_allow_chars).'"';
  53. $save_param[$paramKey] = $paramValue;
  54. }
  55. if ($param['id'] == NULL || $param['id'] == "")
  56. {
  57. $start_cmd .= ' '.$new_param;
  58. }
  59. else
  60. {
  61. $start_cmd = preg_replace( "/%".$param['id']."%/", $new_param, $start_cmd );
  62. }
  63. }
  64. }
  65. if( !isset( $_POST['start_server'] ) )
  66. {
  67. $server_exec = clean_path($server_home['home_path']."/".$server_xml->exe_location."/".$server_xml->server_exec_name);
  68. $r = $remote->rfile_exists($server_exec);
  69. if($r === 0)
  70. {
  71. print_failure(get_lang_f('game_exec_not_found',$server_exec));
  72. return;
  73. }
  74. else if($r === -1)
  75. {
  76. print_failure( get_lang("agent_offline") );
  77. return;
  78. }
  79. // If the result is something else than 1 here then there unexpected retval was received.
  80. else if ($r !== 1 )
  81. {
  82. print_failure( get_lang("unexpected_result_libremote") );
  83. return;
  84. }
  85. $ip_info = $db->getHomeIpPorts($server_home['home_id']);
  86. if ( empty($ip_info) )
  87. {
  88. print_failure( get_lang("no_ip_port_pairs_assigned") );
  89. return;
  90. }
  91. echo get_lang_f('select_params_and_start', get_lang("start_server") );
  92. echo "<form action='home.php?m=gamemanager&amp;p=game_monitor&amp;home_id-mod_id-ip-port=". $server_home['home_id'] . "-". $server_home['mod_id'] . "-" . $server_home['ip'] . "-" . $server_home['port'] . "' method='post'>\n
  93. <input type='hidden' name='mod_id' value='$server_home[mod_id]' />\n
  94. <input type='hidden' name='home_id' value='$server_home[home_id]' />\n
  95. <input type='hidden' name='remote_server_id' value='".$server_home['remote_server_id']."' />\n
  96. <table class='start-server'>
  97. <tr><td class='right'>". get_lang("ogp_agent_ip") .
  98. ":</td><td class='left'>".$server_home['agent_ip']."</td></tr>";
  99. $max_players = $server_home['max_players'];
  100. if ( $max_players > 0 )
  101. {
  102. echo "<tr><td class='right'>". get_lang("max_players") .
  103. ":</td><td class='left'>";
  104. $players = array();
  105. for($i = $max_players; $i > 0; $i--)
  106. {
  107. $players["$i"]="$i";
  108. }
  109. echo create_drop_box_from_array($players,'max_players',$last_param['players']);
  110. echo "<span class='info'>(". get_lang("max") .": ".
  111. $max_players.")</span></td></tr>\n";
  112. }
  113. $display_ip = checkDisplayPublicIP($server_home['display_public_ip'],$server_home['ip'] != $server_home['agent_ip'] ? $server_home['ip'] : $server_home['agent_ip']);
  114. echo "<tr><td class='right'>". get_lang("ip_and_port") .
  115. ":</td><td class='left'>".$display_ip . ":" . $server_home['port']."<input name='ip_port' type='hidden' value='".$server_home['ip'] . ":" . $server_home['port']."'/></td></tr>";
  116. list($list_type,) = explode(":", $server_xml->map_list);
  117. $map_array = -5;
  118. $maps_found = FALSE;
  119. // use maplist file as primary map location.
  120. if ( $server_xml->map_list )
  121. {
  122. $mapfile = $server_home['home_path']."/".
  123. preg_replace("/mod/",$server_home['mod_key'],$server_xml->map_list);
  124. $read_status = $remote->remote_readfile($mapfile,$map_array);
  125. // If file was found and read successfully then lets seperate the maps.
  126. if ( $read_status == 1 )
  127. {
  128. $map_array = array_filter(preg_split("/\n/",$map_array));
  129. if(!empty($map_array))
  130. $maps_found = "FILE";
  131. }
  132. // Otherwise we have error situation...
  133. else
  134. {
  135. $map_array = $read_status;
  136. }
  137. }
  138. // If we could not find maps from the maps file lets try directory listing
  139. // if possible.
  140. if ( $maps_found === FALSE && $server_xml->maps_location )
  141. {
  142. // replace mod with the modname if nessessary.
  143. $map_path = $server_home['home_path']."/".
  144. preg_replace("/mod/",$server_home['mod_key'],$server_xml->maps_location);
  145. // Then we use the directory.
  146. $map_array = $remote->remote_dirlist($map_path);
  147. // If it is array then we successfully read maps.
  148. if ( is_array($map_array) )
  149. {
  150. $map_array = cleanFilenames($map_array);
  151. $maps_found = "DIR";
  152. }
  153. }
  154. $check_ok = TRUE;
  155. // If there is map list or location defined we should have maps available.
  156. if ( $server_xml->map_list || $server_xml->maps_location )
  157. {
  158. if ( is_array($map_array) )
  159. {
  160. echo "<tr><td class='right'>". get_lang("available_maps") .":</td><td class='left'>\n";
  161. // We remove all lines that start with // because we
  162. // expect those lines to be comments.
  163. $comments = preg_grep( "/^\s*\/\//",$map_array );
  164. $map_array = array_diff( $map_array,$comments );
  165. sort($map_array);
  166. echo create_drop_box_from_array($map_array,'map',$last_param['map']);
  167. echo "</td></tr>";
  168. echo "<tr><td colspan='2' class='info'>". get_lang("maps_read_from") ." ";
  169. if ( $maps_found == "DIR" )
  170. {
  171. echo get_lang("directory") ." ".clean_path($map_path).".";
  172. }
  173. else
  174. {
  175. echo get_lang("file") ." ".clean_path($mapfile).".";
  176. }
  177. echo "</td></tr>\n";
  178. }
  179. else
  180. {
  181. echo "<tr><td colspan='2'>";
  182. print_failure( get_lang("failed_to_read_maps_error_code") .": $map_array");
  183. echo "</td></tr>";
  184. $check_ok = FALSE;
  185. }
  186. }
  187. // Print params if there are any.
  188. if($server_xml->server_params)
  189. {
  190. if (!$param_access_enabled)
  191. echo "<span class='failure info'>". get_lang("no_parameter_access") ."</span>";
  192. foreach($server_xml->server_params->param as $param)
  193. {
  194. renderParam($param, $last_param, $param_access_enabled, $server_home['home_id']);
  195. }
  196. foreach($server_xml->server_params->group as $group)
  197. {
  198. echo "<tr><td><table>";
  199. echo "<tr><th><b>".$group['name']."</b></th></tr>";
  200. foreach($group->param as $param)
  201. {
  202. renderParam($param, $last_param, $param_access_enabled, $server_home['home_id']);
  203. }
  204. echo "</table></td></tr>";
  205. }
  206. }
  207. if (isset($server_home['extra_params']))
  208. {
  209. echo "<tr><td colspan='2'><h3>". get_lang("extra_parameters") ."</h3>";
  210. if (!$extra_param_access_enabled)
  211. echo "<span class='failure info'>". get_lang("no_extra_param_access") ."</span>";
  212. echo "</td></tr>\n";
  213. //get last used param or get default
  214. if (array_key_exists('extra', $last_param))
  215. $extra_default = $last_param['extra'];
  216. else
  217. $extra_default = $server_home['extra_params'];
  218. echo "<tr><td colspan='2'><input name='extra_params' value=\"".str_replace('"', "&quot;", strip_real_escape_string($extra_default))."\" style='width:99%' ";
  219. if (!$extra_param_access_enabled)
  220. echo 'disabled';
  221. echo "/></td></tr>";
  222. echo "<tr><td colspan='2' class='info'>". get_lang("extra_parameters_info") ."</td></tr>";
  223. }
  224. echo "</table>";
  225. echo get_lang("start_wait_note");
  226. if ( $check_ok )
  227. {
  228. echo "<div class='submit-start' ><input type='submit' name='start_server' value='".
  229. get_lang("start_server") ."' /></div>\n";
  230. }
  231. else
  232. {
  233. print_failure( get_lang("unable_get_info") );
  234. }
  235. echo "</form>";
  236. return;
  237. }
  238. // Starting the server
  239. elseif($server_home['home_id'] == $_POST['home_id'])
  240. {
  241. // Maxplayers on POST compares with maxplayers on DB for security reasons (FORM HACKING)
  242. if( isset( $_POST['max_players'] ) and is_numeric( $_POST['max_players'] ) )
  243. {
  244. if ( $_POST['max_players'] <= $server_home['max_players'] )
  245. $cli_param_data['PLAYERS'] = $_POST['max_players'];
  246. else
  247. {
  248. echo "<p>" . get_lang_f('unsuitable_maxplayers_value_maximum_reachable_number_of_slots_has_been_set') . "</p>";
  249. $cli_param_data['PLAYERS'] = $server_home['max_players'];
  250. }
  251. }
  252. if ( $server_xml->map_list OR $server_xml->maps_location )
  253. $cli_param_data['MAP'] = $_POST['map'];
  254. else
  255. $cli_param_data['MAP'] = "";
  256. $ip_port = $_POST['ip_port'];
  257. list($ip, $port) = explode(":", $ip_port);
  258. if($server_home['ip'] == $ip && $server_home['port'] == $port)
  259. {
  260. $cli_param_data['IP'] = $ip;
  261. $cli_param_data['PORT'] = $server_home['port'];
  262. }
  263. If ( !isset($cli_param_data['IP']) OR !isset($cli_param_data['PORT']) )
  264. {
  265. echo "<h2>" . get_lang_f('ip_port_pair_not_owned') . "</h2>";
  266. return;
  267. }
  268. $cli_param_data['HOSTNAME'] = $server_home['home_name'];
  269. $cli_param_data['PID_FILE'] = "ogp_game_startup.pid";
  270. $os = $remote->what_os();
  271. if( preg_match("/Linux/", $os) )
  272. {
  273. // Wine
  274. if(preg_match("/_win(32|64)?$/", $server_home['game_key']))
  275. {
  276. $home_path_wine = $remote->exec("winepath -w ".$server_home['home_path']);
  277. $home_path_wine = str_replace("\\","\\\\", $home_path_wine);
  278. $home_path_wine = trim($home_path_wine);
  279. $cli_param_data['BASE_PATH'] = $home_path_wine;
  280. $cli_param_data['HOME_PATH'] = $home_path_wine;
  281. $cli_param_data['SAVE_PATH'] = $home_path_wine;
  282. $cli_param_data['OUTPUT_PATH'] = $home_path_wine;
  283. $cli_param_data['USER_PATH'] = $home_path_wine;
  284. }
  285. // Linux
  286. else
  287. {
  288. $cli_param_data['BASE_PATH'] = $server_home['home_path'];
  289. $cli_param_data['HOME_PATH'] = $server_home['home_path'];
  290. $cli_param_data['SAVE_PATH'] = $server_home['home_path'];
  291. $cli_param_data['OUTPUT_PATH'] = $server_home['home_path'];
  292. $cli_param_data['USER_PATH'] = $server_home['home_path'];
  293. }
  294. }
  295. // Windows
  296. elseif( preg_match("/CYGWIN/", $os) )
  297. {
  298. $home_path_win = $remote->exec("cygpath -w ".$server_home['home_path']);
  299. $home_path_win = str_replace("\\","\\\\", $home_path_win);
  300. $home_path_win = trim($home_path_win);
  301. $cli_param_data['BASE_PATH'] = $home_path_win;
  302. $cli_param_data['HOME_PATH'] = $home_path_win;
  303. $cli_param_data['SAVE_PATH'] = $home_path_win;
  304. $cli_param_data['OUTPUT_PATH'] = $home_path_win;
  305. $cli_param_data['USER_PATH'] = $home_path_win;
  306. }
  307. // We do this check because sometimes server does not answer to lgsl check
  308. // done below and is still running.
  309. if ( $remote->is_screen_running(OGP_SCREEN_TYPE_HOME,$server_home['home_id']) === 1 )
  310. {
  311. echo "<p>".get_lang_f('server_already_running')."<a href=?m=gamemanager&amp;p=stop&amp;home_id=".$server_home['home_id'].
  312. "&amp;ip=".$ip."&amp;port=".
  313. $port.">".get_lang_f('already_running_stop_server')."</a></p>";
  314. return;
  315. }
  316. if ($server_xml->protocol == "gameq")
  317. {
  318. $query_port = get_query_port ($server_xml, $port);
  319. }
  320. elseif ($server_xml->protocol == "lgsl")
  321. {
  322. require('protocol/lgsl/lgsl_protocol.php');
  323. $get_ports = lgsl_port_conversion((string)$server_xml->lgsl_query_name, $port, "", "");
  324. $query_port = $get_ports['1'];
  325. }
  326. elseif ($server_xml->protocol == "teamspeak3")
  327. {
  328. $query_port = "10011";
  329. }
  330. $cli_param_data['QUERY_PORT'] = $query_port;
  331. // Check if the game is supported by lgsl or not.
  332. if ( $server_xml->lgsl_query_name )
  333. {
  334. //error_reporting(E_ERROR);
  335. require_once("includes/functions.php");
  336. $query_port = getQueryPortOverridesForGame((string)$server_xml->lgsl_query_name, $ip, $port, $query_port);
  337. $data = lgsl_query_live((string)$server_xml->lgsl_query_name, $ip, $port, $query_port, $port, "s");
  338. //error_reporting(E_ALL);
  339. if($data['b']['status'] == '1' && strpos((string)$server_xml->lgsl_query_name, 'mohaa') === false) // Skip this check for mohaa since the query ports are random
  340. {
  341. print_failure("".get_lang_f('error_server_already_running')." <b>$port</b>.");
  342. return;
  343. }
  344. }
  345. $cli_param_data['GAME_TYPE'] = $server_home['mod_key'];
  346. $cli_param_data['CONTROL_PASSWORD'] = $server_home['control_password'];
  347. $start_cmd = "";
  348. // If the template is empty then these are not needed.
  349. if ( $server_xml->cli_template )
  350. {
  351. $start_cmd = $server_xml->cli_template;
  352. if ( $server_xml->cli_params )
  353. {
  354. foreach ( $server_xml->cli_params->cli_param as $cli )
  355. {
  356. // If s is found the param is seperated with space
  357. $add_space = preg_match( "/s/", $cli['options'] ) > 0 ? " " : "";
  358. $cli_value = $cli_param_data[(string) $cli['id'] ];
  359. // If q is found we add quotes around the value.
  360. if ( preg_match( "/q/", $cli['options'] ) > 0 )
  361. {
  362. $cli_value = "\"".$cli_value."\"";
  363. }
  364. $start_cmd = preg_replace( "/%".$cli['id']."%/",
  365. $cli['cli_string'].$add_space.$cli_value, $start_cmd );
  366. }
  367. }
  368. if ( $server_xml->reserve_ports )
  369. {
  370. foreach ( $server_xml->reserve_ports->port as $reserve_port )
  371. {
  372. // If s is found the param is seperated with space
  373. $add_space = preg_match( "/s/", $reserve_port['options'] ) > 0 ? " " : "";
  374. $cli_value = $reserve_port['type'] == "add" ? $server_home['port'] + (string) $reserve_port:
  375. $server_home['port'] - (string) $reserve_port;
  376. // If q is found we add quotes around the value.
  377. if ( preg_match( "/q/", $reserve_port['options'] ) > 0 )
  378. {
  379. $cli_value = "\"".$cli_value."\"";
  380. }
  381. $start_cmd = preg_replace( "/%".$reserve_port['id']."%/",
  382. $reserve_port['cli_string'].$add_space.$cli_value, $start_cmd );
  383. }
  384. }
  385. }
  386. $save_param = array();
  387. if(isset($server_xml->server_params->param))
  388. {
  389. if($param_access_enabled and isset($_POST['params']))
  390. {
  391. foreach($server_xml->server_params->param as $param)
  392. {
  393. $paramKey = (string)$param['key'];
  394. $paramType = (string)$param['type'];
  395. // Get the last saved value of this param or its default value
  396. if (array_key_exists($paramKey, $last_param))
  397. $savedValue = (string)$last_param[$paramKey];
  398. $lockedByAdmin = (property_exists($param, 'access') and $param->access == "admin" and !$isAdmin);
  399. // Dependency fields...
  400. if($paramType == "other_game_server_path" or $paramType == "other_game_server_path_additional")
  401. {
  402. $postKey = $paramKey."{DEPENDS:$paramType}";
  403. if(isset($_POST['params'][$postKey]) and !empty($_POST['params'][$postKey]))
  404. {
  405. $dependsSection = strrpos($postKey, "{DEPENDS");
  406. $realKey = substr($postKey, 0, $dependsSection);
  407. $dependsSection = substr($postKey, $dependsSection);
  408. $dependsKey = str_replace("{DEPENDS:", "", $dependsSection);
  409. $dependsKey = str_replace("}", "", $dependsKey);
  410. $_POST['params'][$paramKey] = $_POST['params'][$postKey];
  411. if($dependsKey == "other_game_server_path_additional" and isset($_POST['params'][$dependsKey]))
  412. $_POST['params'][$paramKey] .= ltrim($_POST['params'][$dependsKey],'/');
  413. }
  414. }
  415. if(isset($_POST['params'][$paramKey]))
  416. {
  417. $processIt = true;
  418. $paramValue = $_POST['params'][$paramKey];
  419. if($lockedByAdmin)
  420. {
  421. if(isset($savedValue))
  422. $paramValue = $savedValue;
  423. else
  424. $processIt = false;
  425. }
  426. $paramKey = isset($realKey) ? $realKey : $paramKey;
  427. // Process the param value for the start command and for the save params unless its locked by admin and there's no saved value.
  428. if($processIt)
  429. processParamValue($param, $server_xml, $paramKey, $paramValue, $save_param, $start_cmd);
  430. }
  431. else// 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)
  432. {
  433. if($lockedByAdmin and isset($savedValue))
  434. processParamValue($param, $server_xml, $paramKey, $savedValue, $save_param, $start_cmd);
  435. }
  436. if ($param['id'] != NULL && $param['id'] != "")
  437. $start_cmd = preg_replace( "/%".$param['id']."%/", '', $start_cmd );
  438. if(isset($realKey))
  439. unset($realKey);
  440. if(isset($savedValue))
  441. unset($savedValue);
  442. }
  443. }
  444. elseif( !$param_access_enabled )
  445. {
  446. foreach($server_xml->server_params->param as $param)
  447. {
  448. $paramKey = (string)$param['key'];
  449. if(isset($last_param[$paramKey]) and strlen((string)$last_param[$paramKey]) != 0)
  450. {
  451. $paramValue = (string)$last_param[$paramKey];
  452. if ($paramKey == $paramValue) // it's a checkbox
  453. {
  454. $new_param = $paramKey;
  455. $save_param[$paramKey] = $paramValue;
  456. }
  457. elseif($param->option == "ns" or $param->options == "ns")
  458. {
  459. $new_param = $paramKey.clean_server_param_value($paramValue, $server_xml->cli_allow_chars);
  460. $save_param[$paramKey] = $paramValue;
  461. }
  462. elseif($param->option == "q" or $param->options == "q"){
  463. $new_param = $paramKey . '"' . clean_server_param_value($paramValue, $server_xml->cli_allow_chars) . '"';
  464. $save_param[$paramKey] = $paramValue;
  465. }
  466. elseif($param->option == "s" or $param->options == "s"){
  467. $new_param = $paramKey . ' ' . clean_server_param_value($paramValue, $server_xml->cli_allow_chars);
  468. $save_param[$paramKey] = $paramValue;
  469. }
  470. else
  471. {
  472. $new_param = $paramKey.' "'.clean_server_param_value($paramValue, $server_xml->cli_allow_chars).'"';
  473. $save_param[$paramKey] = $paramValue;
  474. }
  475. if($param['id'] == NULL or $param['id'] == "")
  476. {
  477. $start_cmd .= ' '.$new_param;
  478. }
  479. else
  480. {
  481. $start_cmd = preg_replace( "/%".$param['id']."%/", $new_param, $start_cmd );
  482. }
  483. }
  484. else
  485. {
  486. if($param['id'] != NULL and $param['id'] != "")
  487. $start_cmd = preg_replace( "/%".$param['id']."%/", '', $start_cmd );
  488. }
  489. }
  490. }
  491. }
  492. $save_param['map'] = $cli_param_data['MAP'];
  493. $save_param['players'] = $cli_param_data['PLAYERS'];
  494. if ( $extra_param_access_enabled )
  495. {
  496. if(isset($_REQUEST['extra_params']) and $_REQUEST['extra_params'] != "")
  497. {
  498. $start_cmd .= " ".str_replace("\\\\", "\\", clean_server_param_value($_REQUEST['extra_params'], $server_xml->cli_allow_chars));
  499. $save_param['extra'] = $_REQUEST['extra_params'];
  500. }
  501. }
  502. else
  503. {
  504. // If user does not have access to modify extra params then we use
  505. // the last param or default set by admins.
  506. $extra = ($last_param !== NULL and array_key_exists('extra', $last_param) and (string)$last_param['extra'] != "") ?
  507. $last_param['extra'] : $server_home['extra_params'];
  508. $start_cmd .= " ".str_replace("\\\\", "\\", clean_server_param_value($extra, $server_xml->cli_allow_chars));
  509. $save_param['extra'] = $extra;
  510. }
  511. //Save the param used to the database
  512. $db->changeLastParam($server_home['home_id'],json_encode($save_param));
  513. echo "<table class='server-starting'>";
  514. echo "<tr><td class='right'>". get_lang("ogp_agent_ip") .
  515. ":</td><td class='left'>".$server_home['agent_ip']."</td></tr>\n";
  516. echo "<tr><td class='right'>". get_lang("game_home") .
  517. ":</td><td class='left'>".$server_home['home_path']."</td></tr>";
  518. echo "<tr><td class='right'>". get_lang("startup_cpu") .
  519. ":</td><td class='left'>".$server_home['cpu_affinity']."</td></tr>\n";
  520. echo "<tr><td class='right'>". get_lang("startup_nice") .
  521. ":</td><td class='left'>".$server_home['nice']."</td></tr>";
  522. echo "<tr><td class='right'>". get_lang("startup_params") .
  523. ":</td><td colspan='2' style='word-wrap: break-word'>".strip_real_escape_string($start_cmd)."</td></tr>";
  524. echo "</table>";
  525. if($server_xml->replace_texts OR $server_xml->custom_fields)
  526. require_once("modules/gamemanager/cfg_text_replace.php");
  527. // Run pre-start commands
  528. if(isset($server_xml->pre_start) && !empty($server_xml->pre_start)){
  529. $preStart = trim($server_xml->pre_start);
  530. }else{
  531. $preStart = "";
  532. }
  533. // Environment variables
  534. if(isset($server_xml->environment_variables) && !empty($server_xml->environment_variables)){
  535. $envVars = trim($server_xml->environment_variables);
  536. }else{
  537. $envVars = "";
  538. }
  539. // Additional files to lock
  540. if(isset($server_xml->lock_files) && !empty($server_xml->lock_files)){
  541. $lockFiles = trim($server_xml->lock_files);
  542. }else{
  543. $lockFiles = "";
  544. }
  545. if(!empty($lockFiles)){
  546. // Linux only call
  547. if(preg_match("/Linux/", $os)){
  548. $lockedFilesStatus = $remote->lock_additional_home_files($server_home['home_path'], $lockFiles, "lock");
  549. }
  550. }
  551. $start_retval = $remote->universal_start($server_home['home_id'],
  552. $server_home['home_path'],
  553. $server_xml->server_exec_name,
  554. $server_xml->exe_location,
  555. $start_cmd, $port, $ip,
  556. $server_home['cpu_affinity'],
  557. $server_home['nice'],
  558. $preStart,
  559. $envVars,
  560. $server_xml->game_key,
  561. (isset( $server_xml->console_log ) ? $server_xml->console_log : "")
  562. );
  563. $db->logger( get_lang("server_started") . " (".$server_home['home_name']." $ip:$port)" );
  564. if ( $start_retval == AGENT_ERROR_NOT_EXECUTABLE )
  565. {
  566. print_failure( get_lang("server_binary_not_executable") );
  567. return;
  568. }
  569. else if ( $start_retval <= 0 )
  570. {
  571. if( $start_retval == -14 )
  572. {
  573. echo "<p>".get_lang_f('server_already_running')."<a href=?m=gamemanager&amp;p=stop&amp;home_id=".$server_home['home_id'].
  574. "&amp;ip=".$ip."&amp;port=".
  575. $port.">".get_lang_f('already_running_stop_server')."</a></p>";
  576. return;
  577. }
  578. else
  579. {
  580. print_failure(get_lang_f('failed_start_server_code',$start_retval));
  581. return;
  582. }
  583. }
  584. echo "<h3>". get_lang("starting_server_settings") .":</h3>";
  585. $firewall_settings = $db->getFirewallSettings($server_home['remote_server_id']);
  586. if ($firewall_settings['status'] == "enable")
  587. {
  588. $ip_ports = $db->getHomeIpPorts($server_home['home_id']);
  589. foreach ($ip_ports as $ip_port)
  590. {
  591. if ($server_xml->protocol == "gameq")
  592. {
  593. $query_port = get_query_port($server_xml, $ip_port['port']);
  594. }
  595. elseif ($server_xml->protocol == "lgsl")
  596. {
  597. require('protocol/lgsl/lgsl_protocol.php');
  598. $get_ports = lgsl_port_conversion((string)$server_xml->lgsl_query_name, $ip_port['port'], "", "");
  599. $query_port = $get_ports['1'];
  600. }
  601. elseif ($server_xml->protocol == "teamspeak3")
  602. {
  603. $query_port = "10011";
  604. }
  605. set_firewall($remote, $firewall_settings, 'allow', $ip_port['port'], $ip_port['ip']);
  606. if(isset($query_port) and $query_port != "" and $query_port != $ip_port['port'])
  607. set_firewall($remote, $firewall_settings, 'allow', $query_port, $ip_port['ip']);
  608. }
  609. }
  610. echo "<table class='list_table'>";
  611. if (isset($server_xml->lgsl_query_name) || isset($server_xml->gameq_query_name))
  612. {
  613. if(isset($server_xml->lgsl_query_name))$query_name = $server_xml->lgsl_query_name;
  614. else $query_name = $server_xml->gameq_query_name;
  615. } elseif ($server_xml->protocol == "teamspeak3") {
  616. $query_name = 'ts3';
  617. } else $query_name = $server_xml->mods->mod['key'];
  618. if ( $server_xml->map_list || $server_xml->maps_location )
  619. {
  620. $map_lc = preg_replace("/[^a-z0-9_]/", "_", strtolower($cli_param_data['MAP']));
  621. //----------+ getting the maps image location.
  622. $maplocation = get_map_path($query_name,$server_xml->mods->mod['key'],$map_lc);
  623. echo "<tr><td rowspan='6' style='width:160px;'><img src='".$maplocation."' /></td><td class='right'>". get_lang("map") .
  624. ":</td><td class='left'>".$cli_param_data['MAP']."</td></tr>";
  625. }
  626. else
  627. {
  628. $icon_paths = array("images/icons/".$server_xml->mods->mod['key'].".png",
  629. "images/icons/$query_name.png",
  630. "protocol/lgsl/other/icon_unknown.gif"); // USE UKNOWN ICON
  631. $icon_path = get_first_existing_file($icon_paths);
  632. echo "<tr><td rowspan='6'><img src='".$icon_path."' /></td>";
  633. }
  634. if ( isset($cli_param_data['PLAYERS']) )
  635. {
  636. echo "<tr><td class='right'>". get_lang("max_players") .
  637. ":</td><td class='left'>".$cli_param_data['PLAYERS']."</td></tr>";
  638. }
  639. echo "<tr><td class='right'>". get_lang("server_ip_port") .
  640. ":</td><td class='left'>$ip:$port</td></tr>";
  641. echo "<tr><td class='right'>". get_lang("game_type") .
  642. ":</td><td class='left'>".$server_xml->mods->mod['key']."</td></tr>";
  643. echo "</table>";
  644. print("<p class='note'>". get_lang("starting_server") ."</p>");
  645. global $view;
  646. $view->refresh("?m=gamemanager&amp;p=start&amp;refresh&amp;home_id=".$server_home['home_id']."&amp;ip=".$ip."&amp;port=".$port."&amp;mod_id=".$server_home['mod_id'],3);
  647. return;
  648. }
  649. ?>