28 using System.Collections.Generic;
29 using System.Reflection;
34 using OpenSim.Framework;
35 using OpenSim.Region.Framework.Interfaces;
36 using OpenSim.Region.Framework.Scenes;
37 using OpenSim.Services.Interfaces;
42 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"MapSearchModule")]
45 private static readonly ILog m_log =
46 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 List<Scene> m_scenes =
new List<Scene>();
57 if (m_WorldMap == null)
64 #region ISharedRegionModule Members
77 scene.EventManager.OnNewClient += OnNewClient;
78 m_Clients =
new List<UUID>();
84 m_scenes.Remove(scene);
85 if (m_scene == scene && m_scenes.Count > 0)
86 m_scene = m_scenes[0];
88 scene.EventManager.OnNewClient -= OnNewClient;
103 get {
return "MapSearchModule"; }
106 public Type ReplaceableInterface
118 client.OnMapNameRequest += OnMapNameRequestHandler;
121 private void OnMapNameRequestHandler(
IClientAPI remoteClient,
string mapName, uint flags)
125 if (m_Clients.Contains(remoteClient.
AgentId))
128 m_Clients.Add(remoteClient.AgentId);
133 OnMapNameRequest(remoteClient, mapName, flags);
138 m_Clients.Remove(remoteClient.AgentId);
142 private
void OnMapNameRequest(
IClientAPI remoteClient,
string mapName, uint flags)
144 Util.FireAndForget(x =>
146 List<MapBlockData> blocks =
new List<MapBlockData>();
147 if (mapName.Length < 3 || (mapName.EndsWith(
"#") && mapName.Length < 4))
150 AddFinalBlock(blocks,mapName);
154 remoteClient.SendMapBlock(blocks, flags);
155 remoteClient.SendAlertMessage(
"Use a search string with at least 3 characters");
169 bool needOriginalName =
false;
170 string mapNameOrig = mapName;
171 if (mapName.Contains(
"|"))
173 mapName = mapName.Replace(
'|',
':');
174 needOriginalName =
true;
176 if (mapName.Contains(
"+"))
178 mapName = mapName.Replace(
'+',
' ');
179 needOriginalName =
true;
181 if (mapName.Contains(
"!"))
183 mapName = mapName.Replace(
'!',
'/');
184 needOriginalName =
true;
186 if (mapName.Contains(
"."))
187 needOriginalName =
true;
190 List<GridRegion> regionInfos = m_scene.GridService.GetRegionsByName(m_scene.RegionInfo.ScopeID, mapName, 20);
197 if (regionInfos.Count > 0)
203 data.Access = info.Access;
205 WorldMap.MapBlockFromGridRegion(block, info, flags);
207 if (flags == 2 && regionInfos.Count == 1 && needOriginalName)
208 block.Name = mapNameOrig;
214 AddFinalBlock(blocks,mapNameOrig);
218 remoteClient.SendMapBlock(blocks, flags);
225 if (regionInfos.Count == 0)
226 remoteClient.SendAgentAlertMessage(
"No regions found with that name.",
true);
233 private void AddFinalBlock(List<MapBlockData> blocks,
string name)
238 data.Access = (byte)SimAccess.NonExistent;
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
OpenSim.Services.Interfaces.GridRegion GridRegion
Interactive OpenSim region server
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...