mini_start.php 22 KB

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