Explorar o código

Merge pull request #487 from own3mall/master

CPU Affinity Fixes
OwN-3m-All %!s(int64=6) %!d(string=hai) anos
pai
achega
50bdca0c5a

+ 2 - 0
lang/English/modules/settings.php

@@ -132,6 +132,8 @@ define('OGP_LANG_default_game_server_home_path_prefix', "Default game server hom
 define('OGP_LANG_default_game_server_home_path_prefix_info', "Enter a path prefix for where you want game server homes to be created by default. You can use \"{USERNAME}\" in the path which will be replaced with the OGP username the game server is being assigned to.  You can use \"{GAMEKEY}\" in the path which will be replaced with a friendly lowercase name.  You can use \"{SKIPID}\" anywhere in the path to skip appending the home ID to the path.  Example: /ogp/games/{USERNAME}/{GAMEKEY}{SKIPID} will become /ogp/games/username/arkse/.  Example 2:  /ogp/games will become /ogp/games/1 where 1 is the game servers ID.");
 define('OGP_LANG_use_authorized_hosts', "Limit API to Defined Authorized Hosts");
 define('OGP_LANG_use_authorized_hosts_info', "Enable this setting to only allow API calls from pre-defined and approved IP addresses.  Approved addresses can be set on this page once the setting has been enabled.  If this setting is disabled, a user using a valid key will have access to the API from any IP address.  Users using a valid key will be able to use the API to manage any game server they have permissions to administrate.");
+define('OGP_LANG_allow_setting_cpu_affinity', "Allow Setting CPU Core Assignment for Game Servers");
+define('OGP_LANG_allow_setting_cpu_affinity_info', "If enabled, the admin creating a game home will be shown CPU affinity (core assignment) options for the game server.");
 define('OGP_LANG_setup_api_authorized_hosts', "Setup API authorized hosts");
 define('OGP_LANG_autohorized_hosts', "Authorized hosts");
 define('OGP_LANG_add', "Add");

+ 4 - 0
modules/settings/settings.php

@@ -69,6 +69,7 @@ function exec_ogp_module()
 			"show_server_id_game_monitor" => $_REQUEST['show_server_id_game_monitor'],
 			"default_game_server_home_path_prefix" => $_REQUEST['default_game_server_home_path_prefix'],
 			"use_authorized_hosts" => $_REQUEST['use_authorized_hosts'],
+			"allow_setting_cpu_affinity" => $_REQUEST['allow_setting_cpu_affinity'],
 		);
 		
 		$db->setSettings($settings);
@@ -180,6 +181,9 @@ function exec_ogp_module()
 	// Use authorized hosts for API - this should be disabled by default since using the KEY alone should be secure enough
 	$ft->add_field('on_off','use_authorized_hosts',@$row['use_authorized_hosts']);	
 	
+	// Allow setting the cpu affinity for game servers
+	$ft->add_field('on_off','allow_setting_cpu_affinity',@$row['allow_setting_cpu_affinity']);	
+	
 	// Add option to reset game server order to default
 	$ft->add_field('checkbox','reset_game_server_order','0');	
 	

+ 35 - 31
modules/user_games/home_mods.php

@@ -26,7 +26,7 @@ require_once("includes/lib_remote.php");
 require_once("modules/config_games/server_config_parser.php");
 function exec_ogp_module()
 {
-	global $db;
+	global $db, $settings;
 	$home_id = $_GET['home_id'];
 	echo "<h3>". get_lang("mods") ."</h3>";
 	echo "<p class='info'>". get_lang("extra_cmd_line_info") ."</p>\n";
@@ -155,7 +155,7 @@ function exec_ogp_module()
 		{
 			echo "<form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>\n".
 				 "<input type='hidden' name='home_id' value=\"$home_id\" />\n".
-				 "<p>". available_mods .": <select name='mod_cfg_id'>\n";
+				 "<p>" . get_lang("available_mods") . ": <select name='mod_cfg_id'>\n";
 			foreach ( $game_mods as $game_mod )
 			{
 				echo "<option value='".$game_mod['mod_cfg_id']."'>".$game_mod['mod_name']."</option>\n";
@@ -165,45 +165,49 @@ function exec_ogp_module()
 				 "</form>";
 		}
 
-		echo '<h3>'.get_lang('cpu_affinity').'</h3>';
-		echo "<p class='info'>". get_lang("cpu_affinity_info") ."</p>\n";
-		echo '<div id="cpu_select" class="cpu_select_div inline-block">';
+		// Get the selected cores if the setting is enabled
+		if(@$settings['allow_setting_cpu_affinity']){
+			echo '<h3>'.get_lang('cpu_affinity').'</h3>';
+			echo "<p class='info'>". get_lang("cpu_affinity_info") ."</p>\n";
+			echo '<div id="cpu_select" class="cpu_select_div inline-block">';
 		
-		// Get the selected cores.
-		$enabledCores = $db->getHomeAffinity($home_id);
-		$cores = array();
-		
-		if ($enabledCores !== 'NA')
-		{
+			$enabledCores = $db->getHomeAffinity($home_id);
+			$cores = array();
 			
-			if (preg_match('/win/', $remote->what_os()))
+			if ($enabledCores !== 'NA')
 			{
-				$coreHex = hexdec($enabledCores);
-				$cores = array();
-				$core = 0;
-
-				while ($coreHex > 0)
+				
+				if (preg_match('/win/', $remote->what_os()))
 				{
-					if ($coreHex & 1 === 1)
+					$coreHex = hexdec($enabledCores);
+					$cores = array();
+					$core = 0;
+
+					while ($coreHex > 0)
 					{
-						$cores[] = $core;
+						if ($coreHex & 1 === 1)
+						{
+							$cores[] = $core;
+						}
+						
+						$core++;
+						$coreHex >>= 1;
 					}
-					
-					$core++;
-					$coreHex >>= 1;
+				} else {
+					$cores = explode(',', $enabledCores);
 				}
-			} else {
-				$cores = explode(',', $enabledCores);
+				
 			}
 			
+			$cores = array_filter($cores, 'strlen'); // Don't strip out 0 as a value... default to unchecked
+			
+			for($x = 0; $x <= $cpu_count; ++$x)
+			{
+				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>';
+			}
+			
+			echo '<button class="set_options set_affinity_button" id="'.$enabled_rows['mod_cfg_id'].'" style="margin-left:10px;">'.get_lang('set_affinity').'</button></div>';
 		}
-		
-		for($x = 0; $x <= $cpu_count; ++$x)
-		{
-			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>';
-		}
-		
-		echo '<button class="set_options set_affinity_button" id="'.$enabled_rows['mod_cfg_id'].'" style="margin-left:10px;">'.get_lang('set_affinity').'</button></div>';
 	}
 	?>
 	<script type="text/javascript" src="js/modules/user_games-mods.js"></script>