1
0
Эх сурвалжийг харах

Fix Duplicate Servers when Using Fixed Game Path (allow this)

own3mall 8 жил өмнө
parent
commit
a2687d1eff

+ 3 - 1
includes/database.php

@@ -86,6 +86,8 @@ abstract class OGPDatabase {
 
     abstract public function getUsersGroups($user_id);
     
+    abstract public function getGameServersWithSamePath($remote_id, $home_path);
+    
     abstract public function getUserGroupList($user_id);
 
     /// \return array of users. Array is empty if there is no users available.
@@ -288,4 +290,4 @@ abstract class OGPDatabase {
     abstract public function getHomeAffinity($home_id);
 }
 
-?>
+?>

+ 22 - 0
includes/database_mysql.php

@@ -2372,6 +2372,28 @@ class OGPDatabaseMySQL extends OGPDatabase
 		return $game_home;
 	}
 	
+	public function getGameServersWithSamePath($remote_id, $home_path){
+		$query = sprintf('SELECT * FROM `%1$sserver_homes` 
+			WHERE `home_path` LIKE \'%%2$s%\' AND remote_server_id = \'%3$d\';',
+			$this->table_prefix,
+			mysql_real_escape_string($home_path, $this->link),
+			mysql_real_escape_string($remote_id, $this->link));
+		++$this->queries_;
+		$result = mysql_query($query,$this->link);
+		if ( mysql_num_rows($result) > 0 ){
+			while ($row = mysql_fetch_assoc($result))
+			{
+				$servers[] = $row;
+			}
+		}
+
+		if(isset($servers) && is_array($servers)){
+			return $servers;
+		}
+	
+		return false;
+	}
+	
 	public function getGameHomeWithoutMods($home_id) {
 		$query = sprintf('SELECT *
 			FROM `%1$sremote_servers` 

+ 22 - 0
includes/database_mysqli.php

@@ -2375,6 +2375,28 @@ class OGPDatabaseMySQL extends OGPDatabase
 		return $game_home;
 	}
 	
+	public function getGameServersWithSamePath($remote_id, $home_path){
+		$query = sprintf('SELECT * FROM `%1$sserver_homes` 
+			WHERE `home_path` LIKE \'%%2$s%\' AND remote_server_id = \'%3$d\';',
+			$this->table_prefix,
+			mysqli_real_escape_string($this->link,$home_path),
+			mysqli_real_escape_string($this->link,$remote_id));
+		++$this->queries_;
+		$result = mysqli_query($this->link,$query);
+		if ( mysqli_num_rows($result) > 0 ){
+			while ($row = mysqli_fetch_assoc($result))
+			{
+				$servers[] = $row;
+			}
+		}
+
+		if(isset($servers) && is_array($servers)){
+			return $servers;
+		}
+	
+		return false;
+	}
+	
 	public function getGameHomeWithoutMods($home_id) {
 		$query = sprintf('SELECT *
 			FROM `%1$sremote_servers` 

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

@@ -220,4 +220,5 @@ define('expiration_date_could_not_be_changed', "Expiration date for selected hom
 define('search', "Search");
 define('ftp_account_username_too_long', "FTP username is too long. Try a shorter username no longer than 20 characters.");
 define('ftp_account_password_too_long', "FTP password is too long. Try a shorter password no longer than 20 characters.");
+define('other_servers_exist_with_path_please_change', "Other homes exist with the same path. It is recommended (but not required) that you change this path to something unique. You may have problems if you do NOT.");
 ?>

+ 7 - 2
modules/gamemanager/module.php

@@ -24,8 +24,8 @@
 
 // Module general information
 $module_title = "Game manager";
-$module_version = "1.31";
-$db_version = 6;
+$module_version = "1.32";
+$db_version = 7;
 $module_required = TRUE;
 $module_menus = array( array( 'subpage' => 'game_monitor', 'name'=>'Game Monitor', 'group'=>'user' ) );
 
@@ -102,4 +102,9 @@ $install_queries[5] = array(
 	
 $install_queries[6] = array(
 	"ALTER TABLE `".OGP_DB_PREFIX."server_homes` ADD `server_expiration_date` VARCHAR(21) NOT NULL default 'X';");
+
+$install_queries[7] = array(
+	"ALTER TABLE `".OGP_DB_PREFIX."server_homes` drop index `remote_server_id`",
+	"ALTER TABLE `".OGP_DB_PREFIX."server_homes` drop index `home_path`"
+	);
 ?>

+ 8 - 1
modules/user_games/edit_home.php

@@ -41,6 +41,9 @@ function exec_ogp_module()
 	$submit = isset($_REQUEST['submit']) ? $_REQUEST['submit'] : "";
 
 	$home_info = $db->getGameHomeWithoutMods($home_id);
+	$servers_with_same_path = $db->getGameServersWithSamePath($home_info['remote_server_id'], $home_info['home_path']); 
+	$servers_with_same_path = (is_array($servers_with_same_path) ? count($servers_with_same_path) : 0);
+	
 	$home_id = $home_info['home_id'];
 	$enabled_mods = $db->getHomeMods($home_id);
 
@@ -672,7 +675,11 @@ function exec_ogp_module()
 			 "<input type='text' size='30' name='home_path' value=\"".str_replace('"', "&quot;", $home_info['home_path'])."\" />".
 			 "<input type='submit' name='change_home' value='". change_home ."' id='change_home_path' />".
 			 "</form><button data-path=\"".str_replace('"', "&quot;", $home_info['home_path'])."\" data-home-id='".$home_id."' id='browse'>".
-			  browse ."</button></td></tr>".
+			  browse ."</button>";
+			  if($servers_with_same_path > 0){
+				print_failure(get_lang('other_servers_exist_with_path_please_change'));
+			  }
+		echo "</td></tr>".
 			 "<tr><td colspan='2' class='info'>". change_home_info ."</td></tr>";
 		
 		//Jquery path browser dialog