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

integration
Diva Canto 2012-11-09 20:39:55 -08:00
parent 2540132a54
commit 4f98259617
1 changed files with 55 additions and 19 deletions

View File

@ -45,6 +45,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
Scene m_scene = null; // only need one for communication with GridService Scene m_scene = null; // only need one for communication with GridService
List<Scene> m_scenes = new List<Scene>(); List<Scene> m_scenes = new List<Scene>();
List<UUID> m_Clients;
#region ISharedRegionModule Members #region ISharedRegionModule Members
public void Initialise(IConfigSource source) public void Initialise(IConfigSource source)
@ -60,6 +61,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
m_scenes.Add(scene); m_scenes.Add(scene);
scene.EventManager.OnNewClient += OnNewClient; scene.EventManager.OnNewClient += OnNewClient;
m_Clients = new List<UUID>();
} }
public void RemoveRegion(Scene scene) public void RemoveRegion(Scene scene)
@ -98,17 +100,51 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
private void OnNewClient(IClientAPI client) 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) 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"); remoteClient.SendAlertMessage("Use a search string with at least 3 characters");
return; return;
} }
//m_log.DebugFormat("MAP NAME=({0})", mapName); //m_log.DebugFormat("MAP NAME=({0})", mapName);
// Hack to get around the fact that ll V3 now drops the port from the // Hack to get around the fact that ll V3 now drops the port from the
@ -129,13 +165,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
// try to fetch from GridServer // try to fetch from GridServer
List<GridRegion> regionInfos = m_scene.GridService.GetRegionsByName(m_scene.RegionInfo.ScopeID, mapName, 20); 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); 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) if (regionInfos.Count > 0)
{ {
foreach (GridRegion info in regionInfos) foreach (GridRegion info in regionInfos)
@ -162,16 +193,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
} }
// final block, closing the search result // final block, closing the search result
data = new MapBlockData(); AddFinalBlock(blocks);
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);
// flags are agent flags sent from the viewer. // flags are agent flags sent from the viewer.
// they have different values depending on different viewers, apparently // they have different values depending on different viewers, apparently
@ -183,12 +205,26 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
if (flags == 2) if (flags == 2)
{ {
if (regionInfos.Count == 0) 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) 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) // private Scene GetClientScene(IClientAPI client)
// { // {
// foreach (Scene s in m_scenes) // foreach (Scene s in m_scenes)