clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
26 */
27 using System;
28 using System.Collections.Generic;
29 using System.Reflection;
30 using log4net;
31 using Nini.Config;
32 using OpenMetaverse;
33 using Mono.Addins;
34 using OpenSim.Framework;
35 using OpenSim.Region.Framework.Interfaces;
36 using OpenSim.Region.Framework.Scenes;
37 using OpenSim.Services.Interfaces;
38 using GridRegion = OpenSim.Services.Interfaces.GridRegion;
39  
40 namespace OpenSim.Region.CoreModules.World.WorldMap
41 {
42 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MapSearchModule")]
43 public class MapSearchModule : ISharedRegionModule
44 {
45 private static readonly ILog m_log =
46 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47  
48 Scene m_scene = null; // only need one for communication with GridService
49 List<Scene> m_scenes = new List<Scene>();
50 List<UUID> m_Clients;
51  
52 IWorldMapModule m_WorldMap;
53 IWorldMapModule WorldMap
54 {
55 get
56 {
57 if (m_WorldMap == null)
58 m_WorldMap = m_scene.RequestModuleInterface<IWorldMapModule>();
59 return m_WorldMap;
60 }
61  
62 }
63  
64 #region ISharedRegionModule Members
65 public void Initialise(IConfigSource source)
66 {
67 }
68  
69 public void AddRegion(Scene scene)
70 {
71 if (m_scene == null)
72 {
73 m_scene = scene;
74 }
75  
76 m_scenes.Add(scene);
77 scene.EventManager.OnNewClient += OnNewClient;
78 m_Clients = new List<UUID>();
79  
80 }
81  
82 public void RemoveRegion(Scene scene)
83 {
84 m_scenes.Remove(scene);
85 if (m_scene == scene && m_scenes.Count > 0)
86 m_scene = m_scenes[0];
87  
88 scene.EventManager.OnNewClient -= OnNewClient;
89 }
90  
91 public void PostInitialise()
92 {
93 }
94  
95 public void Close()
96 {
97 m_scene = null;
98 m_scenes.Clear();
99 }
100  
101 public string Name
102 {
103 get { return "MapSearchModule"; }
104 }
105  
106 public Type ReplaceableInterface
107 {
108 get { return null; }
109 }
110  
111 public void RegionLoaded(Scene scene)
112 {
113 }
114 #endregion
115  
116 private void OnNewClient(IClientAPI client)
117 {
118 client.OnMapNameRequest += OnMapNameRequestHandler;
119 }
120  
121 private void OnMapNameRequestHandler(IClientAPI remoteClient, string mapName, uint flags)
122 {
123 lock (m_Clients)
124 {
125 if (m_Clients.Contains(remoteClient.AgentId))
126 return;
127  
128 m_Clients.Add(remoteClient.AgentId);
129 }
130  
131 try
132 {
133 OnMapNameRequest(remoteClient, mapName, flags);
134 }
135 finally
136 {
137 lock (m_Clients)
138 m_Clients.Remove(remoteClient.AgentId);
139 }
140 }
141  
142 private void OnMapNameRequest(IClientAPI remoteClient, string mapName, uint flags)
143 {
144 List<MapBlockData> blocks = new List<MapBlockData>();
145 if (mapName.Length < 3 || (mapName.EndsWith("#") && mapName.Length < 4))
146 {
147 // final block, closing the search result
148 AddFinalBlock(blocks);
149  
150 // flags are agent flags sent from the viewer.
151 // they have different values depending on different viewers, apparently
152 remoteClient.SendMapBlock(blocks, flags);
153 remoteClient.SendAlertMessage("Use a search string with at least 3 characters");
154 return;
155 }
156  
157  
158 List<GridRegion> regionInfos = m_scene.GridService.GetRegionsByName(m_scene.RegionInfo.ScopeID, mapName, 20);
159  
160 string mapNameOrig = mapName;
161 if (regionInfos.Count == 0)
162 {
163 // Hack to get around the fact that ll V3 now drops the port from the
164 // map name. See https://jira.secondlife.com/browse/VWR-28570
165 //
166 // Caller, use this magic form instead:
167 // secondlife://http|!!mygrid.com|8002|Region+Name/128/128
168 // or url encode if possible.
169 // the hacks we do with this viewer...
170 //
171 if (mapName.Contains("|"))
172 mapName = mapName.Replace('|', ':');
173 if (mapName.Contains("+"))
174 mapName = mapName.Replace('+', ' ');
175 if (mapName.Contains("!"))
176 mapName = mapName.Replace('!', '/');
177  
178 if (mapName != mapNameOrig)
179 regionInfos = m_scene.GridService.GetRegionsByName(m_scene.RegionInfo.ScopeID, mapName, 20);
180 }
181  
182 m_log.DebugFormat("[MAPSEARCHMODULE]: search {0} returned {1} regions. Flags={2}", mapName, regionInfos.Count, flags);
183  
184 if (regionInfos.Count > 0)
185 {
186 foreach (GridRegion info in regionInfos)
187 {
188 if ((flags & 2) == 2) // V2 sends this
189 {
190 List<MapBlockData> datas = WorldMap.Map2BlockFromGridRegion(info, flags);
191 // ugh! V2-3 is very sensitive about the result being
192 // exactly the same as the requested name
193 if (regionInfos.Count == 1 && (mapName != mapNameOrig))
194 datas.ForEach(d => d.Name = mapNameOrig);
195  
196 blocks.AddRange(datas);
197 }
198 else
199 {
200 MapBlockData data = WorldMap.MapBlockFromGridRegion(info, flags);
201 blocks.Add(data);
202 }
203 }
204 }
205  
206 // final block, closing the search result
207 AddFinalBlock(blocks);
208  
209 // flags are agent flags sent from the viewer.
210 // they have different values depending on different viewers, apparently
211 remoteClient.SendMapBlock(blocks, flags);
212  
213 // send extra user messages for V3
214 // because the UI is very confusing
215 // while we don't fix the hard-coded urls
216 if (flags == 2)
217 {
218 if (regionInfos.Count == 0)
219 remoteClient.SendAlertMessage("No regions found with that name.");
220 else if (regionInfos.Count == 1)
221 remoteClient.SendAlertMessage("Region found!");
222 }
223 }
224  
225 private void AddFinalBlock(List<MapBlockData> blocks)
226 {
227 // final block, closing the search result
228 MapBlockData data = new MapBlockData();
229 data.Agents = 0;
230 data.Access = (byte)SimAccess.NonExistent;
231 data.MapImageId = UUID.Zero;
232 data.Name = "";
233 data.RegionFlags = 0;
234 data.WaterHeight = 0; // not used
235 data.X = 0;
236 data.Y = 0;
237 blocks.Add(data);
238 }
239 // private Scene GetClientScene(IClientAPI client)
240 // {
241 // foreach (Scene s in m_scenes)
242 // {
243 // if (client.Scene.RegionInfo.RegionHandle == s.RegionInfo.RegionHandle)
244 // return s;
245 // }
246 // return m_scene;
247 // }
248 }
249 }