* 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.
0.6.0-stable
Teravus Ovares 2008-03-18 05:44:25 +00:00
parent 47180080f0
commit 42857fe4e9
13 changed files with 338 additions and 5 deletions

View File

@ -36,6 +36,7 @@ namespace OpenSim.Framework.Communications
bool DeregisterRegion(RegionInfo regionInfo);
List<SimpleRegionInfo> RequestNeighbours(uint x, uint y);
RegionInfo RequestNeighbourInfo(ulong regionHandle);
RegionInfo RequestClosestRegion(string regionName);
Dictionary<string, string> GetGridSettings();
List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY);
}

View File

@ -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;
}
/// <summary>
/// Adds a new specified region to the database
/// </summary>

View File

@ -180,6 +180,49 @@ namespace OpenSim.Framework.Data.MSSQL
return row;
}
/// <summary>
/// Returns a sim profile from it's Region name string
/// </summary>
/// <param name="uuid">The region name search query</param>
/// <returns>The sim profile</returns>
public RegionProfileData GetProfileByString(string regionName)
{
if (regionName.Length > 2)
{
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
// 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;
}
}
/// <summary>
/// Adds a new specified region to the database
/// </summary>

View File

@ -248,6 +248,47 @@ namespace OpenSim.Framework.Data.MySQL
}
}
/// <summary>
/// Returns a sim profile from it's Region name string
/// </summary>
/// <param name="uuid">The region name search query</param>
/// <returns>The sim profile</returns>
public RegionProfileData GetProfileByString(string regionName)
{
if (regionName.Length > 2)
{
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
// 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;
}
}
/// <summary>
/// Adds a new profile to the database
/// </summary>

View File

@ -111,6 +111,38 @@ namespace OpenSim.Framework.Data.SQLite
return row;
}
/// <summary>
/// Returns a sim profile from it's Region name string
/// </summary>
/// <param name="uuid">The region name search query</param>
/// <returns>The sim profile</returns>
public RegionProfileData GetProfileByString(string regionName)
{
if (regionName.Length > 2)
{
Dictionary<string, string> param = new Dictionary<string, string>();
// 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;
}
}
/// <summary>
/// Returns a sim profile from it's UUID
/// </summary>

View File

@ -68,6 +68,13 @@ namespace OpenSim.Framework.Data
/// <returns>A sim profile</returns>
RegionProfileData GetProfileByLLUUID(LLUUID UUID);
/// <summary>
/// Returns a sim profile from a string match
/// </summary>
/// <param name="regionName">A string for a partial region name match</param>
/// <returns>A sim profile</returns>
RegionProfileData GetProfileByString(string regionName);
/// <summary>
/// Returns all profiles within the specified range
/// </summary>

View File

@ -216,5 +216,47 @@ namespace OpenSim.Framework.Data
return simData;
}
/// <summary>
/// Request sim profile information from a grid server
/// </summary>
/// <param name="region_handle"></param>
/// <param name="gridserver_url"></param>
/// <param name="gridserver_sendkey"></param>
/// <param name="gridserver_recvkey"></param>
/// <returns>The sim profile. Null if there was a request failure</returns>
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;
}
}
}

View File

@ -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;
}
}
}

View File

@ -164,6 +164,27 @@ namespace OpenSim.Grid.GridServer
return null;
}
/// <summary>
/// Returns a region by argument
/// </summary>
/// <param name="regionName">A partial regionName of the region to return</param>
/// <returns>A SimProfileData for the region</returns>
public RegionProfileData getRegion(string regionName)
{
foreach (KeyValuePair<string, IGridData> 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<ulong, RegionProfileData> getRegions(uint xmin, uint ymin, uint xmax, uint ymax)
{
Dictionary<ulong, RegionProfileData> regions = new Dictionary<ulong, RegionProfileData>();
@ -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)
{

View File

@ -64,6 +64,8 @@ namespace OpenSim.Grid.UserServer
m_config = config;
}
/// <summary>
/// Customises the login response and fills in missing values.
/// </summary>
@ -94,6 +96,10 @@ namespace OpenSim.Grid.UserServer
}
else
{
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 =
@ -101,6 +107,25 @@ namespace OpenSim.Grid.UserServer
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(
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
//CFK: This is redundant and the next message should always appear.
@ -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;
}

View File

@ -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;
}
/// <summary>
///
/// </summary>

View File

@ -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;
}

View File

@ -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;
}
/// <summary>
///
/// </summary>