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  
28 using log4net;
29 using Mono.Addins;
30 using Nini.Config;
31 using System;
32 using System.Collections.Generic;
33 using System.Reflection;
34 using OpenSim.Framework;
35 using OpenSim.Framework.Console;
36 using OpenSim.Server.Base;
37 using OpenSim.Region.Framework.Interfaces;
38 using OpenSim.Region.Framework.Scenes;
39 using OpenSim.Services.Interfaces;
40 using GridRegion = OpenSim.Services.Interfaces.GridRegion;
41 using OpenMetaverse;
42  
43 namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
44 {
45 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LocalGridServicesConnector")]
46 public class LocalGridServicesConnector : ISharedRegionModule, IGridService
47 {
48 private static readonly ILog m_log =
49 LogManager.GetLogger(
50 MethodBase.GetCurrentMethod().DeclaringType);
51 private static string LogHeader = "[LOCAL GRID SERVICE CONNECTOR]";
52  
53 private IGridService m_GridService;
54 private Dictionary<UUID, RegionCache> m_LocalCache = new Dictionary<UUID, RegionCache>();
55  
56 private bool m_Enabled;
57  
58 public LocalGridServicesConnector()
59 {
60 m_log.DebugFormat("{0} LocalGridServicesConnector no parms.", LogHeader);
61 }
62  
63 public LocalGridServicesConnector(IConfigSource source)
64 {
65 m_log.DebugFormat("{0} LocalGridServicesConnector instantiated directly.", LogHeader);
66 InitialiseService(source);
67 }
68  
69 #region ISharedRegionModule
70  
71 public Type ReplaceableInterface
72 {
73 get { return null; }
74 }
75  
76 public string Name
77 {
78 get { return "LocalGridServicesConnector"; }
79 }
80  
81 public void Initialise(IConfigSource source)
82 {
83 IConfig moduleConfig = source.Configs["Modules"];
84 if (moduleConfig != null)
85 {
86 string name = moduleConfig.GetString("GridServices", "");
87 if (name == Name)
88 {
89 InitialiseService(source);
90 m_log.Info("[LOCAL GRID SERVICE CONNECTOR]: Local grid connector enabled");
91 }
92 }
93 }
94  
95 private void InitialiseService(IConfigSource source)
96 {
97 IConfig config = source.Configs["GridService"];
98 if (config == null)
99 {
100 m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: GridService missing from OpenSim.ini");
101 return;
102 }
103  
104 string serviceDll = config.GetString("LocalServiceModule", String.Empty);
105  
106 if (serviceDll == String.Empty)
107 {
108 m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: No LocalServiceModule named in section GridService");
109 return;
110 }
111  
112 Object[] args = new Object[] { source };
113 m_GridService =
114 ServerUtils.LoadPlugin<IGridService>(serviceDll,
115 args);
116  
117 if (m_GridService == null)
118 {
119 m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: Can't load grid service");
120 return;
121 }
122  
123 m_Enabled = true;
124 }
125  
126 public void PostInitialise()
127 {
128 // FIXME: We will still add this command even if we aren't enabled since RemoteGridServiceConnector
129 // will have instantiated us directly.
130 MainConsole.Instance.Commands.AddCommand("Regions", false, "show neighbours",
131 "show neighbours",
132 "Shows the local regions' neighbours", HandleShowNeighboursCommand);
133 }
134  
135 public void Close()
136 {
137 }
138  
139 public void AddRegion(Scene scene)
140 {
141 if (!m_Enabled)
142 return;
143  
144 scene.RegisterModuleInterface<IGridService>(this);
145  
146 lock (m_LocalCache)
147 {
148 if (m_LocalCache.ContainsKey(scene.RegionInfo.RegionID))
149 m_log.ErrorFormat("[LOCAL GRID SERVICE CONNECTOR]: simulator seems to have more than one region with the same UUID. Please correct this!");
150 else
151 m_LocalCache.Add(scene.RegionInfo.RegionID, new RegionCache(scene));
152 }
153 }
154  
155 public void RemoveRegion(Scene scene)
156 {
157 if (!m_Enabled)
158 return;
159  
160 lock (m_LocalCache)
161 {
162 m_LocalCache[scene.RegionInfo.RegionID].Clear();
163 m_LocalCache.Remove(scene.RegionInfo.RegionID);
164 }
165 }
166  
167 public void RegionLoaded(Scene scene)
168 {
169 }
170  
171 #endregion
172  
173 #region IGridService
174  
175 public string RegisterRegion(UUID scopeID, GridRegion regionInfo)
176 {
177 return m_GridService.RegisterRegion(scopeID, regionInfo);
178 }
179  
180 public bool DeregisterRegion(UUID regionID)
181 {
182 return m_GridService.DeregisterRegion(regionID);
183 }
184  
185 public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
186 {
187 return m_GridService.GetNeighbours(scopeID, regionID);
188 }
189  
190 public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
191 {
192 return m_GridService.GetRegionByUUID(scopeID, regionID);
193 }
194  
195 // Get a region given its base coordinates.
196 // NOTE: this is NOT 'get a region by some point in the region'. The coordinate MUST
197 // be the base coordinate of the region.
198 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
199 {
200 GridRegion region = null;
201 uint regionX = Util.WorldToRegionLoc((uint)x);
202 uint regionY = Util.WorldToRegionLoc((uint)y);
203  
204 // First see if it's a neighbour, even if it isn't on this sim.
205 // Neighbour data is cached in memory, so this is fast
206  
207 lock (m_LocalCache)
208 {
209 foreach (RegionCache rcache in m_LocalCache.Values)
210 {
211 region = rcache.GetRegionByPosition(x, y);
212 if (region != null)
213 {
214 // m_log.DebugFormat("{0} GetRegionByPosition. Found region {1} in cache. Pos=<{2},{3}>",
215 // LogHeader, region.RegionName, x, y);
216 break;
217 }
218 }
219 }
220  
221 // Then try on this sim (may be a lookup in DB if this is using MySql).
222 if (region == null)
223 {
224 region = m_GridService.GetRegionByPosition(scopeID, x, y);
225 /*
226 if (region == null)
227 {
228 m_log.DebugFormat("{0} GetRegionByPosition. Region not found by grid service. Pos=<{1},{2}>",
229 LogHeader, regionX, regionY);
230 }
231 else
232 {
233 m_log.DebugFormat("{0} GetRegionByPosition. Requested region {1} from grid service. Pos=<{2},{3}>",
234 LogHeader, region.RegionName, regionX, regionY);
235 }
236 */
237 }
238 return region;
239 }
240  
241 public GridRegion GetRegionByName(UUID scopeID, string regionName)
242 {
243 return m_GridService.GetRegionByName(scopeID, regionName);
244 }
245  
246 public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
247 {
248 return m_GridService.GetRegionsByName(scopeID, name, maxNumber);
249 }
250  
251 public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
252 {
253 return m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);
254 }
255  
256 public List<GridRegion> GetDefaultRegions(UUID scopeID)
257 {
258 return m_GridService.GetDefaultRegions(scopeID);
259 }
260  
261 public List<GridRegion> GetDefaultHypergridRegions(UUID scopeID)
262 {
263 return m_GridService.GetDefaultHypergridRegions(scopeID);
264 }
265  
266 public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y)
267 {
268 return m_GridService.GetFallbackRegions(scopeID, x, y);
269 }
270  
271 public List<GridRegion> GetHyperlinks(UUID scopeID)
272 {
273 return m_GridService.GetHyperlinks(scopeID);
274 }
275  
276 public int GetRegionFlags(UUID scopeID, UUID regionID)
277 {
278 return m_GridService.GetRegionFlags(scopeID, regionID);
279 }
280  
281 public Dictionary<string, object> GetExtraFeatures()
282 {
283 return m_GridService.GetExtraFeatures();
284 }
285  
286 #endregion
287  
288 public void HandleShowNeighboursCommand(string module, string[] cmdparams)
289 {
290 System.Text.StringBuilder caps = new System.Text.StringBuilder();
291  
292 lock (m_LocalCache)
293 {
294 foreach (KeyValuePair<UUID, RegionCache> kvp in m_LocalCache)
295 {
296 caps.AppendFormat("*** Neighbours of {0} ({1}) ***\n", kvp.Value.RegionName, kvp.Key);
297 List<GridRegion> regions = kvp.Value.GetNeighbours();
298 foreach (GridRegion r in regions)
299 caps.AppendFormat(" {0} @ {1}-{2}\n", r.RegionName, Util.WorldToRegionLoc((uint)r.RegionLocX), Util.WorldToRegionLoc((uint)r.RegionLocY));
300 }
301 }
302  
303 MainConsole.Instance.Output(caps.ToString());
304 }
305 }
306 }