mini_start.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2017 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] = True;
  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', 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'>". 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'>". 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'>(". max .": ".
  111. $max_players.")</span></td></tr>\n";
  112. }
  113. $display_ip = checkDisplayPublicIP($server_home['display_public_ip'],$server_home['ip']);
  114. echo "<tr><td class='right'>". 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'>". 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'>". maps_read_from ." ";
  169. if ( $maps_found == "DIR" )
  170. {
  171. echo directory ." ".clean_path($map_path).".";
  172. }
  173. else
  174. {
  175. echo 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'>". 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>". extra_parameters ."</h3>";
  210. if (!$extra_param_access_enabled)
  211. echo "<span class='failure info'>". 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'>". extra_parameters_info ."</td></tr>";
  223. }
  224. echo "</table>";
  225. echo start_wait_note;
  226. if ( $check_ok )
  227. {
  228. echo "<div class='submit-start' ><input type='submit' name='start_server' value='".
  229. 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 && isset($_REQUEST['params']) )
  388. {
  389. foreach($server_xml->server_params->param as $param)
  390. {
  391. // Get the last saved value of this param or its default value
  392. if (array_key_exists((string)$param['key'], $last_param)){
  393. $origValue = (string)$last_param[(string)$param['key']];
  394. }else{
  395. $origValue = "";
  396. }
  397. // Loop through each posted param and process them
  398. $found = 0;
  399. foreach ( $_REQUEST['params'] as $paramKey => $paramValue )
  400. {
  401. // Dependency fields...
  402. if(stripos($paramKey, "{DEPENDS") !== false){
  403. $dependsSection = strrpos($paramKey, "{DEPENDS");
  404. $realKey = substr($paramKey, 0, $dependsSection);
  405. $dependsSection = substr($paramKey, $dependsSection);
  406. $dependsKey = str_replace("{DEPENDS:", "", $dependsSection);
  407. $dependsKey = str_replace("}", "", $dependsKey);
  408. if(hasValue($_REQUEST['params'][$dependsKey])){
  409. $additionalValue = $_REQUEST['params'][$dependsKey];
  410. // Remove leading slashes if there are any for additional game path
  411. if($dependsKey == "other_game_server_path_additional"){
  412. $additionalValue = ltrim($additionalValue,'/');
  413. }
  414. $paramValue .= $additionalValue;
  415. }
  416. $paramKey = $realKey;
  417. }
  418. if ($param['key'] == $paramKey)
  419. {
  420. // If locked by an admin, ignore the value posted by the user
  421. $lockedByAdmin = false;
  422. if(property_exists($param, 'access') && $param->access == "admin")
  423. {
  424. $lockedByAdmin = true;
  425. if(!$isAdmin){
  426. $paramValue = $origValue; // Set it to the old saved value (which was last set by an admin) or set it to its default value
  427. }
  428. }
  429. // Process the param value for the start command and for the save params
  430. processParamValue($param, $server_xml, $paramKey, $paramValue, $save_param, $start_cmd);
  431. $found++;
  432. break; // More efficient
  433. }
  434. }
  435. // 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
  436. if($found == 0 && !empty($origValue)){
  437. processParamValue($param, $server_xml, (string)$param['key'], $origValue, $save_param, $start_cmd);
  438. }
  439. if ($param['id'] != NULL && $param['id'] != ""){
  440. $start_cmd = preg_replace( "/%".$param['id']."%/", '', $start_cmd );
  441. }
  442. }
  443. }
  444. elseif( !$param_access_enabled )
  445. {
  446. foreach($server_xml->server_params->param as $param)
  447. {
  448. foreach ( $last_param as $paramKey => $paramValue )
  449. {
  450. if ($param['key'] == $paramKey)
  451. {
  452. if (0 == strlen($paramValue))
  453. continue;
  454. if ($paramKey == $paramValue) // it's a checkbox
  455. {
  456. $new_param = $paramKey;
  457. $save_param[$paramKey] = True;
  458. }
  459. elseif($param->option == "ns" or $param->options == "ns")
  460. {
  461. $new_param = $paramKey.clean_server_param_value($paramValue, $server_xml->cli_allow_chars);
  462. $save_param[$paramKey] = $paramValue;
  463. }
  464. elseif($param->option == "q" or $param->options == "q"){
  465. $new_param = $paramKey . '"' . clean_server_param_value($paramValue, $server_xml->cli_allow_chars) . '"';
  466. $save_param[$paramKey] = $paramValue;
  467. }
  468. elseif($param->option == "s" or $param->options == "s"){
  469. $new_param = $paramKey . ' ' . clean_server_param_value($paramValue, $server_xml->cli_allow_chars);
  470. $save_param[$paramKey] = $paramValue;
  471. }
  472. else
  473. {
  474. $new_param = $paramKey.' "'.clean_server_param_value($paramValue, $server_xml->cli_allow_chars).'"';
  475. $save_param[$paramKey] = $paramValue;
  476. }
  477. if ($param['id'] == NULL || $param['id'] == "")
  478. {
  479. $start_cmd .= ' '.$new_param;
  480. }
  481. else
  482. {
  483. $start_cmd = preg_replace( "/%".$param['id']."%/", $new_param, $start_cmd );
  484. }
  485. }
  486. }
  487. if ($param['id'] != NULL && $param['id'] != ""){
  488. $start_cmd = preg_replace( "/%".$param['id']."%/", '', $start_cmd );
  489. }
  490. }
  491. }
  492. }
  493. $save_param['map'] = $cli_param_data['MAP'];
  494. $save_param['players'] = $cli_param_data['PLAYERS'];
  495. if ( $extra_param_access_enabled )
  496. {
  497. if(isset($_REQUEST['extra_params']) and $_REQUEST['extra_params'] != "")
  498. {
  499. $start_cmd .= " ".str_replace("\\\\", "\\", clean_server_param_value($_REQUEST['extra_params'], $server_xml->cli_allow_chars));
  500. $save_param['extra'] = $_REQUEST['extra_params'];
  501. }
  502. }
  503. else
  504. {
  505. // If user does not have access to modify extra params then we use
  506. // the last param or default set by admins.
  507. $extra = ($last_param !== NULL and array_key_exists('extra', $last_param) and $last_param['extra'] != "") ?
  508. $last_param['extra'] : $server_home['extra_params'];
  509. $start_cmd .= " ".str_replace("\\\\", "\\", clean_server_param_value($extra, $server_xml->cli_allow_chars));
  510. $save_param['extra'] = $extra;
  511. }
  512. //Save the param used to the database
  513. $db->changeLastParam($server_home['home_id'],json_encode($save_param));
  514. echo "<table class='server-starting'>";
  515. echo "<tr><td class='right'>". ogp_agent_ip .
  516. ":</td><td class='left'>".$server_home['agent_ip']."</td></tr>\n";
  517. echo "<tr><td class='right'>". game_home .
  518. ":</td><td class='left'>".$server_home['home_path']."</td></tr>";
  519. echo "<tr><td class='right'>". startup_cpu .
  520. ":</td><td class='left'>".$server_home['cpu_affinity']."</td></tr>\n";
  521. echo "<tr><td class='right'>". startup_nice .
  522. ":</td><td class='left'>".$server_home['nice']."</td></tr>";
  523. echo "<tr><td class='right'>". startup_params .
  524. ":</td><td colspan='2' style='word-wrap: break-word'>".strip_real_escape_string($start_cmd)."</td></tr>";
  525. echo "</table>";
  526. if($server_xml->replace_texts OR $server_xml->custom_fields)
  527. require_once("modules/gamemanager/cfg_text_replace.php");
  528. // Run pre-start commands
  529. if(isset($server_xml->pre_start) && !empty($server_xml->pre_start)){
  530. $preStart = trim($server_xml->pre_start);
  531. }else{
  532. $preStart = "";
  533. }
  534. // Environment variables
  535. if(isset($server_xml->environment_variables) && !empty($server_xml->environment_variables)){
  536. $envVars = trim($server_xml->environment_variables);
  537. }else{
  538. $envVars = "";
  539. }
  540. // Additional files to lock
  541. if(isset($server_xml->lock_files) && !empty($server_xml->lock_files)){
  542. $lockFiles = trim($server_xml->lock_files);
  543. }else{
  544. $lockFiles = "";
  545. }
  546. if(!empty($lockFiles)){
  547. // Linux only call
  548. if(preg_match("/Linux/", $os)){
  549. $lockedFilesStatus = $remote->lock_additional_home_files($server_home['home_path'], $lockFiles, "lock");
  550. }
  551. }
  552. $start_retval = $remote->universal_start($server_home['home_id'],
  553. $server_home['home_path'],
  554. $server_xml->server_exec_name,
  555. $server_xml->exe_location,
  556. $start_cmd, $port, $ip,
  557. $server_home['cpu_affinity'],
  558. $server_home['nice'],
  559. $preStart,
  560. $envVars,
  561. $server_xml->game_key
  562. );
  563. $db->logger( 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>". 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. }
  616. else $query_name = $server_xml->mods->mod['key'];
  617. if ( $server_xml->map_list || $server_xml->maps_location )
  618. {
  619. $map_lc = preg_replace("/[^a-z0-9_]/", "_", strtolower($cli_param_data['MAP']));
  620. //----------+ getting the maps image location.
  621. $maplocation = get_map_path($query_name,$server_xml->mods->mod['key'],$map_lc);
  622. echo "<tr><td rowspan='6' style='width:160px;'><img src='".$maplocation."' /></td><td class='right'>". map .
  623. ":</td><td class='left'>".$cli_param_data['MAP']."</td></tr>";
  624. }
  625. else
  626. {
  627. $icon_paths = array("images/icons/".$server_xml->mods->mod['key'].".png",
  628. "images/icons/$query_name.png",
  629. "protocol/lgsl/other/icon_unknown.gif"); // USE UKNOWN ICON
  630. $icon_path = get_first_existing_file($icon_paths);
  631. echo "<tr><td rowspan='6'><img src='".$icon_path."' /></td>";
  632. }
  633. if ( isset($cli_param_data['PLAYERS']) )
  634. {
  635. echo "<tr><td class='right'>". max_players .
  636. ":</td><td class='left'>".$cli_param_data['PLAYERS']."</td></tr>";
  637. }
  638. echo "<tr><td class='right'>". server_ip_port .
  639. ":</td><td class='left'>$ip:$port</td></tr>";
  640. echo "<tr><td class='right'>". game_type .
  641. ":</td><td class='left'>".$server_xml->mods->mod['key']."</td></tr>";
  642. echo "</table>";
  643. print("<p class='note'>". starting_server ."</p>");
  644. global $view;
  645. $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);
  646. return;
  647. }
  648. ?>