Pārlūkot izejas kodu

Additional Logic for Default Game Home Path Setting

own3mall 8 gadi atpakaļ
vecāks
revīzija
0e321c76b5

+ 3 - 2
includes/database_mysql.php

@@ -2308,7 +2308,7 @@ class OGPDatabaseMySQL extends OGPDatabase
 	/// \brief Adds game home to database.
 	/// \return FALSE if failure
 	/// \return id of the home in case of success.
-	public function addGameHome($rserver_id,$user_id_main,$home_cfg_id,$game_path,$server_name,$control_password,$ftp_password){
+	public function addGameHome($rserver_id,$user_id_main,$home_cfg_id,$game_path,$server_name,$control_password,$ftp_password,$skipId = false){
 		$query = sprintf("INSERT INTO `%sserver_homes`
 			( `home_id`, `remote_server_id`, `user_id_main`, `home_cfg_id`, `home_path`, `home_name`,`control_password`,`ftp_password`)
 			VALUES(NULL, '%d', '%d', '%d', '%s', '%s', '%s', '%s')",
@@ -2325,7 +2325,8 @@ class OGPDatabaseMySQL extends OGPDatabase
 		if ( mysql_affected_rows($this->link) != 1 )
 			return FALSE;
 		$homeid = mysql_insert_id($this->link);
-		$this->changeHomePath($homeid,$game_path.$homeid);
+		if(!$skipId)
+			$this->changeHomePath($homeid,$game_path.$homeid);
 		return $homeid;
 	}
 

+ 3 - 2
includes/database_mysqli.php

@@ -2307,7 +2307,7 @@ class OGPDatabaseMySQL extends OGPDatabase
 	/// \brief Adds game home to database.
 	/// \return FALSE if failure
 	/// \return id of the home in case of success.
-	public function addGameHome($rserver_id,$user_id_main,$home_cfg_id,$game_path,$server_name,$control_password,$ftp_password){
+	public function addGameHome($rserver_id,$user_id_main,$home_cfg_id,$game_path,$server_name,$control_password,$ftp_password,$skipId = false){
 		$query = sprintf("INSERT INTO `%sserver_homes`
 			( `home_id`, `remote_server_id`, `user_id_main`, `home_cfg_id`, `home_path`, `home_name`,`control_password`,`ftp_password`)
 			VALUES(NULL, '%d', '%d', '%d', '%s', '%s', '%s', '%s')",
@@ -2324,7 +2324,8 @@ class OGPDatabaseMySQL extends OGPDatabase
 		if ( mysqli_affected_rows($this->link) != 1 )
 			return FALSE;
 		$homeid = mysqli_insert_id($this->link);
-		$this->changeHomePath($homeid,$game_path.$homeid);
+		if(!$skipId)
+			$this->changeHomePath($homeid,$game_path.$homeid);
 		return $homeid;
 	}
 

+ 1 - 1
lang/English/modules/settings.php

@@ -131,5 +131,5 @@ define('bg_wrapper_info', "The wrappers background image. <b style='font-size:10
 define('show_server_id_game_monitor', "Show Server IDs on Game Monitor page");
 define('show_server_id_game_monitor_info', "Show the game server ID column on the Game Monitor for matching up files created by the Agent to the actual game server.");
 define('default_game_server_home_path_prefix', "Default game server home directory prefix");
-define('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.  Example: /ogp/games/{USERNAME} will become /ogp/games/username/1 where 1 is the game servers ID.  Example 2:  /ogp/games will become /ogp/games/1 where 1 is the game servers ID.");
+define('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.");
 ?>

+ 16 - 4
modules/user_games/add_home.php

@@ -93,7 +93,12 @@ function exec_ogp_module()
 		{
 			foreach ( $game_cfgs as $row )
 			{
-				if($row['home_cfg_id'] == $home_cfg_id) $server_name = $row['game_name'];
+				if($row['home_cfg_id'] == $home_cfg_id){
+					 $server_name = $row['game_name'];
+					 $game_key = $row['game_key'];
+					 $readable_game_key = substr($game_key, 0, stripos($game_key, "_"));
+					 $readable_game_key = strtolower($readable_game_key);
+				}
 			}
 			foreach ( $remote_servers as $server )
 			{
@@ -108,9 +113,16 @@ function exec_ogp_module()
 			// Game path logic
 			$game_path = "/home/".$ogp_user."/OGP_User_Files/"; // Default
 	
+			$skipId = false;
 			if(hasValue($default_home_dir)){
+				// Replace some user supported variables with actual value.
 				$game_path = $default_home_dir;			
-				$game_path = str_replace("{USERNAME}", $web_user,  $game_path); // Replace some user supported variables with actual value.
+				$game_path = str_replace("{USERNAME}", $web_user,  $game_path); 
+				if(stripos($game_path, "{SKIPID}") !== false){
+					$skipId = true;
+				}
+				$game_path = str_replace("{SKIPID}", "",  $game_path); 
+				$game_path = str_replace("{GAMEKEY}", $readable_game_key, $game_path);
 			}
 			
 			if($game_path[strlen($game_path)-1] != "/"){ // Make sure the path ends with forward slash
@@ -121,7 +133,7 @@ function exec_ogp_module()
 			// End game path logic
 			
 			if ( ( $new_home_id = $db->addGameHome($rserver_id,$web_user_id,$home_cfg_id,
-				clean_path($game_path),$server_name,$control_password,$ftppassword) )!== FALSE )
+				clean_path($game_path),$server_name,$control_password,$ftppassword,$skipId) )!== FALSE )
 			{				
 				$success = $db->assignHomeTo("user",$web_user_id,$new_home_id,$access_rights);
 				if($success){
@@ -130,7 +142,7 @@ function exec_ogp_module()
 					$remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key'],$home_info['timeout']);
 					
 					// Create new home directory if it doesn't already exist
-					$remote->exec("mkdir -p " . clean_path($game_path) . $new_home_id);
+					$remote->exec("mkdir -p " . clean_path($game_path) . (!$skipId ? $new_home_id : ""));
 					
 					if($ftp)
 					{

+ 18 - 4
modules/user_games/clone_home.php

@@ -30,6 +30,10 @@ function exec_ogp_module()
 	$default_home_dir = $settings["default_game_server_home_path_prefix"];
 
 	$server_row = $db->getGameHomeWithoutMods($home_id);
+	$game_key = $server_row["game_key"];
+	$readable_game_key = substr($game_key, 0, stripos($game_key, "_"));
+	$readable_game_key = strtolower($readable_game_key);
+	
 	if ( empty($server_row) )
 	{
 		print_failure(get_lang('invalid_home_id'));
@@ -52,9 +56,15 @@ function exec_ogp_module()
 		// Game path logic
 		$game_path = "/home/".$server_row['ogp_user']."/OGP_User_Files/"; // Default
 	
+		$skipId = false;
 		if(hasValue($default_home_dir)){
 			$game_path = $default_home_dir;			
 			$game_path = str_replace("{USERNAME}", $web_user,  $game_path); // Replace some user supported variables with actual value.
+			if(stripos($game_path, "{SKIPID}") !== false){
+				$skipId = true;
+			}
+			$game_path = str_replace("{SKIPID}", "",  $game_path); 
+			$game_path = str_replace("{GAMEKEY}", $readable_game_key, $game_path);
 		}
 			
 		if($game_path[strlen($game_path)-1] != "/"){ // Make sure the path ends with forward slash
@@ -65,12 +75,16 @@ function exec_ogp_module()
 		// End game path logic
 
 		$clone_home_id = $db->addGameHome($server_row['remote_server_id'], $server_row['user_id_main'],
-			$server_row['home_cfg_id'], $game_path, $server_name, '', genRandomString(8));
+			$server_row['home_cfg_id'], $game_path, $server_name, '', genRandomString(8), $skipId);
+		
+		$server_path = $game_path;
+		
+		if(!$skipId)
+			$server_path .= $clone_home_id;
 		
-		$server_path = $game_path.$clone_home_id;
+		// Create new home directory if it doesn't already exist		
+		$remote->exec("mkdir -p " . clean_path($server_path));
 		
-		// Create new home directory if it doesn't already exist
-		$remote->exec("mkdir -p " . $server_path);
 		
 		if ( $clone_home_id === FALSE )
 		{