diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs | 99 |
1 files changed, 75 insertions, 24 deletions
diff --git a/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs index f37dd94..708a9a2 100644 --- a/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs +++ b/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs | |||
@@ -24,11 +24,13 @@ | |||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | using System; | ||
27 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
28 | using System.Reflection; | 29 | using System.Reflection; |
29 | using log4net; | 30 | using log4net; |
30 | using Nini.Config; | 31 | using Nini.Config; |
31 | using OpenMetaverse; | 32 | using OpenMetaverse; |
33 | using Mono.Addins; | ||
32 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
33 | using OpenSim.Region.Framework.Interfaces; | 35 | using OpenSim.Region.Framework.Interfaces; |
34 | using OpenSim.Region.Framework.Scenes; | 36 | using OpenSim.Region.Framework.Scenes; |
@@ -37,16 +39,22 @@ using GridRegion = OpenSim.Services.Interfaces.GridRegion; | |||
37 | 39 | ||
38 | namespace OpenSim.Region.CoreModules.World.WorldMap | 40 | namespace OpenSim.Region.CoreModules.World.WorldMap |
39 | { | 41 | { |
40 | public class MapSearchModule : IRegionModule | 42 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MapSearchModule")] |
43 | public class MapSearchModule : ISharedRegionModule | ||
41 | { | 44 | { |
42 | private static readonly ILog m_log = | 45 | private static readonly ILog m_log = |
43 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 46 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
44 | 47 | ||
45 | Scene m_scene = null; // only need one for communication with GridService | 48 | Scene m_scene = null; // only need one for communication with GridService |
46 | List<Scene> m_scenes = new List<Scene>(); | 49 | List<Scene> m_scenes = new List<Scene>(); |
50 | List<UUID> m_Clients; | ||
47 | 51 | ||
48 | #region IRegionModule Members | 52 | #region ISharedRegionModule Members |
49 | public void Initialise(Scene scene, IConfigSource source) | 53 | public void Initialise(IConfigSource source) |
54 | { | ||
55 | } | ||
56 | |||
57 | public void AddRegion(Scene scene) | ||
50 | { | 58 | { |
51 | if (m_scene == null) | 59 | if (m_scene == null) |
52 | { | 60 | { |
@@ -55,6 +63,16 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
55 | 63 | ||
56 | m_scenes.Add(scene); | 64 | m_scenes.Add(scene); |
57 | scene.EventManager.OnNewClient += OnNewClient; | 65 | scene.EventManager.OnNewClient += OnNewClient; |
66 | m_Clients = new List<UUID>(); | ||
67 | } | ||
68 | |||
69 | public void RemoveRegion(Scene scene) | ||
70 | { | ||
71 | m_scenes.Remove(scene); | ||
72 | if (m_scene == scene && m_scenes.Count > 0) | ||
73 | m_scene = m_scenes[0]; | ||
74 | |||
75 | scene.EventManager.OnNewClient -= OnNewClient; | ||
58 | } | 76 | } |
59 | 77 | ||
60 | public void PostInitialise() | 78 | public void PostInitialise() |
@@ -72,26 +90,59 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
72 | get { return "MapSearchModule"; } | 90 | get { return "MapSearchModule"; } |
73 | } | 91 | } |
74 | 92 | ||
75 | public bool IsSharedModule | 93 | public Type ReplaceableInterface |
76 | { | 94 | { |
77 | get { return true; } | 95 | get { return null; } |
78 | } | 96 | } |
79 | 97 | ||
98 | public void RegionLoaded(Scene scene) | ||
99 | { | ||
100 | } | ||
80 | #endregion | 101 | #endregion |
81 | 102 | ||
82 | private void OnNewClient(IClientAPI client) | 103 | private void OnNewClient(IClientAPI client) |
83 | { | 104 | { |
84 | client.OnMapNameRequest += OnMapNameRequest; | 105 | client.OnMapNameRequest += OnMapNameRequestHandler; |
106 | } | ||
107 | |||
108 | private void OnMapNameRequestHandler(IClientAPI remoteClient, string mapName, uint flags) | ||
109 | { | ||
110 | lock (m_Clients) | ||
111 | { | ||
112 | if (m_Clients.Contains(remoteClient.AgentId)) | ||
113 | return; | ||
114 | |||
115 | m_Clients.Add(remoteClient.AgentId); | ||
116 | } | ||
117 | |||
118 | try | ||
119 | { | ||
120 | OnMapNameRequest(remoteClient, mapName, flags); | ||
121 | } | ||
122 | finally | ||
123 | { | ||
124 | lock (m_Clients) | ||
125 | m_Clients.Remove(remoteClient.AgentId); | ||
126 | } | ||
85 | } | 127 | } |
86 | 128 | ||
87 | private void OnMapNameRequest(IClientAPI remoteClient, string mapName, uint flags) | 129 | private void OnMapNameRequest(IClientAPI remoteClient, string mapName, uint flags) |
88 | { | 130 | { |
89 | if (mapName.Length < 3) | 131 | List<MapBlockData> blocks = new List<MapBlockData>(); |
132 | MapBlockData data; | ||
133 | if (mapName.Length < 3 || (mapName.EndsWith("#") && mapName.Length < 4)) | ||
90 | { | 134 | { |
135 | // final block, closing the search result | ||
136 | AddFinalBlock(blocks); | ||
137 | |||
138 | // flags are agent flags sent from the viewer. | ||
139 | // they have different values depending on different viewers, apparently | ||
140 | remoteClient.SendMapBlock(blocks, flags); | ||
91 | remoteClient.SendAlertMessage("Use a search string with at least 3 characters"); | 141 | remoteClient.SendAlertMessage("Use a search string with at least 3 characters"); |
92 | return; | 142 | return; |
93 | } | 143 | } |
94 | 144 | ||
145 | |||
95 | //m_log.DebugFormat("MAP NAME=({0})", mapName); | 146 | //m_log.DebugFormat("MAP NAME=({0})", mapName); |
96 | 147 | ||
97 | // Hack to get around the fact that ll V3 now drops the port from the | 148 | // Hack to get around the fact that ll V3 now drops the port from the |
@@ -112,13 +163,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
112 | 163 | ||
113 | // try to fetch from GridServer | 164 | // try to fetch from GridServer |
114 | List<GridRegion> regionInfos = m_scene.GridService.GetRegionsByName(m_scene.RegionInfo.ScopeID, mapName, 20); | 165 | List<GridRegion> regionInfos = m_scene.GridService.GetRegionsByName(m_scene.RegionInfo.ScopeID, mapName, 20); |
115 | if (regionInfos.Count == 0) | ||
116 | remoteClient.SendAlertMessage("Hyperlink could not be established."); | ||
117 | 166 | ||
118 | m_log.DebugFormat("[MAPSEARCHMODULE]: search {0} returned {1} regions. Flags={2}", mapName, regionInfos.Count, flags); | 167 | m_log.DebugFormat("[MAPSEARCHMODULE]: search {0} returned {1} regions. Flags={2}", mapName, regionInfos.Count, flags); |
119 | List<MapBlockData> blocks = new List<MapBlockData>(); | ||
120 | |||
121 | MapBlockData data; | ||
122 | if (regionInfos.Count > 0) | 168 | if (regionInfos.Count > 0) |
123 | { | 169 | { |
124 | foreach (GridRegion info in regionInfos) | 170 | foreach (GridRegion info in regionInfos) |
@@ -145,16 +191,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
145 | } | 191 | } |
146 | 192 | ||
147 | // final block, closing the search result | 193 | // final block, closing the search result |
148 | data = new MapBlockData(); | 194 | AddFinalBlock(blocks); |
149 | data.Agents = 0; | ||
150 | data.Access = 255; | ||
151 | data.MapImageId = UUID.Zero; | ||
152 | data.Name = ""; // mapName; | ||
153 | data.RegionFlags = 0; | ||
154 | data.WaterHeight = 0; // not used | ||
155 | data.X = 0; | ||
156 | data.Y = 0; | ||
157 | blocks.Add(data); | ||
158 | 195 | ||
159 | // flags are agent flags sent from the viewer. | 196 | // flags are agent flags sent from the viewer. |
160 | // they have different values depending on different viewers, apparently | 197 | // they have different values depending on different viewers, apparently |
@@ -166,12 +203,26 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
166 | if (flags == 2) | 203 | if (flags == 2) |
167 | { | 204 | { |
168 | if (regionInfos.Count == 0) | 205 | if (regionInfos.Count == 0) |
169 | remoteClient.SendAgentAlertMessage("No regions found with that name.", true); | 206 | remoteClient.SendAlertMessage("No regions found with that name."); |
170 | else if (regionInfos.Count == 1) | 207 | else if (regionInfos.Count == 1) |
171 | remoteClient.SendAgentAlertMessage("Region found!", false); | 208 | remoteClient.SendAlertMessage("Region found!"); |
172 | } | 209 | } |
173 | } | 210 | } |
174 | 211 | ||
212 | private void AddFinalBlock(List<MapBlockData> blocks) | ||
213 | { | ||
214 | // final block, closing the search result | ||
215 | MapBlockData data = new MapBlockData(); | ||
216 | data.Agents = 0; | ||
217 | data.Access = 255; | ||
218 | data.MapImageId = UUID.Zero; | ||
219 | data.Name = ""; | ||
220 | data.RegionFlags = 0; | ||
221 | data.WaterHeight = 0; // not used | ||
222 | data.X = 0; | ||
223 | data.Y = 0; | ||
224 | blocks.Add(data); | ||
225 | } | ||
175 | // private Scene GetClientScene(IClientAPI client) | 226 | // private Scene GetClientScene(IClientAPI client) |
176 | // { | 227 | // { |
177 | // foreach (Scene s in m_scenes) | 228 | // foreach (Scene s in m_scenes) |