clockwerk-opensim-stable – Blame information for rev 1
?pathlinks?
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 | |||
52 | private IGridService m_GridService; |
||
53 | private Dictionary<UUID, RegionCache> m_LocalCache = new Dictionary<UUID, RegionCache>(); |
||
54 | |||
55 | private bool m_Enabled; |
||
56 | |||
57 | public LocalGridServicesConnector() |
||
58 | { |
||
59 | m_log.Debug("[LOCAL GRID SERVICE CONNECTOR]: LocalGridServicesConnector no parms."); |
||
60 | } |
||
61 | |||
62 | public LocalGridServicesConnector(IConfigSource source) |
||
63 | { |
||
64 | m_log.Debug("[LOCAL GRID SERVICE CONNECTOR]: LocalGridServicesConnector instantiated directly."); |
||
65 | InitialiseService(source); |
||
66 | } |
||
67 | |||
68 | #region ISharedRegionModule |
||
69 | |||
70 | public Type ReplaceableInterface |
||
71 | { |
||
72 | get { return null; } |
||
73 | } |
||
74 | |||
75 | public string Name |
||
76 | { |
||
77 | get { return "LocalGridServicesConnector"; } |
||
78 | } |
||
79 | |||
80 | public void Initialise(IConfigSource source) |
||
81 | { |
||
82 | IConfig moduleConfig = source.Configs["Modules"]; |
||
83 | if (moduleConfig != null) |
||
84 | { |
||
85 | string name = moduleConfig.GetString("GridServices", ""); |
||
86 | if (name == Name) |
||
87 | { |
||
88 | InitialiseService(source); |
||
89 | m_log.Info("[LOCAL GRID SERVICE CONNECTOR]: Local grid connector enabled"); |
||
90 | } |
||
91 | } |
||
92 | } |
||
93 | |||
94 | private void InitialiseService(IConfigSource source) |
||
95 | { |
||
96 | IConfig assetConfig = source.Configs["GridService"]; |
||
97 | if (assetConfig == null) |
||
98 | { |
||
99 | m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: GridService missing from OpenSim.ini"); |
||
100 | return; |
||
101 | } |
||
102 | |||
103 | string serviceDll = assetConfig.GetString("LocalServiceModule", |
||
104 | 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 | public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) |
||
196 | { |
||
197 | GridRegion region = null; |
||
198 | |||
199 | // First see if it's a neighbour, even if it isn't on this sim. |
||
200 | // Neighbour data is cached in memory, so this is fast |
||
201 | |||
202 | lock (m_LocalCache) |
||
203 | { |
||
204 | foreach (RegionCache rcache in m_LocalCache.Values) |
||
205 | { |
||
206 | region = rcache.GetRegionByPosition(x, y); |
||
207 | if (region != null) |
||
208 | { |
||
209 | return region; |
||
210 | } |
||
211 | } |
||
212 | } |
||
213 | |||
214 | // Then try on this sim (may be a lookup in DB if this is using MySql). |
||
215 | return m_GridService.GetRegionByPosition(scopeID, x, y); |
||
216 | } |
||
217 | |||
218 | public GridRegion GetRegionByName(UUID scopeID, string regionName) |
||
219 | { |
||
220 | return m_GridService.GetRegionByName(scopeID, regionName); |
||
221 | } |
||
222 | |||
223 | public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber) |
||
224 | { |
||
225 | return m_GridService.GetRegionsByName(scopeID, name, maxNumber); |
||
226 | } |
||
227 | |||
228 | public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax) |
||
229 | { |
||
230 | return m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax); |
||
231 | } |
||
232 | |||
233 | public List<GridRegion> GetDefaultRegions(UUID scopeID) |
||
234 | { |
||
235 | return m_GridService.GetDefaultRegions(scopeID); |
||
236 | } |
||
237 | |||
238 | public List<GridRegion> GetDefaultHypergridRegions(UUID scopeID) |
||
239 | { |
||
240 | return m_GridService.GetDefaultHypergridRegions(scopeID); |
||
241 | } |
||
242 | |||
243 | public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y) |
||
244 | { |
||
245 | return m_GridService.GetFallbackRegions(scopeID, x, y); |
||
246 | } |
||
247 | |||
248 | public List<GridRegion> GetHyperlinks(UUID scopeID) |
||
249 | { |
||
250 | return m_GridService.GetHyperlinks(scopeID); |
||
251 | } |
||
252 | |||
253 | public int GetRegionFlags(UUID scopeID, UUID regionID) |
||
254 | { |
||
255 | return m_GridService.GetRegionFlags(scopeID, regionID); |
||
256 | } |
||
257 | |||
258 | #endregion |
||
259 | |||
260 | public void HandleShowNeighboursCommand(string module, string[] cmdparams) |
||
261 | { |
||
262 | System.Text.StringBuilder caps = new System.Text.StringBuilder(); |
||
263 | |||
264 | lock (m_LocalCache) |
||
265 | { |
||
266 | foreach (KeyValuePair<UUID, RegionCache> kvp in m_LocalCache) |
||
267 | { |
||
268 | caps.AppendFormat("*** Neighbours of {0} ({1}) ***\n", kvp.Value.RegionName, kvp.Key); |
||
269 | List<GridRegion> regions = kvp.Value.GetNeighbours(); |
||
270 | foreach (GridRegion r in regions) |
||
271 | caps.AppendFormat(" {0} @ {1}-{2}\n", r.RegionName, r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize); |
||
272 | } |
||
273 | } |
||
274 | |||
275 | MainConsole.Instance.Output(caps.ToString()); |
||
276 | } |
||
277 | } |
||
278 | } |