opensim-development – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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 | #region ISharedRegionModule Members |
||
53 | public void Initialise(IConfigSource source) |
||
54 | { |
||
55 | } |
||
56 | |||
57 | public void AddRegion(Scene scene) |
||
58 | { |
||
59 | if (m_scene == null) |
||
60 | { |
||
61 | m_scene = scene; |
||
62 | } |
||
63 | |||
64 | m_scenes.Add(scene); |
||
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; |
||
76 | } |
||
77 | |||
78 | public void PostInitialise() |
||
79 | { |
||
80 | } |
||
81 | |||
82 | public void Close() |
||
83 | { |
||
84 | m_scene = null; |
||
85 | m_scenes.Clear(); |
||
86 | } |
||
87 | |||
88 | public string Name |
||
89 | { |
||
90 | get { return "MapSearchModule"; } |
||
91 | } |
||
92 | |||
93 | public Type ReplaceableInterface |
||
94 | { |
||
95 | get { return null; } |
||
96 | } |
||
97 | |||
98 | public void RegionLoaded(Scene scene) |
||
99 | { |
||
100 | } |
||
101 | #endregion |
||
102 | |||
103 | private void OnNewClient(IClientAPI client) |
||
104 | { |
||
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 | } |
||
127 | } |
||
128 | |||
129 | private void OnMapNameRequest(IClientAPI remoteClient, string mapName, uint flags) |
||
130 | { |
||
131 | List<MapBlockData> blocks = new List<MapBlockData>(); |
||
132 | MapBlockData data; |
||
133 | if (mapName.Length < 3 || (mapName.EndsWith("#") && mapName.Length < 4)) |
||
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); |
||
141 | remoteClient.SendAlertMessage("Use a search string with at least 3 characters"); |
||
142 | return; |
||
143 | } |
||
144 | |||
145 | |||
146 | //m_log.DebugFormat("MAP NAME=({0})", mapName); |
||
147 | |||
148 | // Hack to get around the fact that ll V3 now drops the port from the |
||
149 | // map name. See https://jira.secondlife.com/browse/VWR-28570 |
||
150 | // |
||
151 | // Caller, use this magic form instead: |
||
152 | // secondlife://http|!!mygrid.com|8002|Region+Name/128/128 |
||
153 | // or url encode if possible. |
||
154 | // the hacks we do with this viewer... |
||
155 | // |
||
156 | string mapNameOrig = mapName; |
||
157 | if (mapName.Contains("|")) |
||
158 | mapName = mapName.Replace('|', ':'); |
||
159 | if (mapName.Contains("+")) |
||
160 | mapName = mapName.Replace('+', ' '); |
||
161 | if (mapName.Contains("!")) |
||
162 | mapName = mapName.Replace('!', '/'); |
||
163 | |||
164 | // try to fetch from GridServer |
||
165 | List<GridRegion> regionInfos = m_scene.GridService.GetRegionsByName(m_scene.RegionInfo.ScopeID, mapName, 20); |
||
166 | |||
167 | m_log.DebugFormat("[MAPSEARCHMODULE]: search {0} returned {1} regions. Flags={2}", mapName, regionInfos.Count, flags); |
||
168 | if (regionInfos.Count > 0) |
||
169 | { |
||
170 | foreach (GridRegion info in regionInfos) |
||
171 | { |
||
172 | data = new MapBlockData(); |
||
173 | data.Agents = 0; |
||
174 | data.Access = info.Access; |
||
175 | if (flags == 2) // V2 sends this |
||
176 | data.MapImageId = UUID.Zero; |
||
177 | else |
||
178 | data.MapImageId = info.TerrainImage; |
||
179 | // ugh! V2-3 is very sensitive about the result being |
||
180 | // exactly the same as the requested name |
||
181 | if (regionInfos.Count == 1 && mapNameOrig.Contains("|") || mapNameOrig.Contains("+")) |
||
182 | data.Name = mapNameOrig; |
||
183 | else |
||
184 | data.Name = info.RegionName; |
||
185 | data.RegionFlags = 0; // TODO not used? |
||
186 | data.WaterHeight = 0; // not used |
||
187 | data.X = (ushort)Util.WorldToRegionLoc((uint)info.RegionLocX); |
||
188 | data.Y = (ushort)Util.WorldToRegionLoc((uint)info.RegionLocY); |
||
189 | blocks.Add(data); |
||
190 | } |
||
191 | } |
||
192 | |||
193 | // final block, closing the search result |
||
194 | AddFinalBlock(blocks); |
||
195 | |||
196 | // flags are agent flags sent from the viewer. |
||
197 | // they have different values depending on different viewers, apparently |
||
198 | remoteClient.SendMapBlock(blocks, flags); |
||
199 | |||
200 | // send extra user messages for V3 |
||
201 | // because the UI is very confusing |
||
202 | // while we don't fix the hard-coded urls |
||
203 | if (flags == 2) |
||
204 | { |
||
205 | if (regionInfos.Count == 0) |
||
206 | remoteClient.SendAlertMessage("No regions found with that name."); |
||
207 | else if (regionInfos.Count == 1) |
||
208 | remoteClient.SendAlertMessage("Region found!"); |
||
209 | } |
||
210 | } |
||
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 | } |
||
226 | // private Scene GetClientScene(IClientAPI client) |
||
227 | // { |
||
228 | // foreach (Scene s in m_scenes) |
||
229 | // { |
||
230 | // if (client.Scene.RegionInfo.RegionHandle == s.RegionInfo.RegionHandle) |
||
231 | // return s; |
||
232 | // } |
||
233 | // return m_scene; |
||
234 | // } |
||
235 | } |
||
236 | } |