mini_start.php 21 KB

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