home_mods.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. require_once("includes/lib_remote.php");
  25. require_once("modules/config_games/server_config_parser.php");
  26. function exec_ogp_module()
  27. {
  28. global $db;
  29. $home_id = $_GET['home_id'];
  30. echo "<h3>". mods ."</h3>";
  31. echo "<p class='info'>". extra_cmd_line_info ."</p>\n";
  32. $enabled_mods = $db->getHomeMods($home_id);
  33. $home_info = $db->getGameHomeWithoutMods($home_id);
  34. $server_xml = read_server_config(SERVER_CONFIG_LOCATION.$home_info['home_cfg_file']);
  35. $remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key'], $home_info['timeout']);
  36. if( empty($enabled_mods) )
  37. {
  38. $cpu_count = $remote->cpu_count();
  39. if($cpu_count === -1)
  40. {
  41. print_failure( warning_agent_offline_defaulting_CPU_count_to_1 );
  42. $cpu_count = 'NA';
  43. }
  44. else
  45. {
  46. // cpu numbering starts from 0 so lets remove the last cpu.
  47. $cpu_count -= 1;
  48. }
  49. $game_mods = $db->getAvailableModsForGameHome($home_id);
  50. foreach ( $game_mods as $game_mod )
  51. {
  52. if( preg_match("/^none$/i", $game_mod['mod_name']) )
  53. {
  54. $mod_cfg_id = $game_mod['mod_cfg_id'];
  55. break;
  56. }
  57. }
  58. if( isset($mod_cfg_id) )
  59. {
  60. if ( $db->addModToGameHome($home_id,$mod_cfg_id) === FALSE )
  61. {
  62. print_failure(get_lang_f('failed_to_assing_mod_to_home',$mod_cfg_id));
  63. }
  64. else
  65. {
  66. $maxplayers = $server_xml->max_user_amount ? $server_xml->max_user_amount : 0;
  67. if( $db->updateGameModParams($maxplayers,'','NA','0',$home_id,$mod_cfg_id) === FALSE )
  68. {
  69. print_failure(get_lang_f('failed_to_assing_mod_to_home',$mod_cfg_id));
  70. }
  71. else
  72. $enabled_mods = $db->getHomeMods($home_id);
  73. }
  74. }
  75. else
  76. {
  77. print_failure( note .":". note_no_mods );
  78. echo "<form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>\n";
  79. echo "<input type='hidden' name='home_id' value=\"$home_id\" />\n";
  80. echo "<p>". available_mods .": <select name='mod_cfg_id'>\n";
  81. foreach ( $game_mods as $game_mod )
  82. {
  83. echo "<option value='".$game_mod['mod_cfg_id']."'>".$game_mod['mod_name']."</option>\n";
  84. }
  85. echo "</select>\n";
  86. echo "<input type='submit' name='add_mod' value='". add_mod ."' /></p>";
  87. echo "</form>";
  88. }
  89. }
  90. if( !empty($enabled_mods) )
  91. {
  92. $cpu_count = $remote->cpu_count();
  93. if($cpu_count === -1)
  94. {
  95. print_failure( warning_agent_offline_defaulting_CPU_count_to_1 );
  96. $cpu_count = 'NA';
  97. } else {
  98. // cpu numbering starts from 0 so lets remove the last cpu.
  99. --$cpu_count;
  100. }
  101. echo "<table class='center'>\n".
  102. "<tr>".
  103. "<td></td>".
  104. "<td><b>". mod_name ."</b></td>";
  105. if ( $server_xml->max_user_amount )
  106. echo "<td><b>". max_players ."</b></td>";
  107. echo "<td><b>". extra_cmd_line_args ."</b></td>".
  108. "<td><b>". nice_level ."</b></td><td></td>".
  109. "</tr>\n";
  110. foreach ( $enabled_mods as $enabled_rows ) {
  111. echo "<tr id='mod_cfg_id_$enabled_rows[mod_cfg_id]'>".
  112. "<td><a href='?m=user_games&amp;p=edit&amp;mod_id=".$enabled_rows['mod_id'].
  113. "&amp;home_id=$home_id&amp;submit=delete_mod'>[ ". remove_mod ." ]</a><br>".
  114. "<a href='?m=user_games&p=install_cmds&home_id=$home_id&mod_id=".$enabled_rows['mod_id'].
  115. "'>". mod_install_cmds ."</a></td>\n".
  116. "<td>".$enabled_rows['mod_name']."</td>\n".
  117. "<td>\n";
  118. if ( $server_xml->max_user_amount )
  119. {
  120. echo create_drop_box_from_array(range(0,$server_xml->max_user_amount),
  121. 'maxplayers',$enabled_rows['max_players'],true).
  122. "</td><td>";
  123. }
  124. echo "<input id='cliopts' type='text' name='cliopts' size='20' value=\"".
  125. str_replace('"', "&quot;", strip_real_escape_string($enabled_rows['extra_params']))."\" />".
  126. "</td><td>\n";
  127. echo create_drop_box_from_array(array_merge(range(-19,19)),
  128. 'nice',$enabled_rows['nice']).
  129. "</td><td>\n".
  130. "<button class='set_options' id='$enabled_rows[mod_cfg_id]' >". set_options ."</button>\n".
  131. "</td></tr>\n";
  132. }
  133. echo '</table>';
  134. $game_mods = $db->getAvailableModsForGameHome($home_id);
  135. $mods_available = 0;
  136. foreach ( $game_mods as $game_mod )
  137. {
  138. if( !preg_match("/^none$/i", $game_mod['mod_name']) )
  139. {
  140. $mods_available++;
  141. break;
  142. }
  143. }
  144. if($mods_available > 0)
  145. {
  146. echo "<form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>\n".
  147. "<input type='hidden' name='home_id' value=\"$home_id\" />\n".
  148. "<p>". available_mods .": <select name='mod_cfg_id'>\n";
  149. foreach ( $game_mods as $game_mod )
  150. {
  151. echo "<option value='".$game_mod['mod_cfg_id']."'>".$game_mod['mod_name']."</option>\n";
  152. }
  153. echo "</select>\n".
  154. "<input type='submit' name='add_mod' value='". add_mod ."' /></p>".
  155. "</form>";
  156. }
  157. echo '<h3>'.get_lang('cpu_affinity').'</h3>';
  158. echo "<p class='info'>". cpu_affinity_info ."</p>\n";
  159. echo '<div id="cpu_select" class="cpu_select_div inline-block">';
  160. // Get the selected cores.
  161. $enabledCores = $db->getHomeAffinity($home_id);
  162. $cores = array();
  163. if ($enabledCores !== 'NA')
  164. {
  165. if (preg_match('/win/', $remote->what_os()))
  166. {
  167. $coreHex = hexdec($enabledCores);
  168. $cores = array();
  169. $core = 0;
  170. while ($coreHex > 0)
  171. {
  172. if ($coreHex & 1 === 1)
  173. {
  174. $cores[] = $core;
  175. }
  176. $core++;
  177. $coreHex >>= 1;
  178. }
  179. } else {
  180. $cores = explode(',', $enabledCores);
  181. }
  182. }
  183. for($x = 0; $x <= $cpu_count; ++$x)
  184. {
  185. echo '<span><label for="cpu_'.$x.'">CPU '.$x.'</label> <input type="checkbox" name="cpus[]" value="'.$x.'" id="cpu_'.$x.'" class="cpus" '. ( in_array($x, $cores) ? 'checked' : '' ) .'/></span>';
  186. }
  187. echo '<button class="set_options set_affinity_button" id="'.$enabled_rows['mod_cfg_id'].'" style="margin-left:10px;">'.get_lang('set_affinity').'</button></div>';
  188. }
  189. ?>
  190. <script type="text/javascript" src="js/modules/user_games-mods.js"></script>
  191. <?php
  192. }
  193. ?>