mini_start.php 24 KB

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