increase HG mapsearch spargetti; add more flexibility on input uri formats. To find regions in memory for a grid the http format needs to be used, because aditional compares made by viewers

melanie
UbitUmarov 2016-11-28 04:29:57 +00:00
parent d3cd323f0c
commit 1aa4dbdb3f
3 changed files with 259 additions and 140 deletions

View File

@ -128,20 +128,14 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
m_Clients.Add(remoteClient.AgentId); m_Clients.Add(remoteClient.AgentId);
} }
try
{
OnMapNameRequest(remoteClient, mapName, flags); OnMapNameRequest(remoteClient, mapName, flags);
} }
finally
{
lock (m_Clients)
m_Clients.Remove(remoteClient.AgentId);
}
}
private void OnMapNameRequest(IClientAPI remoteClient, string mapName, uint flags) private void OnMapNameRequest(IClientAPI remoteClient, string mapName, uint flags)
{ {
Util.FireAndForget(x => Util.FireAndForget(x =>
{
try
{ {
List<MapBlockData> blocks = new List<MapBlockData>(); List<MapBlockData> blocks = new List<MapBlockData>();
if (mapName.Length < 3 || (mapName.EndsWith("#") && mapName.Length < 4)) if (mapName.Length < 3 || (mapName.EndsWith("#") && mapName.Length < 4))
@ -224,8 +218,14 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
{ {
if (regionInfos.Count == 0) if (regionInfos.Count == 0)
remoteClient.SendAgentAlertMessage("No regions found with that name.", true); remoteClient.SendAgentAlertMessage("No regions found with that name.", true);
// else if (regionInfos.Count == 1) // else if (regionInfos.Count == 1)
// remoteClient.SendAgentAlertMessage("Region found!", false); // remoteClient.SendAgentAlertMessage("Region found!", false);
}
}
finally
{
lock (m_Clients)
m_Clients.Remove(remoteClient.AgentId);
} }
}); });
} }

View File

@ -579,7 +579,70 @@ namespace OpenSim.Services.GridService
int count = 0; int count = 0;
List<GridRegion> rinfos = new List<GridRegion>(); List<GridRegion> rinfos = new List<GridRegion>();
if (rdatas != null) if (count < maxNumber && m_AllowHypergridMapSearch && name.Contains("."))
{
string regionURI = "";
string regionName = "";
if(!m_HypergridLinker.buildHGRegionURI(name, out regionURI, out regionName))
return null;
string mapname = regionURI + regionName;
bool haveMatch = false;
if (rdatas != null && (rdatas.Count > 0))
{
// m_log.DebugFormat("[GRID SERVICE]: Found {0} regions", rdatas.Count);
foreach (RegionData rdata in rdatas)
{
if (count++ < maxNumber)
rinfos.Add(RegionData2RegionInfo(rdata));
if(rdata.RegionName == mapname)
{
haveMatch = true;
if(count == maxNumber)
{
rinfos.RemoveAt(count - 1);
rinfos.Add(RegionData2RegionInfo(rdata));
}
}
}
if(haveMatch)
return rinfos;
}
rdatas = m_Database.Get(Util.EscapeForLike(mapname)+ "%", scopeID);
if (rdatas != null && (rdatas.Count > 0))
{
// m_log.DebugFormat("[GRID SERVICE]: Found {0} regions", rdatas.Count);
foreach (RegionData rdata in rdatas)
{
if (count++ < maxNumber)
rinfos.Add(RegionData2RegionInfo(rdata));
if(rdata.RegionName == mapname)
{
haveMatch = true;
if(count == maxNumber)
{
rinfos.RemoveAt(count - 1);
rinfos.Add(RegionData2RegionInfo(rdata));
break;
}
}
}
if(haveMatch)
return rinfos;
}
string HGname = regionURI +" "+ regionName;
GridRegion r = m_HypergridLinker.LinkRegion(scopeID, HGname);
if (r != null)
{
if( count == maxNumber)
rinfos.RemoveAt(count - 1);
rinfos.Add(r);
}
}
else if (rdatas != null && (rdatas.Count > 0))
{ {
// m_log.DebugFormat("[GRID SERVICE]: Found {0} regions", rdatas.Count); // m_log.DebugFormat("[GRID SERVICE]: Found {0} regions", rdatas.Count);
foreach (RegionData rdata in rdatas) foreach (RegionData rdata in rdatas)
@ -589,13 +652,6 @@ namespace OpenSim.Services.GridService
} }
} }
if (m_AllowHypergridMapSearch && (rdatas == null || (rdatas != null && rdatas.Count == 0)))
{
GridRegion r = GetHypergridRegionByName(scopeID, name);
if (r != null)
rinfos.Add(r);
}
return rinfos; return rinfos;
} }
@ -608,7 +664,20 @@ namespace OpenSim.Services.GridService
protected GridRegion GetHypergridRegionByName(UUID scopeID, string name) protected GridRegion GetHypergridRegionByName(UUID scopeID, string name)
{ {
if (name.Contains(".")) if (name.Contains("."))
return m_HypergridLinker.LinkRegion(scopeID, name); {
string regionURI = "";
string regionName = "";
if(!m_HypergridLinker.buildHGRegionURI(name, out regionURI, out regionName))
return null;
string mapname = regionURI + regionName;
List<RegionData> rdatas = m_Database.Get(Util.EscapeForLike(mapname), scopeID);
if ((rdatas != null) && (rdatas.Count > 0))
return RegionData2RegionInfo(rdatas[0]); // get the first
string HGname = regionURI +" "+ regionName;
return m_HypergridLinker.LinkRegion(scopeID, HGname);
}
else else
return null; return null;
} }

View File

@ -191,14 +191,14 @@ namespace OpenSim.Services.GridService
return TryLinkRegionToCoords(scopeID, mapName, xloc, yloc, UUID.Zero, out reason); return TryLinkRegionToCoords(scopeID, mapName, xloc, yloc, UUID.Zero, out reason);
} }
public GridRegion TryLinkRegionToCoords(UUID scopeID, string mapName, int xloc, int yloc, UUID ownerID, out string reason) public bool buildHGRegionURI(string inputName, out string serverURI, out string regionName)
{ {
reason = string.Empty; serverURI = string.Empty;
GridRegion regInfo = null; regionName = string.Empty;
mapName = mapName.Trim(); inputName = inputName.Trim();
if (!mapName.StartsWith("http") && !mapName.StartsWith("https")) if (!inputName.StartsWith("http") && !inputName.StartsWith("https"))
{ {
// Formats: grid.example.com:8002:region name // Formats: grid.example.com:8002:region name
// grid.example.com:region name // grid.example.com:region name
@ -207,37 +207,58 @@ namespace OpenSim.Services.GridService
string host; string host;
uint port = 80; uint port = 80;
string regionName = "";
string[] parts = mapName.Split(new char[] { ':' }); string[] parts = inputName.Split(new char[] { ':' });
int indx;
if (parts.Length == 0) if(parts.Length == 0)
return false;
if (parts.Length == 1)
{ {
reason = "Wrong format for link-region"; indx = inputName.IndexOf('/');
return null; if (indx < 0)
serverURI = "http://"+ inputName + "/";
else
{
serverURI = "http://"+ inputName.Substring(0,indx + 1);
if(indx + 2 < inputName.Length)
regionName = inputName.Substring(indx + 1);
} }
}
else
{
host = parts[0]; host = parts[0];
if (parts.Length >= 2) if (parts.Length >= 2)
{
indx = parts[1].IndexOf('/');
if(indx < 0)
{ {
// If it's a number then assume it's a port. Otherwise, it's a region name. // If it's a number then assume it's a port. Otherwise, it's a region name.
if (!UInt32.TryParse(parts[1], out port)) if (!UInt32.TryParse(parts[1], out port))
{
port = 80;
regionName = parts[1]; regionName = parts[1];
} }
}
else
{
string portstr = parts[1].Substring(0, indx);
if(indx + 2 < parts[1].Length)
regionName = parts[1].Substring(indx + 1);
if (!UInt32.TryParse(portstr, out port))
port = 80;
}
}
// always take the last one // always take the last one
if (parts.Length >= 3) if (parts.Length >= 3)
{ {
regionName = parts[2]; regionName = parts[2];
} }
string serverURI = "http://"+ host +":"+ port.ToString() + "/"; if(port == 80)
// bool success = TryCreateLink(scopeID, xloc, yloc, regionName, port, host, ownerID, out regInfo, out reason); serverURI = "http://"+ host + "/";
if(TryCreateLink(scopeID, xloc, yloc, regionName, 0, null, serverURI, ownerID, out regInfo, out reason)) else
{ serverURI = "http://"+ host +":"+ port.ToString() + "/";
regInfo.RegionName = mapName;
return regInfo;
} }
} }
else else
@ -246,33 +267,62 @@ namespace OpenSim.Services.GridService
// http://grid.example.com "region name" // http://grid.example.com "region name"
// http://grid.example.com // http://grid.example.com
string serverURI; string[] parts = inputName.Split(new char[] { ' ' });
string regionName = "";
string[] parts = mapName.Split(new char[] { ' ' });
if (parts.Length == 0) if (parts.Length == 0)
{ return false;
reason = "Wrong format for link-region";
return null;
}
serverURI = parts[0]; serverURI = parts[0];
if (!serverURI.EndsWith("/"))
serverURI = serverURI + "/";
if (parts.Length >= 2) int indx = serverURI.LastIndexOf('/');
if(indx > 10)
{ {
regionName = mapName.Substring(serverURI.Length); if(indx + 2 < inputName.Length)
regionName = inputName.Substring(indx + 1);
serverURI = inputName.Substring(0, indx + 1);
}
else if (parts.Length >= 2)
{
regionName = inputName.Substring(serverURI.Length);
}
}
// use better code for sanity check
Uri uri;
try
{
uri = new Uri(serverURI);
}
catch
{
return false;
}
if(!string.IsNullOrEmpty(regionName))
regionName = regionName.Trim(new char[] { '"', ' ' }); regionName = regionName.Trim(new char[] { '"', ' ' });
serverURI = uri.AbsoluteUri;
return true;
}
public GridRegion TryLinkRegionToCoords(UUID scopeID, string mapName, int xloc, int yloc, UUID ownerID, out string reason)
{
reason = string.Empty;
GridRegion regInfo = null;
string serverURI = string.Empty;
string regionName = string.Empty;
if(!buildHGRegionURI(mapName, out serverURI, out regionName))
{
reason = "Wrong URI format for link-region";
return null;
} }
if (TryCreateLink(scopeID, xloc, yloc, regionName, 0, null, serverURI, ownerID, out regInfo, out reason)) if (TryCreateLink(scopeID, xloc, yloc, regionName, 0, null, serverURI, ownerID, out regInfo, out reason))
{ {
regInfo.RegionName = mapName; regInfo.RegionName = serverURI + regionName;
return regInfo; return regInfo;
} }
}
return null; return null;
} }