opensim-development – Blame information for rev 1

Subversion Repositories:
Rev:
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  
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 assetConfig = source.Configs["GridService"];
98 if (assetConfig == null)
99 {
100 m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: GridService missing from OpenSim.ini");
101 return;
102 }
103  
104 string serviceDll = assetConfig.GetString("LocalServiceModule",
105 String.Empty);
106  
107 if (serviceDll == String.Empty)
108 {
109 m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: No LocalServiceModule named in section GridService");
110 return;
111 }
112  
113 Object[] args = new Object[] { source };
114 m_GridService =
115 ServerUtils.LoadPlugin<IGridService>(serviceDll,
116 args);
117  
118 if (m_GridService == null)
119 {
120 m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: Can't load grid service");
121 return;
122 }
123  
124 m_Enabled = true;
125 }
126  
127 public void PostInitialise()
128 {
129 // FIXME: We will still add this command even if we aren't enabled since RemoteGridServiceConnector
130 // will have instantiated us directly.
131 MainConsole.Instance.Commands.AddCommand("Regions", false, "show neighbours",
132 "show neighbours",
133 "Shows the local regions' neighbours", HandleShowNeighboursCommand);
134 }
135  
136 public void Close()
137 {
138 }
139  
140 public void AddRegion(Scene scene)
141 {
142 if (!m_Enabled)
143 return;
144  
145 scene.RegisterModuleInterface<IGridService>(this);
146  
147 lock (m_LocalCache)
148 {
149 if (m_LocalCache.ContainsKey(scene.RegionInfo.RegionID))
150 m_log.ErrorFormat("[LOCAL GRID SERVICE CONNECTOR]: simulator seems to have more than one region with the same UUID. Please correct this!");
151 else
152 m_LocalCache.Add(scene.RegionInfo.RegionID, new RegionCache(scene));
153 }
154 }
155  
156 public void RemoveRegion(Scene scene)
157 {
158 if (!m_Enabled)
159 return;
160  
161 lock (m_LocalCache)
162 {
163 m_LocalCache[scene.RegionInfo.RegionID].Clear();
164 m_LocalCache.Remove(scene.RegionInfo.RegionID);
165 }
166 }
167  
168 public void RegionLoaded(Scene scene)
169 {
170 }
171  
172 #endregion
173  
174 #region IGridService
175  
176 public string RegisterRegion(UUID scopeID, GridRegion regionInfo)
177 {
178 return m_GridService.RegisterRegion(scopeID, regionInfo);
179 }
180  
181 public bool DeregisterRegion(UUID regionID)
182 {
183 return m_GridService.DeregisterRegion(regionID);
184 }
185  
186 public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
187 {
188 return m_GridService.GetNeighbours(scopeID, regionID);
189 }
190  
191 public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
192 {
193 return m_GridService.GetRegionByUUID(scopeID, regionID);
194 }
195  
196 // Get a region given its base coordinates.
197 // NOTE: this is NOT 'get a region by some point in the region'. The coordinate MUST
198 // be the base coordinate of the region.
199 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
200 {
201 GridRegion region = null;
202  
203 // First see if it's a neighbour, even if it isn't on this sim.
204 // Neighbour data is cached in memory, so this is fast
205  
206 lock (m_LocalCache)
207 {
208 foreach (RegionCache rcache in m_LocalCache.Values)
209 {
210 region = rcache.GetRegionByPosition(x, y);
211 if (region != null)
212 {
213 // m_log.DebugFormat("{0} GetRegionByPosition. Found region {1} in cache. Pos=<{2},{3}>",
214 // LogHeader, region.RegionName, x, y);
215 break;
216 }
217 }
218 }
219  
220 // Then try on this sim (may be a lookup in DB if this is using MySql).
221 if (region == null)
222 {
223 region = m_GridService.GetRegionByPosition(scopeID, x, y);
224 if (region == null)
225 m_log.DebugFormat("{0} GetRegionByPosition. Region not found by grid service. Pos=<{1},{2}>",
226 LogHeader, x, y);
227 else
228 m_log.DebugFormat("{0} GetRegionByPosition. Requested region {1} from grid service. Pos=<{2},{3}>",
229 LogHeader, region.RegionName, x, y);
230 }
231 return region;
232 }
233  
234 public GridRegion GetRegionByName(UUID scopeID, string regionName)
235 {
236 return m_GridService.GetRegionByName(scopeID, regionName);
237 }
238  
239 public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
240 {
241 return m_GridService.GetRegionsByName(scopeID, name, maxNumber);
242 }
243  
244 public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
245 {
246 return m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);
247 }
248  
249 public List<GridRegion> GetDefaultRegions(UUID scopeID)
250 {
251 return m_GridService.GetDefaultRegions(scopeID);
252 }
253  
254 public List<GridRegion> GetDefaultHypergridRegions(UUID scopeID)
255 {
256 return m_GridService.GetDefaultHypergridRegions(scopeID);
257 }
258  
259 public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y)
260 {
261 return m_GridService.GetFallbackRegions(scopeID, x, y);
262 }
263  
264 public List<GridRegion> GetHyperlinks(UUID scopeID)
265 {
266 return m_GridService.GetHyperlinks(scopeID);
267 }
268  
269 public int GetRegionFlags(UUID scopeID, UUID regionID)
270 {
271 return m_GridService.GetRegionFlags(scopeID, regionID);
272 }
273  
274 #endregion
275  
276 public void HandleShowNeighboursCommand(string module, string[] cmdparams)
277 {
278 System.Text.StringBuilder caps = new System.Text.StringBuilder();
279  
280 lock (m_LocalCache)
281 {
282 foreach (KeyValuePair<UUID, RegionCache> kvp in m_LocalCache)
283 {
284 caps.AppendFormat("*** Neighbours of {0} ({1}) ***\n", kvp.Value.RegionName, kvp.Key);
285 List<GridRegion> regions = kvp.Value.GetNeighbours();
286 foreach (GridRegion r in regions)
287 caps.AppendFormat(" {0} @ {1}-{2}\n", r.RegionName, Util.WorldToRegionLoc((uint)r.RegionLocX), Util.WorldToRegionLoc((uint)r.RegionLocY));
288 }
289 }
290  
291 MainConsole.Instance.Output(caps.ToString());
292 }
293 }
294 }