Просмотр исходного кода

Multiple Core Assignement

Accidentally removed these when creating a branch for the auto-update
feature. Woops.

But I was able to test it now on Windows. Previously only on Linux Mint.
Can confirm it works on both... only needed a slight change for Windows.
Adjokip 9 лет назад
Родитель
Сommit
a2e546b5c3

+ 10 - 2
js/modules/user_games-mods.js

@@ -6,9 +6,17 @@ $('.set_options').click(function(){
 	var mod_cfg_id = $(this).attr('id');
 	var modtr = $('#mod_cfg_id_'+mod_cfg_id);
 	var addpost = {};
+	
+	var cpus = [];
+
+	$("#cpu_select").find('.cpus:checked').each(function(i, e) {
+		cpus.push($(this).val());
+		addpost['cpus'] = cpus.join();
+	});
+
 	addpost[ 'set_options' ] = 1;
 	addpost[ 'cliopts' ] = modtr.find('#cliopts').val();
-	addpost[ 'cpus' ] = modtr.find('#cpus').val();
+
 	addpost[ 'nice' ] = modtr.find('#nice').val();
 	addpost[ 'mod_cfg_id' ] = mod_cfg_id;
 	if( modtr.find('#maxplayers').get(0) )
@@ -28,4 +36,4 @@ $('.set_options').click(function(){
 		},
 		dataType: "json"
 	});
-});
+});

+ 1 - 0
lang/English/modules/user_games.php

@@ -212,4 +212,5 @@ define('add_folder', "Add folder");
 define('add_folder_info', "Write the name for the new folder, then click on the icon.");
 define('valid_user', "Please specify a valid user.");
 define('valid_group', "Please specify a valid group.");
+define('set_affinity', "Set Server Affinity");
 ?>

+ 44 - 2
modules/user_games/edit_home.php

@@ -504,8 +504,50 @@ function exec_ogp_module()
 		{
 			$maxplayers = 0 + @$_POST['maxplayers'];
 			$cliopts = $_POST['cliopts'];
-			$cpus = $_POST['cpus'];
-			$nice = $_POST['nice'];
+
+			// Get the total CPU count. and, if the agent is offline, set the CPU to NA.
+			$remoteCpus = $remote->cpu_count();
+			$validCpus = $remoteCpus === -1 ? 'NA' : $remoteCpus-1;
+
+			if(isset($_POST['cpus']) && $validCpus !== 'NA')
+			{
+				$cpuArray = explode(',', $_POST['cpus']);
+
+				// Check if a a valid core has been submitted. eg, the checkbox hasn't been manually edited.
+				foreach($cpuArray as $cpu)
+				{
+					if($cpu > $validCpus || !is_numeric($cpu))
+					{
+						$cpus = 'NA';
+						break;
+					} else {
+						$cpus[] = $cpu;
+					}
+				}
+
+				// If $cpus is an array, seperate all the values with a comma. Otherwise, just pass $cpus to the query - which, as above, will be NA.
+				$cpus = is_array($cpus) ? implode(',', $cpus) : $cpus;
+
+			} else {
+				$cpus = 'NA';
+			}
+
+			// If we're on Windows, and some cores have been selected...
+			if(preg_match('/win/', $remote->what_os()) && $cpus !== 'NA')
+			{
+				$result = 0;
+				$cores = explode(',', $cpus);
+
+				foreach ($cores as $core)
+				{
+					$coreNum = intval($core);
+					$result |= (1 << $coreNum);
+				}
+
+				$cpus = strtoupper(dechex($result));
+			}
+
+			$nice = isset($_POST['nice']) ? (int)$_POST['nice'] : 0;
 			$mod_cfg_id = $_POST['mod_cfg_id'];
 
 			if ( $db->updateGameModParams($maxplayers,$cliopts,$cpus,$nice,$home_id,$mod_cfg_id) === TRUE )

+ 21 - 12
modules/user_games/home_mods.php

@@ -93,15 +93,14 @@ function exec_ogp_module()
 	if( !empty($enabled_mods) )
 	{
 		$cpu_count = $remote->cpu_count();
+		
 		if($cpu_count === -1)
 		{
 			print_failure( warning_agent_offline_defaulting_CPU_count_to_1 );
 			$cpu_count = 'NA';
-		}
-		else
-		{
+		} else {
 			// cpu numbering starts from 0 so lets remove the last cpu.
-			$cpu_count -= 1;
+			--$cpu_count;
 		}
 
 		echo "<table class='center'>\n".
@@ -111,7 +110,6 @@ function exec_ogp_module()
 		if ( $server_xml->max_user_amount )
 			echo "<td><b>". max_players ."</b></td>";
 		echo "<td><b>". extra_cmd_line_args ."</b></td>".
-			 "<td><b>". cpu_affinity ."</b></td>".
 			 "<td><b>". nice_level ."</b></td><td></td>".
 			 "</tr>\n";
 		foreach ( $enabled_mods as $enabled_rows ) {
@@ -130,17 +128,28 @@ function exec_ogp_module()
 			}
 			echo "<input id='cliopts' type='text' name='cliopts' size='20' value=\"".
 				 str_replace('"', "&quot;", strip_real_escape_string($enabled_rows['extra_params']))."\" />".
-				 "</td><td>\n".
-				 create_drop_box_from_array(array_merge(array('NA'),range(0,$cpu_count)),
-				 'cpus',$enabled_rows['cpu_affinity']).
-				 "</td><td>\n".
-				 create_drop_box_from_array(array_merge(range(-19,19)),
+				 "</td><td>\n";
+
+				 echo create_drop_box_from_array(array_merge(range(-19,19)),
 				 'nice',$enabled_rows['nice']).
 				 "</td><td>\n".
 				 "<button class='set_options' id='$enabled_rows[mod_cfg_id]' >". set_options ."</button>\n".
 				 "</td></tr>\n";
+
 		}
-		echo "</table>\n";
+			
+		echo '</table>';
+
+		echo '<h2>'.get_lang('cpu_affinity').'</h2>';
+		echo '<div id="cpu_select">';
+		
+		for($x = 0; $x <= $cpu_count; ++$x)
+		{
+			echo '<span style="display:inline-block;"><label for="cpu_'.$x.'">CPU '.$x.'</label> <input type="checkbox" name="cpus[]" value="'.$x.'" id="cpu_'.$x.'" class="cpus" /></span>';
+		}
+		
+		echo '</div><button class="set_options" id="'.$enabled_rows['mod_cfg_id'].'" style="float:right">'.get_lang('set_affinity').'</button>';
+
 		$game_mods = $db->getAvailableModsForGameHome($home_id);
 		$mods_available = 0;
 		foreach ( $game_mods as $game_mod )
@@ -169,4 +178,4 @@ function exec_ogp_module()
 	<script type="text/javascript" src="js/modules/user_games-mods.js"></script>
 	<?php
 }
-?>
+?>

+ 6 - 2
modules/user_games/module.php

@@ -25,7 +25,7 @@
 // Module general information
 $module_title = "User games";
 $module_version = "1.3";
-$db_version = 2;
+$db_version = 3;
 $module_required = TRUE;
 $module_menus = array(
 	array( 'subpage' => '', 'name'=>'Game Servers', 'group'=>'admin' )
@@ -66,4 +66,8 @@ $install_queries[1] = array(
 $install_queries[2] = array(
 	"ALTER TABLE `".OGP_DB_PREFIX."user_homes` ADD `user_expiration_date` VARCHAR(21) NOT NULL default 'X';",
 	"ALTER TABLE `".OGP_DB_PREFIX."user_group_homes` ADD `user_group_expiration_date` VARCHAR(21) NOT NULL default 'X';");
-?>
+
+$install_queries[3] = array(
+	"ALTER TABLE `".OGP_DB_PREFIX."game_mods` modify column `cpu_affinity` varchar(64) null AFTER `extra_params`, comment = 'utf8mb4_general_ci'";
+	);
+?>