mini_start.php 23 KB

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