aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs304
1 files changed, 304 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
new file mode 100644
index 0000000..b7e3213
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
@@ -0,0 +1,304 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31
32using OpenSim.Framework;
33using OpenSim.Region.Framework.Interfaces;
34using OpenSim.Region.Framework.Scenes;
35using OpenSim.Services.Interfaces;
36using OpenSim.Server.Base;
37using OpenSim.Services.Connectors.Grid;
38
39using OpenMetaverse;
40using log4net;
41using Nini.Config;
42
43namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
44{
45 public class HGGridConnector : ISharedRegionModule, IGridService
46 {
47 private static readonly ILog m_log =
48 LogManager.GetLogger(
49 MethodBase.GetCurrentMethod().DeclaringType);
50
51 private bool m_Enabled = false;
52 private bool m_Initialized = false;
53
54 private IGridService m_GridServiceConnector;
55 private HypergridServiceConnector m_HypergridServiceConnector;
56
57 // Hyperlink regions are hyperlinks on the map
58 protected Dictionary<UUID, SimpleRegionInfo> m_HyperlinkRegions = new Dictionary<UUID, SimpleRegionInfo>();
59
60 // Known regions are home regions of visiting foreign users.
61 // They are not on the map as static hyperlinks. They are dynamic hyperlinks, they go away when
62 // the visitor goes away. They are mapped to X=0 on the map.
63 // This is key-ed on agent ID
64 protected Dictionary<UUID, SimpleRegionInfo> m_knownRegions = new Dictionary<UUID, SimpleRegionInfo>();
65
66 #region ISharedRegionModule
67
68 public Type ReplaceableInterface
69 {
70 get { return null; }
71 }
72
73 public string Name
74 {
75 get { return "HGGridServicesConnector"; }
76 }
77
78 public void Initialise(IConfigSource source)
79 {
80 IConfig moduleConfig = source.Configs["Modules"];
81 if (moduleConfig != null)
82 {
83 string name = moduleConfig.GetString("GridServices", "");
84 if (name == Name)
85 {
86 IConfig gridConfig = source.Configs["GridService"];
87 if (gridConfig == null)
88 {
89 m_log.Error("[HGGRID CONNECTOR]: GridService missing from OpenSim.ini");
90 return;
91 }
92
93
94 InitialiseConnectorModule(source);
95
96 m_Enabled = true;
97 m_log.Info("[HGGRID CONNECTOR]: HG grid enabled");
98 }
99 }
100 }
101
102 private void InitialiseConnectorModule(IConfigSource source)
103 {
104 IConfig gridConfig = source.Configs["GridService"];
105 if (gridConfig == null)
106 {
107 m_log.Error("[HGGRID CONNECTOR]: GridService missing from OpenSim.ini");
108 throw new Exception("Grid connector init error");
109 }
110
111 string module = gridConfig.GetString("GridServiceConnectorModule", String.Empty);
112 if (module == String.Empty)
113 {
114 m_log.Error("[HGGRID CONNECTOR]: No GridServiceConnectorModule named in section GridService");
115 //return;
116 throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's");
117 }
118
119 Object[] args = new Object[] { source };
120 m_GridServiceConnector = ServerUtils.LoadPlugin<IGridService>(module, args);
121
122 }
123
124 public void PostInitialise()
125 {
126 }
127
128 public void Close()
129 {
130 }
131
132 public void AddRegion(Scene scene)
133 {
134 if (!m_Enabled)
135 return;
136
137 scene.RegisterModuleInterface<IGridService>(this);
138 }
139
140 public void RemoveRegion(Scene scene)
141 {
142 }
143
144 public void RegionLoaded(Scene scene)
145 {
146 if (m_Enabled && !m_Initialized)
147 {
148 m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService);
149 m_Initialized = true;
150 }
151 }
152
153 #endregion
154
155 #region IGridService
156
157 public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo)
158 {
159 // Region doesn't exist here. Trying to link remote region
160 if (regionInfo.RegionID.Equals(UUID.Zero))
161 {
162 m_log.Info("[HGrid]: Linking remote region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort);
163 regionInfo.RegionID = m_HypergridServiceConnector.LinkRegion(regionInfo);
164 if (!regionInfo.RegionID.Equals(UUID.Zero))
165 {
166 m_HyperlinkRegions.Add(regionInfo.RegionID, regionInfo);
167 m_log.Info("[HGrid]: Successfully linked to region_uuid " + regionInfo.RegionID);
168
169 // Try get the map image
170 m_HypergridServiceConnector.GetMapImage(regionInfo);
171 return true;
172 }
173 else
174 {
175 m_log.Info("[HGrid]: No such region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort + "(" + regionInfo.InternalEndPoint.Port + ")");
176 return false;
177 }
178 // Note that these remote regions aren't registered in localBackend, so return null, no local listeners
179 }
180 else // normal grid
181 return m_GridServiceConnector.RegisterRegion(scopeID, regionInfo);
182 }
183
184 public bool DeregisterRegion(UUID regionID)
185 {
186 // Try the hyperlink collection
187 if (m_HyperlinkRegions.ContainsKey(regionID))
188 {
189 m_HyperlinkRegions.Remove(regionID);
190 return true;
191 }
192 // Try the foreign users home collection
193 if (m_knownRegions.ContainsKey(regionID))
194 {
195 m_knownRegions.Remove(regionID);
196 return true;
197 }
198 // Finally, try the normal route
199 return m_GridServiceConnector.DeregisterRegion(regionID);
200 }
201
202 public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID)
203 {
204 // No serving neighbours on hyperliked regions.
205 // Just the regular regions.
206 return m_GridServiceConnector.GetNeighbours(scopeID, regionID);
207 }
208
209 public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID)
210 {
211 // Try the hyperlink collection
212 if (m_HyperlinkRegions.ContainsKey(regionID))
213 return m_HyperlinkRegions[regionID];
214
215 // Try the foreign users home collection
216 if (m_knownRegions.ContainsKey(regionID))
217 return m_knownRegions[regionID];
218
219 // Finally, try the normal route
220 return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID);
221 }
222
223 public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y)
224 {
225 int snapX = (int) (x / Constants.RegionSize) * (int)Constants.RegionSize;
226 int snapY = (int) (y / Constants.RegionSize) * (int)Constants.RegionSize;
227 // Try the hyperlink collection
228 foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values)
229 {
230 if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY))
231 return r;
232 }
233
234 // Try the foreign users home collection
235 foreach (SimpleRegionInfo r in m_knownRegions.Values)
236 {
237 if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY))
238 return r;
239 }
240
241 // Finally, try the normal route
242 return m_GridServiceConnector.GetRegionByPosition(scopeID, x, y);
243 }
244
245 public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName)
246 {
247 // Try normal grid first
248 SimpleRegionInfo region = m_GridServiceConnector.GetRegionByName(scopeID, regionName);
249 if (region != null)
250 return region;
251
252 // !!! Commenting until region name exists
253 //// Try the hyperlink collection
254 //foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values)
255 //{
256 // if (r.RegionName == regionName)
257 // return r;
258 //}
259
260 //// Try the foreign users home collection
261 //foreach (SimpleRegionInfo r in m_knownRegions.Values)
262 //{
263 // if (r.RegionName == regionName)
264 // return r;
265 //}
266 return null;
267 }
268
269 public List<SimpleRegionInfo> GetRegionsByName(UUID scopeID, string name, int maxNumber)
270 {
271 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
272
273 // Commenting until regionname exists
274 //foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values)
275 // if ((r.RegionName != null) && r.RegionName.StartsWith(name))
276 // rinfos.Add(r);
277
278 rinfos.AddRange(m_GridServiceConnector.GetRegionsByName(scopeID, name, maxNumber));
279 return rinfos;
280 }
281
282 public List<SimpleRegionInfo> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
283 {
284 int snapXmin = (int)(xmin / Constants.RegionSize) * (int)Constants.RegionSize;
285 int snapXmax = (int)(xmax / Constants.RegionSize) * (int)Constants.RegionSize;
286 int snapYmin = (int)(ymin / Constants.RegionSize) * (int)Constants.RegionSize;
287 int snapYmax = (int)(ymax / Constants.RegionSize) * (int)Constants.RegionSize;
288
289 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
290 foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values)
291 if ((r.RegionLocX > snapXmin) && (r.RegionLocX < snapYmax) &&
292 (r.RegionLocY > snapYmin) && (r.RegionLocY < snapYmax))
293 rinfos.Add(r);
294
295 rinfos.AddRange(m_GridServiceConnector.GetRegionRange(scopeID, xmin, xmax, ymin, ymax));
296
297 return rinfos;
298 }
299
300 #endregion
301
302
303 }
304}