aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml4
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs129
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs295
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs558
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs68
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs182
6 files changed, 1209 insertions, 27 deletions
diff --git a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml
index f9e61aa..8f82718 100644
--- a/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml
+++ b/OpenSim/Region/CoreModules/Resources/CoreModulePlugin.addin.xml
@@ -38,11 +38,15 @@
38 <RegionModule id="RemoteLandServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Land.RemoteLandServicesConnector" /> 38 <RegionModule id="RemoteLandServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Land.RemoteLandServicesConnector" />
39 <RegionModule id="LocalInterregionComms" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion.LocalInterregionComms" /> 39 <RegionModule id="LocalInterregionComms" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion.LocalInterregionComms" />
40 <RegionModule id="RESTInterregionComms" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion.RESTInterregionComms" /> 40 <RegionModule id="RESTInterregionComms" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion.RESTInterregionComms" />
41 <RegionModule id="LocalGridServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.LocalGridServicesConnector" />
42 <RegionModule id="RemoteGridServicesConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.RemoteGridServicesConnector" />
43 <RegionModule id="HGGridConnector" type="OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.HGGridConnector" />
41 <!-- Service connectors IN modules --> 44 <!-- Service connectors IN modules -->
42 <RegionModule id="AssetServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Asset.AssetServiceInConnectorModule" /> 45 <RegionModule id="AssetServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Asset.AssetServiceInConnectorModule" />
43 <RegionModule id="InventoryServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Inventory.InventoryServiceInConnectorModule" /> 46 <RegionModule id="InventoryServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Inventory.InventoryServiceInConnectorModule" />
44 <RegionModule id="LandServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Land.LandServiceInConnectorModule" /> 47 <RegionModule id="LandServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Land.LandServiceInConnectorModule" />
45 <RegionModule id="NeighbourServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Neighbour.NeighbourServiceInConnectorModule" /> \ 48 <RegionModule id="NeighbourServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Neighbour.NeighbourServiceInConnectorModule" /> \
49 <RegionModule id="HypergridServiceInConnectorModule" type="OpenSim.Region.CoreModules.ServiceConnectorsIn.Grid.HypergridServiceInConnectorModule" /> \
46 50
47 </Extension> 51 </Extension>
48 52
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs
new file mode 100644
index 0000000..4fbee7f
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Grid/HypergridServiceInConnectorModule.cs
@@ -0,0 +1,129 @@
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.Reflection;
30using System.Collections.Generic;
31using log4net;
32using Nini.Config;
33using OpenSim.Framework;
34using OpenSim.Framework.Servers.HttpServer;
35using OpenSim.Region.Framework.Scenes;
36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Server.Base;
38using OpenSim.Server.Handlers.Base;
39using OpenSim.Server.Handlers.Grid;
40
41namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Grid
42{
43 public class HypergridServiceInConnectorModule : ISharedRegionModule
44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 private static bool m_Enabled = false;
47
48 private IConfigSource m_Config;
49 bool m_Registered = false;
50 HypergridServiceInConnector m_HypergridHandler;
51
52 #region IRegionModule interface
53
54 public void Initialise(IConfigSource config)
55 {
56 //// This module is only on for standalones in hypergrid mode
57 //enabled = (!config.Configs["Startup"].GetBoolean("gridmode", true)) &&
58 // config.Configs["Startup"].GetBoolean("hypergrid", true);
59 //m_log.DebugFormat("[RegionInventoryService]: enabled? {0}", enabled);
60 m_Config = config;
61 IConfig moduleConfig = config.Configs["Modules"];
62 if (moduleConfig != null)
63 {
64 m_Enabled = moduleConfig.GetBoolean("HypergridServiceInConnector", false);
65 if (m_Enabled)
66 {
67 m_log.Info("[HGGRID IN CONNECTOR]: Hypergrid Service In Connector enabled");
68 }
69
70 }
71
72 }
73
74 public void PostInitialise()
75 {
76 }
77
78 public void Close()
79 {
80 }
81
82 public Type ReplaceableInterface
83 {
84 get { return null; }
85 }
86
87 public string Name
88 {
89 get { return "HypergridService"; }
90 }
91
92 public void AddRegion(Scene scene)
93 {
94 if (!m_Enabled)
95 return;
96
97 if (!m_Registered)
98 {
99 m_Registered = true;
100
101 m_log.Info("[HypergridService]: Starting...");
102
103 Object[] args = new Object[] { m_Config, MainServer.Instance };
104
105 m_HypergridHandler = new HypergridServiceInConnector(m_Config, MainServer.Instance);
106 //ServerUtils.LoadPlugin<HypergridServiceInConnector>("OpenSim.Server.Handlers.dll:HypergridServiceInConnector", args);
107 }
108
109 SimpleRegionInfo rinfo = new SimpleRegionInfo(scene.RegionInfo);
110 m_HypergridHandler.AddRegion(rinfo);
111 }
112
113 public void RemoveRegion(Scene scene)
114 {
115 if (!m_Enabled)
116 return;
117
118 SimpleRegionInfo rinfo = new SimpleRegionInfo(scene.RegionInfo);
119 m_HypergridHandler.RemoveRegion(rinfo);
120 }
121
122 public void RegionLoaded(Scene scene)
123 {
124 }
125
126 #endregion
127
128 }
129}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs
new file mode 100644
index 0000000..2a862d4
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs
@@ -0,0 +1,295 @@
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;
31using System.Xml;
32using log4net;
33using Nini.Config;
34using OpenSim.Framework;
35//using OpenSim.Framework.Communications;
36using OpenSim.Framework.Console;
37using OpenSim.Region.Framework;
38using OpenSim.Region.Framework.Scenes;
39using OpenSim.Region.Framework.Scenes.Hypergrid;
40
41namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
42{
43 public class HGCommands
44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 private HGGridConnector m_HGGridConnector;
47 private Scene m_scene;
48
49 private static uint m_autoMappingX = 0;
50 private static uint m_autoMappingY = 0;
51 private static bool m_enableAutoMapping = false;
52
53 public HGCommands(HGGridConnector hgConnector, Scene scene)
54 {
55 m_HGGridConnector = hgConnector;
56 m_scene = scene;
57 }
58
59 //public static Scene CreateScene(RegionInfo regionInfo, AgentCircuitManager circuitManager, CommunicationsManager m_commsManager,
60 // StorageManager storageManager, ModuleLoader m_moduleLoader, ConfigSettings m_configSettings, OpenSimConfigSource m_config, string m_version)
61 //{
62 // HGSceneCommunicationService sceneGridService = new HGSceneCommunicationService(m_commsManager, HGServices);
63
64 // return
65 // new HGScene(
66 // regionInfo, circuitManager, m_commsManager, sceneGridService, storageManager,
67 // m_moduleLoader, false, m_configSettings.PhysicalPrim,
68 // m_configSettings.See_into_region_from_neighbor, m_config.Source, m_version);
69 //}
70
71 public void RunCommand(string module, string[] cmdparams)
72 {
73 List<string> args = new List<string>(cmdparams);
74 if (args.Count < 1)
75 return;
76
77 string command = args[0];
78 args.RemoveAt(0);
79
80 cmdparams = args.ToArray();
81
82 RunHGCommand(command, cmdparams);
83
84 }
85
86 private void RunHGCommand(string command, string[] cmdparams)
87 {
88 if (command.Equals("linkk-mapping"))
89 {
90 if (cmdparams.Length == 2)
91 {
92 try
93 {
94 m_autoMappingX = Convert.ToUInt32(cmdparams[0]);
95 m_autoMappingY = Convert.ToUInt32(cmdparams[1]);
96 m_enableAutoMapping = true;
97 }
98 catch (Exception)
99 {
100 m_autoMappingX = 0;
101 m_autoMappingY = 0;
102 m_enableAutoMapping = false;
103 }
104 }
105 }
106 else if (command.Equals("linkk-region"))
107 {
108 if (cmdparams.Length < 3)
109 {
110 if ((cmdparams.Length == 1) || (cmdparams.Length == 2))
111 {
112 LoadXmlLinkFile(cmdparams);
113 }
114 else
115 {
116 LinkRegionCmdUsage();
117 }
118 return;
119 }
120
121 if (cmdparams[2].Contains(":"))
122 {
123 // New format
124 uint xloc, yloc;
125 string mapName;
126 try
127 {
128 xloc = Convert.ToUInt32(cmdparams[0]);
129 yloc = Convert.ToUInt32(cmdparams[1]);
130 mapName = cmdparams[2];
131 if (cmdparams.Length > 3)
132 for (int i = 3; i < cmdparams.Length; i++)
133 mapName += " " + cmdparams[i];
134
135 m_log.Info(">> MapName: " + mapName);
136 //internalPort = Convert.ToUInt32(cmdparams[4]);
137 //remotingPort = Convert.ToUInt32(cmdparams[5]);
138 }
139 catch (Exception e)
140 {
141 m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message);
142 LinkRegionCmdUsage();
143 return;
144 }
145
146 m_HGGridConnector.TryLinkRegionToCoords(m_scene, null, mapName, xloc, yloc);
147 }
148 else
149 {
150 // old format
151 SimpleRegionInfo regInfo;
152 uint xloc, yloc;
153 uint externalPort;
154 string externalHostName;
155 try
156 {
157 xloc = Convert.ToUInt32(cmdparams[0]);
158 yloc = Convert.ToUInt32(cmdparams[1]);
159 externalPort = Convert.ToUInt32(cmdparams[3]);
160 externalHostName = cmdparams[2];
161 //internalPort = Convert.ToUInt32(cmdparams[4]);
162 //remotingPort = Convert.ToUInt32(cmdparams[5]);
163 }
164 catch (Exception e)
165 {
166 m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message);
167 LinkRegionCmdUsage();
168 return;
169 }
170
171 //if (TryCreateLink(xloc, yloc, externalPort, externalHostName, out regInfo))
172 if (m_HGGridConnector.TryCreateLink(m_scene, null, xloc, yloc, "", externalPort, externalHostName, out regInfo))
173 {
174 if (cmdparams.Length >= 5)
175 {
176 regInfo.RegionName = "";
177 for (int i = 4; i < cmdparams.Length; i++)
178 regInfo.RegionName += cmdparams[i] + " ";
179 }
180 }
181 }
182 return;
183 }
184 else if (command.Equals("unlinkk-region"))
185 {
186 if (cmdparams.Length < 1)
187 {
188 UnlinkRegionCmdUsage();
189 return;
190 }
191 if (m_HGGridConnector.TryUnlinkRegion(m_scene, cmdparams[0]))
192 m_log.InfoFormat("[HGrid]: Successfully unlinked {0}", cmdparams[0]);
193 else
194 m_log.InfoFormat("[HGrid]: Unable to unlink {0}, region not found", cmdparams[0]);
195 }
196 }
197
198 private void LoadXmlLinkFile(string[] cmdparams)
199 {
200 //use http://www.hgurl.com/hypergrid.xml for test
201 try
202 {
203 XmlReader r = XmlReader.Create(cmdparams[0]);
204 XmlConfigSource cs = new XmlConfigSource(r);
205 string[] excludeSections = null;
206
207 if (cmdparams.Length == 2)
208 {
209 if (cmdparams[1].ToLower().StartsWith("excludelist:"))
210 {
211 string excludeString = cmdparams[1].ToLower();
212 excludeString = excludeString.Remove(0, 12);
213 char[] splitter = { ';' };
214
215 excludeSections = excludeString.Split(splitter);
216 }
217 }
218
219 for (int i = 0; i < cs.Configs.Count; i++)
220 {
221 bool skip = false;
222 if ((excludeSections != null) && (excludeSections.Length > 0))
223 {
224 for (int n = 0; n < excludeSections.Length; n++)
225 {
226 if (excludeSections[n] == cs.Configs[i].Name.ToLower())
227 {
228 skip = true;
229 break;
230 }
231 }
232 }
233 if (!skip)
234 {
235 ReadLinkFromConfig(cs.Configs[i]);
236 }
237 }
238 }
239 catch (Exception e)
240 {
241 m_log.Error(e.ToString());
242 }
243 }
244
245
246 private void ReadLinkFromConfig(IConfig config)
247 {
248 SimpleRegionInfo regInfo;
249 uint xloc, yloc;
250 uint externalPort;
251 string externalHostName;
252 uint realXLoc, realYLoc;
253
254 xloc = Convert.ToUInt32(config.GetString("xloc", "0"));
255 yloc = Convert.ToUInt32(config.GetString("yloc", "0"));
256 externalPort = Convert.ToUInt32(config.GetString("externalPort", "0"));
257 externalHostName = config.GetString("externalHostName", "");
258 realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0"));
259 realYLoc = Convert.ToUInt32(config.GetString("real-yloc", "0"));
260
261 if (m_enableAutoMapping)
262 {
263 xloc = (uint)((xloc % 100) + m_autoMappingX);
264 yloc = (uint)((yloc % 100) + m_autoMappingY);
265 }
266
267 if (((realXLoc == 0) && (realYLoc == 0)) ||
268 (((realXLoc - xloc < 3896) || (xloc - realXLoc < 3896)) &&
269 ((realYLoc - yloc < 3896) || (yloc - realYLoc < 3896))))
270 {
271 if (
272 m_HGGridConnector.TryCreateLink(m_scene, null, xloc, yloc, "", externalPort,
273 externalHostName, out regInfo))
274 {
275 regInfo.RegionName = config.GetString("localName", "");
276 }
277 }
278 }
279
280
281 private void LinkRegionCmdUsage()
282 {
283 m_log.Info("Usage: link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>]");
284 m_log.Info("Usage: link-region <Xloc> <Yloc> <HostName> <HttpPort> [<LocalName>]");
285 m_log.Info("Usage: link-region <URI_of_xml> [<exclude>]");
286 }
287
288 private void UnlinkRegionCmdUsage()
289 {
290 m_log.Info("Usage: unlink-region <HostName>:<HttpPort>");
291 m_log.Info("Usage: unlink-region <LocalName>");
292 }
293
294 }
295}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
new file mode 100644
index 0000000..c6ade15
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
@@ -0,0 +1,558 @@
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.Net;
31using System.Reflection;
32using System.Xml;
33
34using OpenSim.Framework;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes;
37using OpenSim.Region.Framework.Scenes.Hypergrid;
38using OpenSim.Services.Interfaces;
39using OpenSim.Server.Base;
40using OpenSim.Services.Connectors.Grid;
41using OpenSim.Framework.Console;
42
43using OpenMetaverse;
44using log4net;
45using Nini.Config;
46
47namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
48{
49 public class HGGridConnector : ISharedRegionModule, IGridService
50 {
51 private static readonly ILog m_log =
52 LogManager.GetLogger(
53 MethodBase.GetCurrentMethod().DeclaringType);
54
55 private bool m_Enabled = false;
56 private bool m_Initialized = false;
57
58 private IGridService m_GridServiceConnector;
59 private HypergridServiceConnector m_HypergridServiceConnector;
60
61 // Hyperlink regions are hyperlinks on the map
62 protected Dictionary<UUID, SimpleRegionInfo> m_HyperlinkRegions = new Dictionary<UUID, SimpleRegionInfo>();
63
64 // Known regions are home regions of visiting foreign users.
65 // They are not on the map as static hyperlinks. They are dynamic hyperlinks, they go away when
66 // the visitor goes away. They are mapped to X=0 on the map.
67 // This is key-ed on agent ID
68 protected Dictionary<UUID, SimpleRegionInfo> m_knownRegions = new Dictionary<UUID, SimpleRegionInfo>();
69
70 protected Dictionary<UUID, ulong> m_HyperlinkHandles = new Dictionary<UUID, ulong>();
71
72 #region ISharedRegionModule
73
74 public Type ReplaceableInterface
75 {
76 get { return null; }
77 }
78
79 public string Name
80 {
81 get { return "HGGridServicesConnector"; }
82 }
83
84 public void Initialise(IConfigSource source)
85 {
86 IConfig moduleConfig = source.Configs["Modules"];
87 if (moduleConfig != null)
88 {
89 string name = moduleConfig.GetString("GridServices", "");
90 if (name == Name)
91 {
92 IConfig gridConfig = source.Configs["GridService"];
93 if (gridConfig == null)
94 {
95 m_log.Error("[HGGRID CONNECTOR]: GridService missing from OpenSim.ini");
96 return;
97 }
98
99
100 InitialiseConnectorModule(source);
101
102 m_Enabled = true;
103 m_log.Info("[HGGRID CONNECTOR]: HG grid enabled");
104 }
105 }
106 }
107
108 private void InitialiseConnectorModule(IConfigSource source)
109 {
110 IConfig gridConfig = source.Configs["GridService"];
111 if (gridConfig == null)
112 {
113 m_log.Error("[HGGRID CONNECTOR]: GridService missing from OpenSim.ini");
114 throw new Exception("Grid connector init error");
115 }
116
117 string module = gridConfig.GetString("GridServiceConnectorModule", String.Empty);
118 if (module == String.Empty)
119 {
120 m_log.Error("[HGGRID CONNECTOR]: No GridServiceConnectorModule named in section GridService");
121 //return;
122 throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's");
123 }
124
125 Object[] args = new Object[] { source };
126 m_GridServiceConnector = ServerUtils.LoadPlugin<IGridService>(module, args);
127
128 }
129
130 public void PostInitialise()
131 {
132 }
133
134 public void Close()
135 {
136 }
137
138 public void AddRegion(Scene scene)
139 {
140 if (!m_Enabled)
141 return;
142
143 scene.RegisterModuleInterface<IGridService>(this);
144
145 }
146
147 public void RemoveRegion(Scene scene)
148 {
149 }
150
151 public void RegionLoaded(Scene scene)
152 {
153 if (!m_Enabled)
154 return;
155
156 if (!m_Initialized)
157 {
158 m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService);
159 HGCommands hgCommands = new HGCommands(this, scene);
160 MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "linkk-region",
161 "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>",
162 "Link a hypergrid region", hgCommands.RunCommand);
163 MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "unlinkk-region",
164 "unlink-region <local name> or <HostName>:<HttpPort> <cr>",
165 "Unlink a hypergrid region", hgCommands.RunCommand);
166 MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "linkk-mapping", "link-mapping [<x> <y>] <cr>",
167 "Set local coordinate to map HG regions to", hgCommands.RunCommand);
168 m_Initialized = true;
169 }
170
171
172 //scene.AddCommand("HGGridServicesConnector", "linkk-region",
173 // "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>",
174 // "Link a hypergrid region", hgCommands.RunCommand);
175 //scene.AddCommand("HGGridServicesConnector", "unlinkk-region",
176 // "unlink-region <local name> or <HostName>:<HttpPort> <cr>",
177 // "Unlink a hypergrid region", hgCommands.RunCommand);
178 //scene.AddCommand("HGGridServicesConnector", "linkk-mapping", "link-mapping [<x> <y>] <cr>",
179 // "Set local coordinate to map HG regions to", hgCommands.RunCommand);
180
181 }
182
183 #endregion
184
185 #region IGridService
186
187 public bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo)
188 {
189 // Region doesn't exist here. Trying to link remote region
190 if (regionInfo.RegionID.Equals(UUID.Zero))
191 {
192 m_log.Info("[HGrid]: Linking remote region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort);
193 ulong regionHandle = 0;
194 regionInfo.RegionID = m_HypergridServiceConnector.LinkRegion(regionInfo, out regionHandle);
195 if (!regionInfo.RegionID.Equals(UUID.Zero))
196 {
197 AddHyperlinkRegion(regionInfo, regionHandle);
198 m_log.Info("[HGrid]: Successfully linked to region_uuid " + regionInfo.RegionID);
199
200 // Try get the map image
201 m_HypergridServiceConnector.GetMapImage(regionInfo);
202 return true;
203 }
204 else
205 {
206 m_log.Info("[HGrid]: No such region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort + "(" + regionInfo.InternalEndPoint.Port + ")");
207 return false;
208 }
209 // Note that these remote regions aren't registered in localBackend, so return null, no local listeners
210 }
211 else // normal grid
212 return m_GridServiceConnector.RegisterRegion(scopeID, regionInfo);
213 }
214
215 public bool DeregisterRegion(UUID regionID)
216 {
217 // Try the hyperlink collection
218 if (m_HyperlinkRegions.ContainsKey(regionID))
219 {
220 RemoveHyperlinkRegion(regionID);
221 return true;
222 }
223 // Try the foreign users home collection
224
225 foreach (SimpleRegionInfo r in m_knownRegions.Values)
226 if (r.RegionID == regionID)
227 {
228 RemoveHyperlinkHomeRegion(regionID);
229 return true;
230 }
231
232 // Finally, try the normal route
233 return m_GridServiceConnector.DeregisterRegion(regionID);
234 }
235
236 public List<SimpleRegionInfo> GetNeighbours(UUID scopeID, UUID regionID)
237 {
238 // No serving neighbours on hyperliked regions.
239 // Just the regular regions.
240 return m_GridServiceConnector.GetNeighbours(scopeID, regionID);
241 }
242
243 public SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID)
244 {
245 // Try the hyperlink collection
246 if (m_HyperlinkRegions.ContainsKey(regionID))
247 return m_HyperlinkRegions[regionID];
248
249 // Try the foreign users home collection
250 foreach (SimpleRegionInfo r in m_knownRegions.Values)
251 if (r.RegionID == regionID)
252 return m_knownRegions[regionID];
253
254 // Finally, try the normal route
255 return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID);
256 }
257
258 public SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y)
259 {
260 int snapX = (int) (x / Constants.RegionSize) * (int)Constants.RegionSize;
261 int snapY = (int) (y / Constants.RegionSize) * (int)Constants.RegionSize;
262 // Try the hyperlink collection
263 foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values)
264 {
265 if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY))
266 return r;
267 }
268
269 // Try the foreign users home collection
270 foreach (SimpleRegionInfo r in m_knownRegions.Values)
271 {
272 if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY))
273 return r;
274 }
275
276 // Finally, try the normal route
277 return m_GridServiceConnector.GetRegionByPosition(scopeID, x, y);
278 }
279
280 public SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName)
281 {
282 // Try normal grid first
283 SimpleRegionInfo region = m_GridServiceConnector.GetRegionByName(scopeID, regionName);
284 if (region != null)
285 return region;
286
287 // Try the hyperlink collection
288 foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values)
289 {
290 if (r.RegionName == regionName)
291 return r;
292 }
293
294 // Try the foreign users home collection
295 foreach (SimpleRegionInfo r in m_knownRegions.Values)
296 {
297 if (r.RegionName == regionName)
298 return r;
299 }
300 return null;
301 }
302
303 public List<SimpleRegionInfo> GetRegionsByName(UUID scopeID, string name, int maxNumber)
304 {
305 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
306
307 // Commenting until regionname exists
308 //foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values)
309 // if ((r.RegionName != null) && r.RegionName.StartsWith(name))
310 // rinfos.Add(r);
311
312 rinfos.AddRange(m_GridServiceConnector.GetRegionsByName(scopeID, name, maxNumber));
313 return rinfos;
314 }
315
316 public List<SimpleRegionInfo> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
317 {
318 int snapXmin = (int)(xmin / Constants.RegionSize) * (int)Constants.RegionSize;
319 int snapXmax = (int)(xmax / Constants.RegionSize) * (int)Constants.RegionSize;
320 int snapYmin = (int)(ymin / Constants.RegionSize) * (int)Constants.RegionSize;
321 int snapYmax = (int)(ymax / Constants.RegionSize) * (int)Constants.RegionSize;
322
323 List<SimpleRegionInfo> rinfos = new List<SimpleRegionInfo>();
324 foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values)
325 if ((r.RegionLocX > snapXmin) && (r.RegionLocX < snapYmax) &&
326 (r.RegionLocY > snapYmin) && (r.RegionLocY < snapYmax))
327 rinfos.Add(r);
328
329 rinfos.AddRange(m_GridServiceConnector.GetRegionRange(scopeID, xmin, xmax, ymin, ymax));
330
331 return rinfos;
332 }
333
334 #endregion
335
336 #region Auxiliary
337
338 private void AddHyperlinkRegion(SimpleRegionInfo regionInfo, ulong regionHandle)
339 {
340 m_HyperlinkRegions.Add(regionInfo.RegionID, regionInfo);
341 m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle);
342 }
343
344 private void RemoveHyperlinkRegion(UUID regionID)
345 {
346 m_HyperlinkRegions.Remove(regionID);
347 m_HyperlinkHandles.Remove(regionID);
348 }
349
350 private void AddHyperlinkHomeRegion(UUID userID, SimpleRegionInfo regionInfo, ulong regionHandle)
351 {
352 m_knownRegions.Add(userID, regionInfo);
353 m_HyperlinkHandles.Add(regionInfo.RegionID, regionHandle);
354 }
355
356 private void RemoveHyperlinkHomeRegion(UUID regionID)
357 {
358 foreach (KeyValuePair<UUID, SimpleRegionInfo> kvp in m_knownRegions)
359 {
360 if (kvp.Value.RegionID == regionID)
361 {
362 m_knownRegions.Remove(kvp.Key);
363 }
364 }
365 m_HyperlinkHandles.Remove(regionID);
366 }
367 #endregion
368
369 #region Hyperlinks
370
371 private static Random random = new Random();
372
373 public SimpleRegionInfo TryLinkRegionToCoords(Scene m_scene, IClientAPI client, string mapName, uint xloc, uint yloc)
374 {
375 string host = "127.0.0.1";
376 string portstr;
377 string regionName = "";
378 uint port = 9000;
379 string[] parts = mapName.Split(new char[] { ':' });
380 if (parts.Length >= 1)
381 {
382 host = parts[0];
383 }
384 if (parts.Length >= 2)
385 {
386 portstr = parts[1];
387 if (!UInt32.TryParse(portstr, out port))
388 regionName = parts[1];
389 }
390 // always take the last one
391 if (parts.Length >= 3)
392 {
393 regionName = parts[2];
394 }
395
396 // Sanity check. Don't ever link to this sim.
397 IPAddress ipaddr = null;
398 try
399 {
400 ipaddr = Util.GetHostFromDNS(host);
401 }
402 catch { }
403
404 if ((ipaddr != null) &&
405 !((m_scene.RegionInfo.ExternalEndPoint.Address.Equals(ipaddr)) && (m_scene.RegionInfo.HttpPort == port)))
406 {
407 SimpleRegionInfo regInfo;
408 bool success = TryCreateLink(m_scene, client, xloc, yloc, regionName, port, host, out regInfo);
409 if (success)
410 {
411 regInfo.RegionName = mapName;
412 return regInfo;
413 }
414 }
415
416 return null;
417 }
418
419 // From the map search and secondlife://blah
420 public SimpleRegionInfo TryLinkRegion(Scene m_scene, IClientAPI client, string mapName)
421 {
422 uint xloc = (uint)(random.Next(0, Int16.MaxValue));
423 return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0);
424 }
425
426 public bool TryCreateLink(Scene m_scene, IClientAPI client, uint xloc, uint yloc,
427 string externalRegionName, uint externalPort, string externalHostName, out SimpleRegionInfo regInfo)
428 {
429 m_log.DebugFormat("[HGrid]: Link to {0}:{1}, in {2}-{3}", externalHostName, externalPort, xloc, yloc);
430
431 regInfo = new SimpleRegionInfo();
432 regInfo.RegionName = externalRegionName;
433 regInfo.HttpPort = externalPort;
434 regInfo.ExternalHostName = externalHostName;
435 regInfo.RegionLocX = xloc;
436 regInfo.RegionLocY = yloc;
437
438 try
439 {
440 regInfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)0);
441 }
442 catch (Exception e)
443 {
444 m_log.Warn("[HGrid]: Wrong format for link-region: " + e.Message);
445 return false;
446 }
447
448 // Finally, link it
449 try
450 {
451 RegisterRegion(UUID.Zero, regInfo);
452 }
453 catch (Exception e)
454 {
455 m_log.Warn("[HGrid]: Unable to link region: " + e.Message);
456 return false;
457 }
458
459 uint x, y;
460 if (!Check4096(m_scene, regInfo, out x, out y))
461 {
462 DeregisterRegion(regInfo.RegionID);
463 if (client != null)
464 client.SendAlertMessage("Region is too far (" + x + ", " + y + ")");
465 m_log.Info("[HGrid]: Unable to link, region is too far (" + x + ", " + y + ")");
466 return false;
467 }
468
469 if (!CheckCoords(m_scene.RegionInfo.RegionLocX, m_scene.RegionInfo.RegionLocY, x, y))
470 {
471 DeregisterRegion(regInfo.RegionID);
472 if (client != null)
473 client.SendAlertMessage("Region has incompatible coordinates (" + x + ", " + y + ")");
474 m_log.Info("[HGrid]: Unable to link, region has incompatible coordinates (" + x + ", " + y + ")");
475 return false;
476 }
477
478 m_log.Debug("[HGrid]: link region succeeded");
479 return true;
480 }
481
482 public bool TryUnlinkRegion(Scene m_scene, string mapName)
483 {
484 SimpleRegionInfo regInfo = null;
485 if (mapName.Contains(":"))
486 {
487 string host = "127.0.0.1";
488 //string portstr;
489 //string regionName = "";
490 uint port = 9000;
491 string[] parts = mapName.Split(new char[] { ':' });
492 if (parts.Length >= 1)
493 {
494 host = parts[0];
495 }
496 // if (parts.Length >= 2)
497 // {
498 // portstr = parts[1];
499 // if (!UInt32.TryParse(portstr, out port))
500 // regionName = parts[1];
501 // }
502 // always take the last one
503 // if (parts.Length >= 3)
504 // {
505 // regionName = parts[2];
506 // }
507 foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values)
508 if (host.Equals(r.ExternalHostName) && (port == r.HttpPort))
509 regInfo = r;
510 }
511 else
512 {
513 foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values)
514 if (r.RegionName.Equals(mapName))
515 regInfo = r;
516 }
517 if (regInfo != null)
518 {
519 return DeregisterRegion(regInfo.RegionID);
520 }
521 else
522 {
523 m_log.InfoFormat("[HGrid]: Region {0} not found", mapName);
524 return false;
525 }
526 }
527
528 /// <summary>
529 /// Cope with this viewer limitation.
530 /// </summary>
531 /// <param name="regInfo"></param>
532 /// <returns></returns>
533 public bool Check4096(Scene m_scene, SimpleRegionInfo regInfo, out uint x, out uint y)
534 {
535 ulong realHandle = m_HyperlinkHandles[regInfo.RegionID];
536 Utils.LongToUInts(realHandle, out x, out y);
537 x = x / Constants.RegionSize;
538 y = y / Constants.RegionSize;
539
540 if ((Math.Abs((int)m_scene.RegionInfo.RegionLocX - (int)x) >= 4096) ||
541 (Math.Abs((int)m_scene.RegionInfo.RegionLocY - (int)y) >= 4096))
542 {
543 return false;
544 }
545 return true;
546 }
547
548 public bool CheckCoords(uint thisx, uint thisy, uint x, uint y)
549 {
550 if ((thisx == x) && (thisy == y))
551 return false;
552 return true;
553 }
554
555 #endregion
556
557 }
558}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
index 74ece2e..c1b7235 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
@@ -50,6 +50,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
50 50
51 private bool m_Enabled = false; 51 private bool m_Enabled = false;
52 52
53 public LocalGridServicesConnector()
54 {
55 }
56
57 public LocalGridServicesConnector(IConfigSource source)
58 {
59 InitialiseService(source);
60 }
61
53 #region ISharedRegionModule 62 #region ISharedRegionModule
54 63
55 public Type ReplaceableInterface 64 public Type ReplaceableInterface
@@ -70,38 +79,43 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
70 string name = moduleConfig.GetString("GridServices", ""); 79 string name = moduleConfig.GetString("GridServices", "");
71 if (name == Name) 80 if (name == Name)
72 { 81 {
73 IConfig assetConfig = source.Configs["GridService"]; 82 InitialiseService(source);
74 if (assetConfig == null)
75 {
76 m_log.Error("[GRID CONNECTOR]: GridService missing from OpenSim.ini");
77 return;
78 }
79
80 string serviceDll = assetConfig.GetString("LocalServiceModule",
81 String.Empty);
82
83 if (serviceDll == String.Empty)
84 {
85 m_log.Error("[GRID CONNECTOR]: No LocalServiceModule named in section GridService");
86 return;
87 }
88
89 Object[] args = new Object[] { source };
90 m_GridService =
91 ServerUtils.LoadPlugin<IGridService>(serviceDll,
92 args);
93
94 if (m_GridService == null)
95 {
96 m_log.Error("[GRID CONNECTOR]: Can't load asset service");
97 return;
98 }
99 m_Enabled = true; 83 m_Enabled = true;
100 m_log.Info("[GRID CONNECTOR]: Local grid connector enabled"); 84 m_log.Info("[LOCAL GRID CONNECTOR]: Local grid connector enabled");
101 } 85 }
102 } 86 }
103 } 87 }
104 88
89 private void InitialiseService(IConfigSource source)
90 {
91 IConfig assetConfig = source.Configs["GridService"];
92 if (assetConfig == null)
93 {
94 m_log.Error("[LOCAL GRID CONNECTOR]: GridService missing from OpenSim.ini");
95 return;
96 }
97
98 string serviceDll = assetConfig.GetString("LocalServiceModule",
99 String.Empty);
100
101 if (serviceDll == String.Empty)
102 {
103 m_log.Error("[LOCAL GRID CONNECTOR]: No LocalServiceModule named in section GridService");
104 return;
105 }
106
107 Object[] args = new Object[] { source };
108 m_GridService =
109 ServerUtils.LoadPlugin<IGridService>(serviceDll,
110 args);
111
112 if (m_GridService == null)
113 {
114 m_log.Error("[LOCAL GRID CONNECTOR]: Can't load asset service");
115 return;
116 }
117 }
118
105 public void PostInitialise() 119 public void PostInitialise()
106 { 120 {
107 } 121 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs
new file mode 100644
index 0000000..4303fa8
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs
@@ -0,0 +1,182 @@
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 log4net;
29using System;
30using System.Collections.Generic;
31using System.Reflection;
32using Nini.Config;
33using OpenMetaverse;
34
35using OpenSim.Framework;
36using OpenSim.Services.Connectors;
37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes;
39using OpenSim.Services.Interfaces;
40
41namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
42{
43 public class RemoteGridServicesConnector :
44 GridServicesConnector, ISharedRegionModule, IGridService
45 {
46 private static readonly ILog m_log =
47 LogManager.GetLogger(
48 MethodBase.GetCurrentMethod().DeclaringType);
49
50 private bool m_Enabled = false;
51
52 private IGridService m_LocalGridService;
53
54 public RemoteGridServicesConnector()
55 {
56 }
57
58 public RemoteGridServicesConnector(IConfigSource source)
59 {
60 InitialiseServices(source);
61 }
62
63 #region ISharedRegionmodule
64
65 public Type ReplaceableInterface
66 {
67 get { return null; }
68 }
69
70 public string Name
71 {
72 get { return "RemoteGridServicesConnector"; }
73 }
74
75 public override void Initialise(IConfigSource source)
76 {
77 IConfig moduleConfig = source.Configs["Modules"];
78 if (moduleConfig != null)
79 {
80 string name = moduleConfig.GetString("GridServices", "");
81 if (name == Name)
82 {
83 InitialiseServices(source);
84 m_Enabled = true;
85 m_log.Info("[REMOTE GRID CONNECTOR]: Remote grid enabled");
86 }
87 }
88 }
89
90 private void InitialiseServices(IConfigSource source)
91 {
92 IConfig gridConfig = source.Configs["GridService"];
93 if (gridConfig == null)
94 {
95 m_log.Error("[REMOTE GRID CONNECTOR]: GridService missing from OpenSim.ini");
96 return;
97 }
98
99 base.Initialise(source);
100
101 m_LocalGridService = new LocalGridServicesConnector(source);
102 }
103
104 public void PostInitialise()
105 {
106 }
107
108 public void Close()
109 {
110 }
111
112 public void AddRegion(Scene scene)
113 {
114 if (!m_Enabled)
115 return;
116
117 scene.RegisterModuleInterface<IGridService>(this);
118 }
119
120 public void RemoveRegion(Scene scene)
121 {
122 }
123
124 public void RegionLoaded(Scene scene)
125 {
126 }
127
128 #endregion
129
130 #region IGridService
131
132 public override bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo)
133 {
134 if (m_LocalGridService.RegisterRegion(scopeID, regionInfo))
135 return base.RegisterRegion(scopeID, regionInfo);
136
137 return false;
138 }
139
140 public override bool DeregisterRegion(UUID regionID)
141 {
142 if (m_LocalGridService.DeregisterRegion(regionID))
143 return base.DeregisterRegion(regionID);
144
145 return false;
146 }
147
148 // Let's not override GetNeighbours -- let's get them all from the grid server
149
150 public override SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID)
151 {
152 SimpleRegionInfo rinfo = m_LocalGridService.GetRegionByUUID(scopeID, regionID);
153 if (rinfo == null)
154 rinfo = base.GetRegionByUUID(scopeID, regionID);
155
156 return rinfo;
157 }
158
159 public override SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y)
160 {
161 SimpleRegionInfo rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y);
162 if (rinfo == null)
163 rinfo = base.GetRegionByPosition(scopeID, x, y);
164
165 return rinfo;
166 }
167
168 public override SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName)
169 {
170 SimpleRegionInfo rinfo = m_LocalGridService.GetRegionByName(scopeID, regionName);
171 if (rinfo == null)
172 rinfo = base.GetRegionByName(scopeID, regionName);
173
174 return rinfo;
175 }
176
177 // Let's not override GetRegionsByName -- let's get them all from the grid server
178 // Let's not override GetRegionRange -- let's get them all from the grid server
179
180 #endregion
181 }
182}