From 42857fe4e9e898c8e350da2f9acb3b252b31694a Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Tue, 18 Mar 2008 05:44:25 +0000 Subject: [PATCH] * Added the ability to type the partial name of a region in the start location box and go to that region if it's there. If no close match was found, it sends you home. This is tested on mySQL. There's untested code on grids that are based on sqlite and MSSQL. The SQL statements *should* be right, but your results may very. * Ex, if you want to go to Wright Plaza, you simply need to type Wright Plaza in the start location in the client when you log-in. --- .../Framework/Communications/IGridServices.cs | 1 + OpenSim/Framework/Data.DB4o/DB4oGridData.cs | 5 ++ OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs | 43 +++++++++++++++ OpenSim/Framework/Data.MySQL/MySQLGridData.cs | 41 ++++++++++++++ .../Framework/Data.SQLite/SQLiteGridData.cs | 32 +++++++++++ OpenSim/Framework/Data/GridData.cs | 7 +++ OpenSim/Framework/Data/RegionProfileData.cs | 42 +++++++++++++++ OpenSim/Framework/Util.cs | 48 +++++++++++++++++ OpenSim/Grid/GridServer/GridManager.cs | 25 +++++++++ OpenSim/Grid/UserServer/UserLoginService.cs | 38 +++++++++++-- .../Local/LocalBackEndServices.cs | 6 +++ .../Communications/Local/LocalLoginService.cs | 2 + .../Communications/OGS1/OGS1GridServices.cs | 53 +++++++++++++++++++ 13 files changed, 338 insertions(+), 5 deletions(-) diff --git a/OpenSim/Framework/Communications/IGridServices.cs b/OpenSim/Framework/Communications/IGridServices.cs index 14baf3fcd8..3e2a5daaea 100644 --- a/OpenSim/Framework/Communications/IGridServices.cs +++ b/OpenSim/Framework/Communications/IGridServices.cs @@ -36,6 +36,7 @@ namespace OpenSim.Framework.Communications bool DeregisterRegion(RegionInfo regionInfo); List RequestNeighbours(uint x, uint y); RegionInfo RequestNeighbourInfo(ulong regionHandle); + RegionInfo RequestClosestRegion(string regionName); Dictionary GetGridSettings(); List RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY); } diff --git a/OpenSim/Framework/Data.DB4o/DB4oGridData.cs b/OpenSim/Framework/Data.DB4o/DB4oGridData.cs index b11af82e2d..999d4f88ea 100644 --- a/OpenSim/Framework/Data.DB4o/DB4oGridData.cs +++ b/OpenSim/Framework/Data.DB4o/DB4oGridData.cs @@ -98,6 +98,11 @@ namespace OpenSim.Framework.Data.DB4o "). Total Registered Regions: " + manager.simProfiles.Count); } + public RegionProfileData GetProfileByString(string regionName) + { + throw new Exception("GetProfileByString Not supported in DB4oGridData"); + //return null; + } /// /// Adds a new specified region to the database /// diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs index 2b91cf94c9..38a1d08929 100644 --- a/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs +++ b/OpenSim/Framework/Data.MSSQL/MSSQLGridData.cs @@ -180,6 +180,49 @@ namespace OpenSim.Framework.Data.MSSQL return row; } + + /// + /// Returns a sim profile from it's Region name string + /// + /// The region name search query + /// The sim profile + public RegionProfileData GetProfileByString(string regionName) + { + if (regionName.Length > 2) + { + try + { + lock (database) + { + Dictionary param = new Dictionary(); + // Add % because this is a like query. + param["?regionName"] = regionName + "%"; + // Order by statement will return shorter matches first. Only returns one record or no record. + IDbCommand result = database.Query("SELECT top 1 * FROM " + m_regionsTableName + " WHERE regionName like ?regionName order by regionName", param); + IDataReader reader = result.ExecuteReader(); + + RegionProfileData row = database.getRegionRow(reader); + reader.Close(); + result.Dispose(); + + return row; + } + } + catch (Exception e) + { + database.Reconnect(); + m_log.Error(e.ToString()); + return null; + } + } + else + { + m_log.Error("[DATABASE]: Searched for a Region Name shorter then 3 characters"); + return null; + } + } + + /// /// Adds a new specified region to the database /// diff --git a/OpenSim/Framework/Data.MySQL/MySQLGridData.cs b/OpenSim/Framework/Data.MySQL/MySQLGridData.cs index 584d49c5db..3855d99ee5 100644 --- a/OpenSim/Framework/Data.MySQL/MySQLGridData.cs +++ b/OpenSim/Framework/Data.MySQL/MySQLGridData.cs @@ -248,6 +248,47 @@ namespace OpenSim.Framework.Data.MySQL } } + /// + /// Returns a sim profile from it's Region name string + /// + /// The region name search query + /// The sim profile + public RegionProfileData GetProfileByString(string regionName) + { + if (regionName.Length > 2) + { + try + { + lock (database) + { + Dictionary param = new Dictionary(); + // Add % because this is a like query. + param["?regionName"] = regionName + "%"; + // Order by statement will return shorter matches first. Only returns one record or no record. + IDbCommand result = database.Query("SELECT * FROM regions WHERE regionName like ?regionName order by LENGTH(regionName) asc LIMIT 1", param); + IDataReader reader = result.ExecuteReader(); + + RegionProfileData row = database.readSimRow(reader); + reader.Close(); + result.Dispose(); + + return row; + } + } + catch (Exception e) + { + database.Reconnect(); + m_log.Error(e.ToString()); + return null; + } + } + else + { + m_log.Error("[DATABASE]: Searched for a Region Name shorter then 3 characters"); + return null; + } + } + /// /// Adds a new profile to the database /// diff --git a/OpenSim/Framework/Data.SQLite/SQLiteGridData.cs b/OpenSim/Framework/Data.SQLite/SQLiteGridData.cs index 6487ba7e7a..4d42f19b6e 100644 --- a/OpenSim/Framework/Data.SQLite/SQLiteGridData.cs +++ b/OpenSim/Framework/Data.SQLite/SQLiteGridData.cs @@ -111,6 +111,38 @@ namespace OpenSim.Framework.Data.SQLite return row; } + /// + /// Returns a sim profile from it's Region name string + /// + /// The region name search query + /// The sim profile + public RegionProfileData GetProfileByString(string regionName) + { + if (regionName.Length > 2) + { + + Dictionary param = new Dictionary(); + // Add % because this is a like query. + param["?regionName"] = regionName + "%"; + // Only returns one record or no record. + IDbCommand result = database.Query("SELECT * FROM regions WHERE regionName like ?regionName LIMIT 1", param); + IDataReader reader = result.ExecuteReader(); + + RegionProfileData row = database.getRow(reader); + reader.Close(); + result.Dispose(); + + return row; + + } + else + { + //m_log.Error("[DATABASE]: Searched for a Region Name shorter then 3 characters"); + return null; + } + } + + /// /// Returns a sim profile from it's UUID /// diff --git a/OpenSim/Framework/Data/GridData.cs b/OpenSim/Framework/Data/GridData.cs index 95a568ab01..5eaa2c4856 100644 --- a/OpenSim/Framework/Data/GridData.cs +++ b/OpenSim/Framework/Data/GridData.cs @@ -68,6 +68,13 @@ namespace OpenSim.Framework.Data /// A sim profile RegionProfileData GetProfileByLLUUID(LLUUID UUID); + /// + /// Returns a sim profile from a string match + /// + /// A string for a partial region name match + /// A sim profile + RegionProfileData GetProfileByString(string regionName); + /// /// Returns all profiles within the specified range /// diff --git a/OpenSim/Framework/Data/RegionProfileData.cs b/OpenSim/Framework/Data/RegionProfileData.cs index b541116a91..f736571c98 100644 --- a/OpenSim/Framework/Data/RegionProfileData.cs +++ b/OpenSim/Framework/Data/RegionProfileData.cs @@ -216,5 +216,47 @@ namespace OpenSim.Framework.Data return simData; } + + /// + /// Request sim profile information from a grid server + /// + /// + /// + /// + /// + /// The sim profile. Null if there was a request failure + public static RegionProfileData RequestSimProfileData(string regionName, string gridserver_url, + string gridserver_sendkey, string gridserver_recvkey) + { + Hashtable requestData = new Hashtable(); + requestData["region_name_search"] = regionName; + requestData["authkey"] = gridserver_sendkey; + ArrayList SendParams = new ArrayList(); + SendParams.Add(requestData); + XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams); + XmlRpcResponse GridResp = GridReq.Send(gridserver_url, 3000); + + Hashtable responseData = (Hashtable)GridResp.Value; + + if (responseData.ContainsKey("error")) + { + return null; + } + + RegionProfileData simData = new RegionProfileData(); + simData.regionLocX = Convert.ToUInt32((string)responseData["region_locx"]); + simData.regionLocY = Convert.ToUInt32((string)responseData["region_locy"]); + simData.regionHandle = Helpers.UIntsToLong((simData.regionLocX * Constants.RegionSize), (simData.regionLocY * Constants.RegionSize)); + simData.serverIP = (string)responseData["sim_ip"]; + simData.serverPort = Convert.ToUInt32((string)responseData["sim_port"]); + simData.httpPort = Convert.ToUInt32((string)responseData["http_port"]); + simData.remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]); + simData.httpServerURI = "http://" + simData.serverIP + ":" + simData.httpPort.ToString() + "/"; + simData.serverURI = (string)responseData["server_uri"]; + simData.UUID = new LLUUID((string)responseData["region_UUID"]); + simData.regionName = (string)responseData["region_name"]; + + return simData; + } } } diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 0f1f0d9518..37ddb3e74c 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -597,5 +597,53 @@ namespace OpenSim.Framework return ret; } + public static string[] ParseStartLocationRequest(string startLocationRequest) + { + string[] returnstring = new string[4]; + // format uri:RegionName&X&Y&Z + returnstring[0] = "last"; + returnstring[1] = "127"; + returnstring[2] = "127"; + returnstring[3] = "0"; + // This is the crappy way of doing it. + + if (startLocationRequest.Contains(":") && startLocationRequest.Contains("&")) + { + //System.Console.WriteLine("StartLocationRequest Contains proper elements"); + + string[] splitstr = startLocationRequest.Split(':');//,2,StringSplitOptions.RemoveEmptyEntries); + + //System.Console.WriteLine("Found " + splitstr.GetLength(0) + " elements in 1st split result"); + + if (splitstr.GetLength(0) == 2) + { + + string[] splitstr2 = splitstr[1].Split('&');//, 4, StringSplitOptions.RemoveEmptyEntries); + + //System.Console.WriteLine("Found " + splitstr2.GetLength(0) + " elements in 2nd split result"); + + if (splitstr2.GetLength(0) >= 1) + { + returnstring[0] = splitstr2[0]; + } + if (splitstr2.GetLength(0) >= 2) + { + returnstring[1] = splitstr2[1]; + } + if (splitstr2.GetLength(0) >= 3) + { + returnstring[2] = splitstr2[2]; + } + if (splitstr2.GetLength(0) >= 4) + { + returnstring[3] = splitstr2[3]; + } + } + + } + return returnstring; + + + } } } diff --git a/OpenSim/Grid/GridServer/GridManager.cs b/OpenSim/Grid/GridServer/GridManager.cs index e9ff91acf2..86fc4456dc 100644 --- a/OpenSim/Grid/GridServer/GridManager.cs +++ b/OpenSim/Grid/GridServer/GridManager.cs @@ -164,6 +164,27 @@ namespace OpenSim.Grid.GridServer return null; } + /// + /// Returns a region by argument + /// + /// A partial regionName of the region to return + /// A SimProfileData for the region + public RegionProfileData getRegion(string regionName) + { + foreach (KeyValuePair kvp in _plugins) + { + try + { + return kvp.Value.GetProfileByString(regionName); + } + catch + { + m_log.Warn("[storage]: Unable to find region " + regionName + " via " + kvp.Key); + } + } + return null; + } + public Dictionary getRegions(uint xmin, uint ymin, uint xmax, uint ymax) { Dictionary regions = new Dictionary(); @@ -615,6 +636,10 @@ namespace OpenSim.Grid.GridServer //CFK: Console.WriteLine("requesting data for region " + (string) requestData["region_handle"]); simData = getRegion(Convert.ToUInt64((string)requestData["region_handle"])); } + else if (requestData.ContainsKey("region_name_search")) + { + simData = getRegion((string)requestData["region_name_search"]); + } if (simData == null) { diff --git a/OpenSim/Grid/UserServer/UserLoginService.cs b/OpenSim/Grid/UserServer/UserLoginService.cs index b85ece99f3..6cc34d565b 100644 --- a/OpenSim/Grid/UserServer/UserLoginService.cs +++ b/OpenSim/Grid/UserServer/UserLoginService.cs @@ -64,6 +64,8 @@ namespace OpenSim.Grid.UserServer m_config = config; } + + /// /// Customises the login response and fills in missing values. /// @@ -95,11 +97,34 @@ namespace OpenSim.Grid.UserServer } else { - // TODO: Parse out startlocationrequest string in the format; 'uri:RegionName&X&Y&Z' - SimInfo = + string[] startLocationRequestParsed = Util.ParseStartLocationRequest(startLocationRequest); + m_log.Info("[DEBUGLOGINPARSE]: 1:" + startLocationRequestParsed[0] + ", 2:" + startLocationRequestParsed[1] + ", 3:" + startLocationRequestParsed[2] + ", 4:" + startLocationRequestParsed[3]); + if (startLocationRequestParsed[0] == "last") + { + // TODO: Parse out startlocationrequest string in the format; 'uri:RegionName&X&Y&Z' + SimInfo = + RegionProfileData.RequestSimProfileData( + theUser.currentAgent.currentHandle, m_config.GridServerURL, + m_config.GridSendKey, m_config.GridRecvKey); + } + else + { + m_log.Info("[LOGIN]: Looking up Sim: " + startLocationRequestParsed[0]); + SimInfo = RegionProfileData.RequestSimProfileData( - theUser.currentAgent.currentHandle, m_config.GridServerURL, + startLocationRequestParsed[0], m_config.GridServerURL, m_config.GridSendKey, m_config.GridRecvKey); + + if (SimInfo == null) + { + m_log.Info("[LOGIN]: Didn't find region with a close name match sending to home location"); + SimInfo = + RegionProfileData.RequestSimProfileData( + theUser.homeRegion, m_config.GridServerURL, + m_config.GridSendKey, m_config.GridRecvKey); + } + + } } // Customise the response @@ -132,6 +157,9 @@ namespace OpenSim.Grid.UserServer //CFK: m_log.Info("[LOGIN]: " + SimInfo.regionName + " (" + SimInfo.serverURI + ") " + //CFK: SimInfo.regionLocX + "," + SimInfo.regionLocY); + theUser.currentAgent.currentRegion = SimInfo.UUID; + theUser.currentAgent.currentHandle = SimInfo.regionHandle; + // Prepare notification Hashtable SimParams = new Hashtable(); SimParams["session_id"] = theUser.currentAgent.sessionID.ToString(); @@ -149,8 +177,7 @@ namespace OpenSim.Grid.UserServer SendParams.Add(SimParams); // Update agent with target sim - theUser.currentAgent.currentRegion = SimInfo.UUID; - theUser.currentAgent.currentHandle = SimInfo.regionHandle; + m_log.Info("[LOGIN]: Telling " + SimInfo.regionName + " @ " + SimInfo.httpServerURI + " " + @@ -175,6 +202,7 @@ namespace OpenSim.Grid.UserServer } } catch (Exception) + //catch (System.AccessViolationException) { tryDefault = true; } diff --git a/OpenSim/Region/Communications/Local/LocalBackEndServices.cs b/OpenSim/Region/Communications/Local/LocalBackEndServices.cs index 5df2e66f75..8cc13124d0 100644 --- a/OpenSim/Region/Communications/Local/LocalBackEndServices.cs +++ b/OpenSim/Region/Communications/Local/LocalBackEndServices.cs @@ -176,6 +176,12 @@ namespace OpenSim.Region.Communications.Local return null; } + public RegionInfo RequestClosestRegion(string regionName) + { + // Don't use this method. It's only for SLURLS and Logins + return null; + } + /// /// /// diff --git a/OpenSim/Region/Communications/Local/LocalLoginService.cs b/OpenSim/Region/Communications/Local/LocalLoginService.cs index 41f5b3d7a6..eff597e960 100644 --- a/OpenSim/Region/Communications/Local/LocalLoginService.cs +++ b/OpenSim/Region/Communications/Local/LocalLoginService.cs @@ -135,6 +135,8 @@ namespace OpenSim.Region.Communications.Local } else { + m_log.Info("[LOGIN]: Got Custom Login URL, but can't process it"); + // LocalBackEndServices can't possibly look up a region by name :( // TODO: Parse string in the following format: 'uri:RegionName&X&Y&Z' currentRegion = theUser.currentAgent.currentHandle; } diff --git a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs b/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs index 05c2721511..b7fae65223 100644 --- a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs +++ b/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs @@ -361,6 +361,59 @@ namespace OpenSim.Region.Communications.OGS1 return regionInfo; } + public RegionInfo RequestClosestRegion(string regionName) + { + // Don't use this method. It's only for SLURLS and Logins + RegionInfo regionInfo = null; + try + { + Hashtable requestData = new Hashtable(); + requestData["region_name_search"] = regionName; + requestData["authkey"] = serversInfo.GridSendKey; + ArrayList SendParams = new ArrayList(); + SendParams.Add(requestData); + XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams); + XmlRpcResponse GridResp = GridReq.Send(serversInfo.GridURL, 3000); + + Hashtable responseData = (Hashtable) GridResp.Value; + + if (responseData.ContainsKey("error")) + { + m_log.Error("[OGS1 GRID SERVICES]: Error received from grid server" + responseData["error"]); + return null; + } + + uint regX = Convert.ToUInt32((string) responseData["region_locx"]); + uint regY = Convert.ToUInt32((string) responseData["region_locy"]); + string internalIpStr = (string) responseData["sim_ip"]; + uint port = Convert.ToUInt32(responseData["sim_port"]); + string externalUri = (string) responseData["sim_uri"]; + + IPEndPoint neighbourInternalEndPoint = new IPEndPoint(IPAddress.Parse(internalIpStr), (int) port); + string neighbourExternalUri = externalUri; + regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, internalIpStr); + + regionInfo.RemotingPort = Convert.ToUInt32((string) responseData["remoting_port"]); + regionInfo.RemotingAddress = internalIpStr; + + regionInfo.RegionID = new LLUUID((string) responseData["region_UUID"]); + regionInfo.RegionName = (string) responseData["region_name"]; + + m_remoteRegionInfoCache.Add(regionInfo.RegionHandle, regionInfo); + } + catch (WebException) + { + m_log.Error("[OGS1 GRID SERVICES]: " + + "Region lookup failed for: " + regionName + + " - Is the GridServer down?"); + } + + + return regionInfo; + + } + + /// /// ///