mini_start.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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 = json_decode($server_home['last_param'], True);
  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'] = $server_home['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. $data = lgsl_query_live((string)$server_xml->lgsl_query_name, $ip, $port, $query_port, $port, "s");
  336. //error_reporting(E_ALL);
  337. if($data['b']['status'] == '1')
  338. {
  339. print_failure("".get_lang_f('error_server_already_running')." <b>$port</b>.");
  340. return;
  341. }
  342. }
  343. $cli_param_data['GAME_TYPE'] = $server_home['mod_key'];
  344. $cli_param_data['CONTROL_PASSWORD'] = $server_home['control_password'];
  345. $start_cmd = "";
  346. // If the template is empty then these are not needed.
  347. if ( $server_xml->cli_template )
  348. {
  349. $start_cmd = $server_xml->cli_template;
  350. if ( $server_xml->cli_params )
  351. {
  352. foreach ( $server_xml->cli_params->cli_param as $cli )
  353. {
  354. // If s is found the param is seperated with space
  355. $add_space = preg_match( "/s/", $cli['options'] ) > 0 ? " " : "";
  356. $cli_value = $cli_param_data[(string) $cli['id'] ];
  357. // If q is found we add quotes around the value.
  358. if ( preg_match( "/q/", $cli['options'] ) > 0 )
  359. {
  360. $cli_value = "\"".$cli_value."\"";
  361. }
  362. $start_cmd = preg_replace( "/%".$cli['id']."%/",
  363. $cli['cli_string'].$add_space.$cli_value, $start_cmd );
  364. }
  365. }
  366. if ( $server_xml->reserve_ports )
  367. {
  368. foreach ( $server_xml->reserve_ports->port as $reserve_port )
  369. {
  370. // If s is found the param is seperated with space
  371. $add_space = preg_match( "/s/", $reserve_port['options'] ) > 0 ? " " : "";
  372. $cli_value = $reserve_port['type'] == "add" ? $server_home['port'] + (string) $reserve_port:
  373. $server_home['port'] - (string) $reserve_port;
  374. // If q is found we add quotes around the value.
  375. if ( preg_match( "/q/", $reserve_port['options'] ) > 0 )
  376. {
  377. $cli_value = "\"".$cli_value."\"";
  378. }
  379. $start_cmd = preg_replace( "/%".$reserve_port['id']."%/",
  380. $reserve_port['cli_string'].$add_space.$cli_value, $start_cmd );
  381. }
  382. }
  383. }
  384. $save_param = array();
  385. if(isset($server_xml->server_params->param))
  386. {
  387. if($param_access_enabled and isset($_POST['params']))
  388. {
  389. foreach($server_xml->server_params->param as $param)
  390. {
  391. $paramKey = (string)$param['key'];
  392. $paramType = (string)$param['type'];
  393. // Get the last saved value of this param or its default value
  394. if (array_key_exists($paramKey, $last_param))
  395. $savedValue = (string)$last_param[$paramKey];
  396. $lockedByAdmin = (property_exists($param, 'access') and $param->access == "admin" and !$isAdmin);
  397. // Dependency fields...
  398. if($paramType == "other_game_server_path" or $paramType == "other_game_server_path_additional")
  399. {
  400. $postKey = $paramKey."{DEPENDS:$paramType}";
  401. if(isset($_POST['params'][$postKey]) and !empty($_POST['params'][$postKey]))
  402. {
  403. $dependsSection = strrpos($postKey, "{DEPENDS");
  404. $realKey = substr($postKey, 0, $dependsSection);
  405. $dependsSection = substr($postKey, $dependsSection);
  406. $dependsKey = str_replace("{DEPENDS:", "", $dependsSection);
  407. $dependsKey = str_replace("}", "", $dependsKey);
  408. $_POST['params'][$paramKey] = $_POST['params'][$postKey];
  409. if($dependsKey == "other_game_server_path_additional" and isset($_POST['params'][$dependsKey]))
  410. $_POST['params'][$paramKey] .= ltrim($_POST['params'][$dependsKey],'/');
  411. }
  412. }
  413. if(isset($_POST['params'][$paramKey]))
  414. {
  415. $processIt = true;
  416. $paramValue = $_POST['params'][$paramKey];
  417. if($lockedByAdmin)
  418. {
  419. if(isset($savedValue))
  420. $paramValue = $savedValue;
  421. else
  422. $processIt = false;
  423. }
  424. $paramKey = isset($realKey) ? $realKey : $paramKey;
  425. // Process the param value for the start command and for the save params unless its locked by admin and there's no saved value.
  426. if($processIt)
  427. processParamValue($param, $server_xml, $paramKey, $paramValue, $save_param, $start_cmd);
  428. }
  429. 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)
  430. {
  431. if($lockedByAdmin and isset($savedValue))
  432. processParamValue($param, $server_xml, $paramKey, $savedValue, $save_param, $start_cmd);
  433. }
  434. if ($param['id'] != NULL && $param['id'] != "")
  435. $start_cmd = preg_replace( "/%".$param['id']."%/", '', $start_cmd );
  436. if(isset($realKey))
  437. unset($realKey);
  438. if(isset($savedValue))
  439. unset($savedValue);
  440. }
  441. }
  442. elseif( !$param_access_enabled )
  443. {
  444. foreach($server_xml->server_params->param as $param)
  445. {
  446. $paramKey = (string)$param['key'];
  447. if(isset($last_param[$paramKey]) and strlen((string)$last_param[$paramKey]) != 0)
  448. {
  449. $paramValue = (string)$last_param[$paramKey];
  450. if ($paramKey == $paramValue) // it's a checkbox
  451. {
  452. $new_param = $paramKey;
  453. $save_param[$paramKey] = $paramValue;
  454. }
  455. elseif($param->option == "ns" or $param->options == "ns")
  456. {
  457. $new_param = $paramKey.clean_server_param_value($paramValue, $server_xml->cli_allow_chars);
  458. $save_param[$paramKey] = $paramValue;
  459. }
  460. elseif($param->option == "q" or $param->options == "q"){
  461. $new_param = $paramKey . '"' . clean_server_param_value($paramValue, $server_xml->cli_allow_chars) . '"';
  462. $save_param[$paramKey] = $paramValue;
  463. }
  464. elseif($param->option == "s" or $param->options == "s"){
  465. $new_param = $paramKey . ' ' . clean_server_param_value($paramValue, $server_xml->cli_allow_chars);
  466. $save_param[$paramKey] = $paramValue;
  467. }
  468. else
  469. {
  470. $new_param = $paramKey.' "'.clean_server_param_value($paramValue, $server_xml->cli_allow_chars).'"';
  471. $save_param[$paramKey] = $paramValue;
  472. }
  473. if($param['id'] == NULL or $param['id'] == "")
  474. {
  475. $start_cmd .= ' '.$new_param;
  476. }
  477. else
  478. {
  479. $start_cmd = preg_replace( "/%".$param['id']."%/", $new_param, $start_cmd );
  480. }
  481. }
  482. else
  483. {
  484. if($param['id'] != NULL and $param['id'] != "")
  485. $start_cmd = preg_replace( "/%".$param['id']."%/", '', $start_cmd );
  486. }
  487. }
  488. }
  489. }
  490. $save_param['map'] = $cli_param_data['MAP'];
  491. $save_param['players'] = $cli_param_data['PLAYERS'];
  492. if ( $extra_param_access_enabled )
  493. {
  494. if(isset($_REQUEST['extra_params']) and $_REQUEST['extra_params'] != "")
  495. {
  496. $start_cmd .= " ".str_replace("\\\\", "\\", clean_server_param_value($_REQUEST['extra_params'], $server_xml->cli_allow_chars));
  497. $save_param['extra'] = $_REQUEST['extra_params'];
  498. }
  499. }
  500. else
  501. {
  502. // If user does not have access to modify extra params then we use
  503. // the last param or default set by admins.
  504. $extra = ($last_param !== NULL and array_key_exists('extra', $last_param) and (string)$last_param['extra'] != "") ?
  505. $last_param['extra'] : $server_home['extra_params'];
  506. $start_cmd .= " ".str_replace("\\\\", "\\", clean_server_param_value($extra, $server_xml->cli_allow_chars));
  507. $save_param['extra'] = $extra;
  508. }
  509. //Save the param used to the database
  510. $db->changeLastParam($server_home['home_id'],json_encode($save_param));
  511. echo "<table class='server-starting'>";
  512. echo "<tr><td class='right'>". get_lang("ogp_agent_ip") .
  513. ":</td><td class='left'>".$server_home['agent_ip']."</td></tr>\n";
  514. echo "<tr><td class='right'>". get_lang("game_home") .
  515. ":</td><td class='left'>".$server_home['home_path']."</td></tr>";
  516. echo "<tr><td class='right'>". get_lang("startup_cpu") .
  517. ":</td><td class='left'>".$server_home['cpu_affinity']."</td></tr>\n";
  518. echo "<tr><td class='right'>". get_lang("startup_nice") .
  519. ":</td><td class='left'>".$server_home['nice']."</td></tr>";
  520. echo "<tr><td class='right'>". get_lang("startup_params") .
  521. ":</td><td colspan='2' style='word-wrap: break-word'>".strip_real_escape_string($start_cmd)."</td></tr>";
  522. echo "</table>";
  523. if($server_xml->replace_texts OR $server_xml->custom_fields)
  524. require_once("modules/gamemanager/cfg_text_replace.php");
  525. // Run pre-start commands
  526. if(isset($server_xml->pre_start) && !empty($server_xml->pre_start)){
  527. $preStart = trim($server_xml->pre_start);
  528. }else{
  529. $preStart = "";
  530. }
  531. // Environment variables
  532. if(isset($server_xml->environment_variables) && !empty($server_xml->environment_variables)){
  533. $envVars = trim($server_xml->environment_variables);
  534. }else{
  535. $envVars = "";
  536. }
  537. // Additional files to lock
  538. if(isset($server_xml->lock_files) && !empty($server_xml->lock_files)){
  539. $lockFiles = trim($server_xml->lock_files);
  540. }else{
  541. $lockFiles = "";
  542. }
  543. if(!empty($lockFiles)){
  544. // Linux only call
  545. if(preg_match("/Linux/", $os)){
  546. $lockedFilesStatus = $remote->lock_additional_home_files($server_home['home_path'], $lockFiles, "lock");
  547. }
  548. }
  549. $start_retval = $remote->universal_start($server_home['home_id'],
  550. $server_home['home_path'],
  551. $server_xml->server_exec_name,
  552. $server_xml->exe_location,
  553. $start_cmd, $port, $ip,
  554. $server_home['cpu_affinity'],
  555. $server_home['nice'],
  556. $preStart,
  557. $envVars,
  558. $server_xml->game_key
  559. );
  560. $db->logger( get_lang("server_started") . " (".$server_home['home_name']." $ip:$port)" );
  561. if ( $start_retval == AGENT_ERROR_NOT_EXECUTABLE )
  562. {
  563. print_failure( get_lang("server_binary_not_executable") );
  564. return;
  565. }
  566. else if ( $start_retval <= 0 )
  567. {
  568. if( $start_retval == -14 )
  569. {
  570. echo "<p>".get_lang_f('server_already_running')."<a href=?m=gamemanager&amp;p=stop&amp;home_id=".$server_home['home_id'].
  571. "&amp;ip=".$ip."&amp;port=".
  572. $port.">".get_lang_f('already_running_stop_server')."</a></p>";
  573. return;
  574. }
  575. else
  576. {
  577. print_failure(get_lang_f('failed_start_server_code',$start_retval));
  578. return;
  579. }
  580. }
  581. echo "<h3>". get_lang("starting_server_settings") .":</h3>";
  582. $firewall_settings = $db->getFirewallSettings($server_home['remote_server_id']);
  583. if ($firewall_settings['status'] == "enable")
  584. {
  585. $ip_ports = $db->getHomeIpPorts($server_home['home_id']);
  586. foreach ($ip_ports as $ip_port)
  587. {
  588. if ($server_xml->protocol == "gameq")
  589. {
  590. $query_port = get_query_port($server_xml, $ip_port['port']);
  591. }
  592. elseif ($server_xml->protocol == "lgsl")
  593. {
  594. require('protocol/lgsl/lgsl_protocol.php');
  595. $get_ports = lgsl_port_conversion((string)$server_xml->lgsl_query_name, $ip_port['port'], "", "");
  596. $query_port = $get_ports['1'];
  597. }
  598. elseif ($server_xml->protocol == "teamspeak3")
  599. {
  600. $query_port = "10011";
  601. }
  602. set_firewall($remote, $firewall_settings, 'allow', $ip_port['port'], $ip_port['ip']);
  603. if(isset($query_port) and $query_port != "" and $query_port != $ip_port['port'])
  604. set_firewall($remote, $firewall_settings, 'allow', $query_port, $ip_port['ip']);
  605. }
  606. }
  607. echo "<table class='list_table'>";
  608. if (isset($server_xml->lgsl_query_name) || isset($server_xml->gameq_query_name))
  609. {
  610. if(isset($server_xml->lgsl_query_name))$query_name = $server_xml->lgsl_query_name;
  611. else $query_name = $server_xml->gameq_query_name;
  612. }
  613. else $query_name = $server_xml->mods->mod['key'];
  614. if ( $server_xml->map_list || $server_xml->maps_location )
  615. {
  616. $map_lc = preg_replace("/[^a-z0-9_]/", "_", strtolower($cli_param_data['MAP']));
  617. //----------+ getting the maps image location.
  618. $maplocation = get_map_path($query_name,$server_xml->mods->mod['key'],$map_lc);
  619. echo "<tr><td rowspan='6' style='width:160px;'><img src='".$maplocation."' /></td><td class='right'>". get_lang("map") .
  620. ":</td><td class='left'>".$cli_param_data['MAP']."</td></tr>";
  621. }
  622. else
  623. {
  624. $icon_paths = array("images/icons/".$server_xml->mods->mod['key'].".png",
  625. "images/icons/$query_name.png",
  626. "protocol/lgsl/other/icon_unknown.gif"); // USE UKNOWN ICON
  627. $icon_path = get_first_existing_file($icon_paths);
  628. echo "<tr><td rowspan='6'><img src='".$icon_path."' /></td>";
  629. }
  630. if ( isset($cli_param_data['PLAYERS']) )
  631. {
  632. echo "<tr><td class='right'>". get_lang("max_players") .
  633. ":</td><td class='left'>".$cli_param_data['PLAYERS']."</td></tr>";
  634. }
  635. echo "<tr><td class='right'>". get_lang("server_ip_port") .
  636. ":</td><td class='left'>$ip:$port</td></tr>";
  637. echo "<tr><td class='right'>". get_lang("game_type") .
  638. ":</td><td class='left'>".$server_xml->mods->mod['key']."</td></tr>";
  639. echo "</table>";
  640. print("<p class='note'>". get_lang("starting_server") ."</p>");
  641. global $view;
  642. $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);
  643. return;
  644. }
  645. ?>