Преглед изворни кода

Remember Checked Affinity Boxes.

As per @FarukGamer and @Zorrototo's suggestion, this pull request will
put the 'checked' attribute on each checkbox next to the CPU checkboxes
which are currently assigned to a server.

I added a new database method so the data may be used elsewhere if so
desired.

Tested on Windows and Linux Mint.
Adjokip пре 9 година
родитељ
комит
42ccf52ff3
4 измењених фајлова са 89 додато и 16 уклоњено
  1. 15 13
      includes/database.php
  2. 22 1
      includes/database_mysql.php
  3. 22 1
      includes/database_mysqli.php
  4. 30 1
      modules/user_games/home_mods.php

+ 15 - 13
includes/database.php

@@ -66,8 +66,8 @@ abstract class OGPDatabase {
     abstract public function getGroupList();
 
     abstract public function getUsersGroups($user_id);
-	
-	abstract public function getUserGroupList($user_id);
+    
+    abstract public function getUserGroupList($user_id);
 
     /// \return array of users. Array is empty if there is no users available.
     abstract public function getAvailableUsersForGroup($group_id);
@@ -116,7 +116,7 @@ abstract class OGPDatabase {
 
     abstract public function addModule($module_title,$module,$module_version,$db_version);
 
-	abstract public function getModuleMenu($module_id);
+    abstract public function getModuleMenu($module_id);
 
     abstract public function addModuleMenu($module_id,$subpage,$group,$name,$pos);
 
@@ -177,8 +177,8 @@ abstract class OGPDatabase {
     abstract public function isIpPortOwnedByUser($user_id, $ip, $port);
 
     abstract public function getRemoteServerById($remote_server_id);
-	
-	abstract public function getCfgHomeById($cfgid);
+    
+    abstract public function getCfgHomeById($cfgid);
 
     abstract public function getIpPortsForUser($user_id);
 
@@ -219,11 +219,11 @@ abstract class OGPDatabase {
     abstract public function delGameMod($mod_id);
 
     abstract public function changeHomePath($home_id,$path);
-	
-	abstract public function changeUserIdMain($home_id,$userid);
-	
-	abstract public function changeFtpPassword($home_id,$password);
-	
+    
+    abstract public function changeUserIdMain($home_id,$userid);
+    
+    abstract public function changeFtpPassword($home_id,$password);
+    
     /// \brief get available mods for game home.
     abstract public function getAvailableModsForGameHome($home_id);
 
@@ -245,8 +245,10 @@ abstract class OGPDatabase {
     /// \return true If username and password match.
     /// \return false If username and password does not match
     abstract public function is_valid_login($username,$password);
-	
-	abstract public function getTablePrefix();
+    
+    abstract public function getTablePrefix();
+    
+    abstract public function getHomeAffinity($home_id);
 }
 
-?>
+?>

+ 22 - 1
includes/database_mysql.php

@@ -2824,6 +2824,27 @@ class OGPDatabaseMySQL extends OGPDatabase
 		}
 		return FALSE;
 	}
+	
+	public function getHomeAffinity ($home_id)
+	{
+		if (is_numeric($home_id) === false)
+		{
+			return false;
+		}
+		
+		$query = 'SELECT `cpu_affinity` FROM `%sgame_mods` WHERE `home_id` = %2$d;';
+		$query = sprintf($query, $this->table_prefix, (int)$home_id);
+		
+		$result = mysql_query($query, $this->link);
+		++$this->queries_;
+		
+		if($result === false)
+		{
+			return false;
+		}
+		
+		return mysql_fetch_row($result)[0];
+	}
 }
 
-?>
+?>

+ 22 - 1
includes/database_mysqli.php

@@ -2831,6 +2831,27 @@ class OGPDatabaseMySQL extends OGPDatabase
 		}
 		return FALSE;
 	}
+	
+	public function getHomeAffinity ($home_id)
+	{
+		if (is_numeric($home_id) === false)
+		{
+			return false;
+		}
+		
+		$query = 'SELECT `cpu_affinity` FROM `%sgame_mods` WHERE `home_id` = %2$d;';
+		$query = sprintf($query, $this->table_prefix, (int)$home_id);
+		
+		$result = mysqli_query($this->link, $query);
+		++$this->queries_;
+		
+		if($result === false)
+		{
+			return false;
+		}
+		
+		return mysqli_fetch_row($result)[0];
+	}
 }
 
-?>
+?>

+ 30 - 1
modules/user_games/home_mods.php

@@ -143,9 +143,38 @@ function exec_ogp_module()
 		echo '<h2>'.get_lang('cpu_affinity').'</h2>';
 		echo '<div id="cpu_select">';
 		
+		// Get the selected cores.
+		$enabledCores = $db->getHomeAffinity($home_id);
+		$cores = [];
+		
+		if ($enabledCores !== 'NA')
+		{
+			
+			if (preg_match('/win/', $remote->what_os()))
+			{
+				$coreHex = hexdec($enabledCores);
+				$cores = [];
+				$core = 0;
+
+				while ($coreHex > 0)
+				{
+					if ($coreHex & 1 === 1)
+					{
+						$cores[] = $core;
+					}
+					
+					$core++;
+					$coreHex >>= 1;
+				}
+			} else {
+				$cores = explode(',', $enabledCores);
+			}
+			
+		}
+		
 		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 '<span style="display:inline-block;"><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 '</div><button class="set_options" id="'.$enabled_rows['mod_cfg_id'].'" style="float:right">'.get_lang('set_affinity').'</button>';