Minor improvement in the MapSearchModule. Stop blocking the client thread if the search takes too long.

0.7.4-extended
Diva Canto 2012-11-09 20:39:55 -08:00 committed by Justin Clark-Casey (justincc)
parent 862f595e5d
commit 72e0c77f91
1 changed files with 55 additions and 19 deletions

View File

@ -44,6 +44,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
Scene m_scene = null; // only need one for communication with GridService
List<Scene> m_scenes = new List<Scene>();
List<UUID> m_Clients;
#region IRegionModule Members
public void Initialise(Scene scene, IConfigSource source)
@ -55,6 +56,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
m_scenes.Add(scene);
scene.EventManager.OnNewClient += OnNewClient;
m_Clients = new List<UUID>();
}
public void PostInitialise()
@ -81,17 +83,51 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
private void OnNewClient(IClientAPI client)
{
client.OnMapNameRequest += OnMapNameRequest;
client.OnMapNameRequest += OnMapNameRequestHandler;
}
private void OnMapNameRequestHandler(IClientAPI remoteClient, string mapName, uint flags)
{
lock (m_Clients)
{
if (m_Clients.Contains(remoteClient.AgentId))
return;
m_Clients.Add(remoteClient.AgentId);
}
Util.FireAndForget(delegate
{
try
{
OnMapNameRequest(remoteClient, mapName, flags);
}
finally
{
lock (m_Clients)
m_Clients.Remove(remoteClient.AgentId);
}
});
}
private void OnMapNameRequest(IClientAPI remoteClient, string mapName, uint flags)
{
if (mapName.Length < 3)
List<MapBlockData> blocks = new List<MapBlockData>();
MapBlockData data;
if (mapName.Length < 3 || (mapName.EndsWith("#") && mapName.Length < 4))
{
// final block, closing the search result
AddFinalBlock(blocks);
// flags are agent flags sent from the viewer.
// they have different values depending on different viewers, apparently
remoteClient.SendMapBlock(blocks, flags);
remoteClient.SendAlertMessage("Use a search string with at least 3 characters");
return;
}
//m_log.DebugFormat("MAP NAME=({0})", mapName);
// Hack to get around the fact that ll V3 now drops the port from the
@ -112,13 +148,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
// try to fetch from GridServer
List<GridRegion> regionInfos = m_scene.GridService.GetRegionsByName(m_scene.RegionInfo.ScopeID, mapName, 20);
if (regionInfos.Count == 0)
remoteClient.SendAlertMessage("Hyperlink could not be established.");
m_log.DebugFormat("[MAPSEARCHMODULE]: search {0} returned {1} regions. Flags={2}", mapName, regionInfos.Count, flags);
List<MapBlockData> blocks = new List<MapBlockData>();
MapBlockData data;
if (regionInfos.Count > 0)
{
foreach (GridRegion info in regionInfos)
@ -145,16 +176,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
}
// final block, closing the search result
data = new MapBlockData();
data.Agents = 0;
data.Access = 255;
data.MapImageId = UUID.Zero;
data.Name = ""; // mapName;
data.RegionFlags = 0;
data.WaterHeight = 0; // not used
data.X = 0;
data.Y = 0;
blocks.Add(data);
AddFinalBlock(blocks);
// flags are agent flags sent from the viewer.
// they have different values depending on different viewers, apparently
@ -166,12 +188,26 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
if (flags == 2)
{
if (regionInfos.Count == 0)
remoteClient.SendAgentAlertMessage("No regions found with that name.", true);
remoteClient.SendAlertMessage("No regions found with that name.");
else if (regionInfos.Count == 1)
remoteClient.SendAgentAlertMessage("Region found!", false);
remoteClient.SendAlertMessage("Region found!");
}
}
private void AddFinalBlock(List<MapBlockData> blocks)
{
// final block, closing the search result
MapBlockData data = new MapBlockData();
data.Agents = 0;
data.Access = 255;
data.MapImageId = UUID.Zero;
data.Name = "";
data.RegionFlags = 0;
data.WaterHeight = 0; // not used
data.X = 0;
data.Y = 0;
blocks.Add(data);
}
// private Scene GetClientScene(IClientAPI client)
// {
// foreach (Scene s in m_scenes)