diff options
author | Diva Canto | 2009-09-22 20:25:00 -0700 |
---|---|---|
committer | Diva Canto | 2009-09-22 20:25:00 -0700 |
commit | 882d2c9cc399c4c7d1809702104ce94c9c2c7b17 (patch) | |
tree | 7b79cdd31d5ac659586acc4ae15bfd6519b4565e /OpenSim/Region/CoreModules/ServiceConnectorsOut | |
parent | Moved RegionName from RegionInfo to SimpleRegionInfo. (diff) | |
download | opensim-SC_OLD-882d2c9cc399c4c7d1809702104ce94c9c2c7b17.zip opensim-SC_OLD-882d2c9cc399c4c7d1809702104ce94c9c2c7b17.tar.gz opensim-SC_OLD-882d2c9cc399c4c7d1809702104ce94c9c2c7b17.tar.bz2 opensim-SC_OLD-882d2c9cc399c4c7d1809702104ce94c9c2c7b17.tar.xz |
Added hg console commands to the module.
Added the IN connector module for link-region and corresponding handler to be used in the regions only. No service as such is needed.
This will replace the current link-region machinery. Compiles but not tested.
Diffstat (limited to '')
3 files changed, 567 insertions, 5 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs new file mode 100644 index 0000000..eee3a6c --- /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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Xml; | ||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | //using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Console; | ||
37 | using OpenSim.Region.Framework; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Region.Framework.Scenes.Hypergrid; | ||
40 | |||
41 | namespace 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("link-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("link-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("unlink-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 index e3cb05c..7aeb761 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs | |||
@@ -27,14 +27,18 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Net; | ||
30 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Xml; | ||
31 | 33 | ||
32 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
33 | using OpenSim.Region.Framework.Interfaces; | 35 | using OpenSim.Region.Framework.Interfaces; |
34 | using OpenSim.Region.Framework.Scenes; | 36 | using OpenSim.Region.Framework.Scenes; |
37 | using OpenSim.Region.Framework.Scenes.Hypergrid; | ||
35 | using OpenSim.Services.Interfaces; | 38 | using OpenSim.Services.Interfaces; |
36 | using OpenSim.Server.Base; | 39 | using OpenSim.Server.Base; |
37 | using OpenSim.Services.Connectors.Grid; | 40 | using OpenSim.Services.Connectors.Grid; |
41 | using OpenSim.Framework.Console; | ||
38 | 42 | ||
39 | using OpenMetaverse; | 43 | using OpenMetaverse; |
40 | using log4net; | 44 | using log4net; |
@@ -94,7 +98,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
94 | 98 | ||
95 | 99 | ||
96 | InitialiseConnectorModule(source); | 100 | InitialiseConnectorModule(source); |
97 | 101 | ||
98 | m_Enabled = true; | 102 | m_Enabled = true; |
99 | m_log.Info("[HGGRID CONNECTOR]: HG grid enabled"); | 103 | m_log.Info("[HGGRID CONNECTOR]: HG grid enabled"); |
100 | } | 104 | } |
@@ -137,6 +141,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
137 | return; | 141 | return; |
138 | 142 | ||
139 | scene.RegisterModuleInterface<IGridService>(this); | 143 | scene.RegisterModuleInterface<IGridService>(this); |
144 | |||
140 | } | 145 | } |
141 | 146 | ||
142 | public void RemoveRegion(Scene scene) | 147 | public void RemoveRegion(Scene scene) |
@@ -145,11 +150,25 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
145 | 150 | ||
146 | public void RegionLoaded(Scene scene) | 151 | public void RegionLoaded(Scene scene) |
147 | { | 152 | { |
148 | if (m_Enabled && !m_Initialized) | 153 | if (!m_Enabled) |
154 | return; | ||
155 | |||
156 | if (!m_Initialized) | ||
149 | { | 157 | { |
150 | m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService); | 158 | m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService); |
151 | m_Initialized = true; | 159 | m_Initialized = true; |
152 | } | 160 | } |
161 | |||
162 | HGCommands hgCommands = new HGCommands(this, scene); | ||
163 | scene.AddCommand("HG", "link-region", | ||
164 | "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>", | ||
165 | "Link a hypergrid region", hgCommands.RunCommand); | ||
166 | scene.AddCommand("HG", "unlink-region", | ||
167 | "unlink-region <local name> or <HostName>:<HttpPort> <cr>", | ||
168 | "Unlink a hypergrid region", hgCommands.RunCommand); | ||
169 | scene.AddCommand("HG", "link-mapping", "link-mapping [<x> <y>] <cr>", | ||
170 | "Set local coordinate to map HG regions to", hgCommands.RunCommand); | ||
171 | |||
153 | } | 172 | } |
154 | 173 | ||
155 | #endregion | 174 | #endregion |
@@ -305,6 +324,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
305 | 324 | ||
306 | #endregion | 325 | #endregion |
307 | 326 | ||
327 | #region Auxiliary | ||
328 | |||
308 | private void AddHyperlinkRegion(SimpleRegionInfo regionInfo, ulong regionHandle) | 329 | private void AddHyperlinkRegion(SimpleRegionInfo regionInfo, ulong regionHandle) |
309 | { | 330 | { |
310 | m_HyperlinkRegions.Add(regionInfo.RegionID, regionInfo); | 331 | m_HyperlinkRegions.Add(regionInfo.RegionID, regionInfo); |
@@ -334,6 +355,194 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
334 | } | 355 | } |
335 | m_HyperlinkHandles.Remove(regionID); | 356 | m_HyperlinkHandles.Remove(regionID); |
336 | } | 357 | } |
358 | #endregion | ||
359 | |||
360 | #region Hyperlinks | ||
361 | |||
362 | private static Random random = new Random(); | ||
363 | |||
364 | public SimpleRegionInfo TryLinkRegionToCoords(Scene m_scene, IClientAPI client, string mapName, uint xloc, uint yloc) | ||
365 | { | ||
366 | string host = "127.0.0.1"; | ||
367 | string portstr; | ||
368 | string regionName = ""; | ||
369 | uint port = 9000; | ||
370 | string[] parts = mapName.Split(new char[] { ':' }); | ||
371 | if (parts.Length >= 1) | ||
372 | { | ||
373 | host = parts[0]; | ||
374 | } | ||
375 | if (parts.Length >= 2) | ||
376 | { | ||
377 | portstr = parts[1]; | ||
378 | if (!UInt32.TryParse(portstr, out port)) | ||
379 | regionName = parts[1]; | ||
380 | } | ||
381 | // always take the last one | ||
382 | if (parts.Length >= 3) | ||
383 | { | ||
384 | regionName = parts[2]; | ||
385 | } | ||
386 | |||
387 | // Sanity check. Don't ever link to this sim. | ||
388 | IPAddress ipaddr = null; | ||
389 | try | ||
390 | { | ||
391 | ipaddr = Util.GetHostFromDNS(host); | ||
392 | } | ||
393 | catch { } | ||
394 | |||
395 | if ((ipaddr != null) && | ||
396 | !((m_scene.RegionInfo.ExternalEndPoint.Address.Equals(ipaddr)) && (m_scene.RegionInfo.HttpPort == port))) | ||
397 | { | ||
398 | SimpleRegionInfo regInfo; | ||
399 | bool success = TryCreateLink(m_scene, client, xloc, yloc, regionName, port, host, out regInfo); | ||
400 | if (success) | ||
401 | { | ||
402 | regInfo.RegionName = mapName; | ||
403 | return regInfo; | ||
404 | } | ||
405 | } | ||
406 | |||
407 | return null; | ||
408 | } | ||
409 | |||
410 | public SimpleRegionInfo TryLinkRegion(Scene m_scene, IClientAPI client, string mapName) | ||
411 | { | ||
412 | uint xloc = (uint)(random.Next(0, Int16.MaxValue)); | ||
413 | return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0); | ||
414 | } | ||
415 | |||
416 | public bool TryCreateLink(Scene m_scene, IClientAPI client, uint xloc, uint yloc, | ||
417 | string externalRegionName, uint externalPort, string externalHostName, out SimpleRegionInfo regInfo) | ||
418 | { | ||
419 | m_log.DebugFormat("[HGrid]: Link to {0}:{1}, in {2}-{3}", externalHostName, externalPort, xloc, yloc); | ||
420 | |||
421 | regInfo = new SimpleRegionInfo(); | ||
422 | regInfo.RegionName = externalRegionName; | ||
423 | regInfo.HttpPort = externalPort; | ||
424 | regInfo.ExternalHostName = externalHostName; | ||
425 | regInfo.RegionLocX = xloc; | ||
426 | regInfo.RegionLocY = yloc; | ||
427 | |||
428 | try | ||
429 | { | ||
430 | regInfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)0); | ||
431 | } | ||
432 | catch (Exception e) | ||
433 | { | ||
434 | m_log.Warn("[HGrid]: Wrong format for link-region: " + e.Message); | ||
435 | return false; | ||
436 | } | ||
437 | |||
438 | // Finally, link it | ||
439 | try | ||
440 | { | ||
441 | RegisterRegion(UUID.Zero, regInfo); | ||
442 | } | ||
443 | catch (Exception e) | ||
444 | { | ||
445 | m_log.Warn("[HGrid]: Unable to link region: " + e.Message); | ||
446 | return false; | ||
447 | } | ||
448 | |||
449 | uint x, y; | ||
450 | if (!Check4096(m_scene, regInfo, out x, out y)) | ||
451 | { | ||
452 | DeregisterRegion(regInfo.RegionID); | ||
453 | if (client != null) | ||
454 | client.SendAlertMessage("Region is too far (" + x + ", " + y + ")"); | ||
455 | m_log.Info("[HGrid]: Unable to link, region is too far (" + x + ", " + y + ")"); | ||
456 | return false; | ||
457 | } | ||
458 | |||
459 | if (!CheckCoords(m_scene.RegionInfo.RegionLocX, m_scene.RegionInfo.RegionLocY, x, y)) | ||
460 | { | ||
461 | DeregisterRegion(regInfo.RegionID); | ||
462 | if (client != null) | ||
463 | client.SendAlertMessage("Region has incompatible coordinates (" + x + ", " + y + ")"); | ||
464 | m_log.Info("[HGrid]: Unable to link, region has incompatible coordinates (" + x + ", " + y + ")"); | ||
465 | return false; | ||
466 | } | ||
467 | |||
468 | m_log.Debug("[HGrid]: link region succeeded"); | ||
469 | return true; | ||
470 | } | ||
471 | |||
472 | public bool TryUnlinkRegion(Scene m_scene, string mapName) | ||
473 | { | ||
474 | SimpleRegionInfo regInfo = null; | ||
475 | if (mapName.Contains(":")) | ||
476 | { | ||
477 | string host = "127.0.0.1"; | ||
478 | //string portstr; | ||
479 | //string regionName = ""; | ||
480 | uint port = 9000; | ||
481 | string[] parts = mapName.Split(new char[] { ':' }); | ||
482 | if (parts.Length >= 1) | ||
483 | { | ||
484 | host = parts[0]; | ||
485 | } | ||
486 | // if (parts.Length >= 2) | ||
487 | // { | ||
488 | // portstr = parts[1]; | ||
489 | // if (!UInt32.TryParse(portstr, out port)) | ||
490 | // regionName = parts[1]; | ||
491 | // } | ||
492 | // always take the last one | ||
493 | // if (parts.Length >= 3) | ||
494 | // { | ||
495 | // regionName = parts[2]; | ||
496 | // } | ||
497 | foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) | ||
498 | if (host.Equals(r.ExternalHostName) && (port == r.HttpPort)) | ||
499 | regInfo = r; | ||
500 | } | ||
501 | else | ||
502 | { | ||
503 | foreach (SimpleRegionInfo r in m_HyperlinkRegions.Values) | ||
504 | if (r.RegionName.Equals(mapName)) | ||
505 | regInfo = r; | ||
506 | } | ||
507 | if (regInfo != null) | ||
508 | { | ||
509 | return DeregisterRegion(regInfo.RegionID); | ||
510 | } | ||
511 | else | ||
512 | { | ||
513 | m_log.InfoFormat("[HGrid]: Region {0} not found", mapName); | ||
514 | return false; | ||
515 | } | ||
516 | } | ||
517 | |||
518 | /// <summary> | ||
519 | /// Cope with this viewer limitation. | ||
520 | /// </summary> | ||
521 | /// <param name="regInfo"></param> | ||
522 | /// <returns></returns> | ||
523 | public bool Check4096(Scene m_scene, SimpleRegionInfo regInfo, out uint x, out uint y) | ||
524 | { | ||
525 | ulong realHandle = m_HyperlinkHandles[regInfo.RegionID]; | ||
526 | Utils.LongToUInts(realHandle, out x, out y); | ||
527 | x = x / Constants.RegionSize; | ||
528 | y = y / Constants.RegionSize; | ||
529 | |||
530 | if ((Math.Abs((int)m_scene.RegionInfo.RegionLocX - (int)x) >= 4096) || | ||
531 | (Math.Abs((int)m_scene.RegionInfo.RegionLocY - (int)y) >= 4096)) | ||
532 | { | ||
533 | return false; | ||
534 | } | ||
535 | return true; | ||
536 | } | ||
537 | |||
538 | public bool CheckCoords(uint thisx, uint thisy, uint x, uint y) | ||
539 | { | ||
540 | if ((thisx == x) && (thisy == y)) | ||
541 | return false; | ||
542 | return true; | ||
543 | } | ||
544 | |||
545 | #endregion | ||
337 | 546 | ||
338 | } | 547 | } |
339 | } | 548 | } |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs index 22b1015..8526653 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs | |||
@@ -30,6 +30,8 @@ using System; | |||
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using Nini.Config; | 32 | using Nini.Config; |
33 | using OpenMetaverse; | ||
34 | |||
33 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
34 | using OpenSim.Services.Connectors; | 36 | using OpenSim.Services.Connectors; |
35 | using OpenSim.Region.Framework.Interfaces; | 37 | using OpenSim.Region.Framework.Interfaces; |
@@ -47,9 +49,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
47 | 49 | ||
48 | private bool m_Enabled = false; | 50 | private bool m_Enabled = false; |
49 | 51 | ||
52 | private IGridService m_LocalGridService; | ||
53 | |||
50 | public RemoteGridServicesConnector(IConfigSource source) | 54 | public RemoteGridServicesConnector(IConfigSource source) |
51 | { | 55 | { |
52 | InitialiseService(source); | 56 | InitialiseServices(source); |
53 | } | 57 | } |
54 | 58 | ||
55 | #region ISharedRegionmodule | 59 | #region ISharedRegionmodule |
@@ -72,14 +76,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
72 | string name = moduleConfig.GetString("GridServices", ""); | 76 | string name = moduleConfig.GetString("GridServices", ""); |
73 | if (name == Name) | 77 | if (name == Name) |
74 | { | 78 | { |
75 | InitialiseService(source); | 79 | InitialiseServices(source); |
76 | m_Enabled = true; | 80 | m_Enabled = true; |
77 | m_log.Info("[REMOTE GRID CONNECTOR]: Remote grid enabled"); | 81 | m_log.Info("[REMOTE GRID CONNECTOR]: Remote grid enabled"); |
78 | } | 82 | } |
79 | } | 83 | } |
80 | } | 84 | } |
81 | 85 | ||
82 | private void InitialiseService(IConfigSource source) | 86 | private void InitialiseServices(IConfigSource source) |
83 | { | 87 | { |
84 | IConfig gridConfig = source.Configs["GridService"]; | 88 | IConfig gridConfig = source.Configs["GridService"]; |
85 | if (gridConfig == null) | 89 | if (gridConfig == null) |
@@ -89,6 +93,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
89 | } | 93 | } |
90 | 94 | ||
91 | base.Initialise(source); | 95 | base.Initialise(source); |
96 | |||
97 | m_LocalGridService = new LocalGridServicesConnector(source); | ||
92 | } | 98 | } |
93 | 99 | ||
94 | public void PostInitialise() | 100 | public void PostInitialise() |
@@ -116,5 +122,57 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
116 | } | 122 | } |
117 | 123 | ||
118 | #endregion | 124 | #endregion |
125 | |||
126 | #region IGridService | ||
127 | |||
128 | public override bool RegisterRegion(UUID scopeID, SimpleRegionInfo regionInfo) | ||
129 | { | ||
130 | if (m_LocalGridService.RegisterRegion(scopeID, regionInfo)) | ||
131 | return base.RegisterRegion(scopeID, regionInfo); | ||
132 | |||
133 | return false; | ||
134 | } | ||
135 | |||
136 | public override bool DeregisterRegion(UUID regionID) | ||
137 | { | ||
138 | if (m_LocalGridService.DeregisterRegion(regionID)) | ||
139 | return base.DeregisterRegion(regionID); | ||
140 | |||
141 | return false; | ||
142 | } | ||
143 | |||
144 | // Let's not override GetNeighbours -- let's get them all from the grid server | ||
145 | |||
146 | public override SimpleRegionInfo GetRegionByUUID(UUID scopeID, UUID regionID) | ||
147 | { | ||
148 | SimpleRegionInfo rinfo = m_LocalGridService.GetRegionByUUID(scopeID, regionID); | ||
149 | if (rinfo == null) | ||
150 | rinfo = base.GetRegionByUUID(scopeID, regionID); | ||
151 | |||
152 | return rinfo; | ||
153 | } | ||
154 | |||
155 | public override SimpleRegionInfo GetRegionByPosition(UUID scopeID, int x, int y) | ||
156 | { | ||
157 | SimpleRegionInfo rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y); | ||
158 | if (rinfo == null) | ||
159 | rinfo = base.GetRegionByPosition(scopeID, x, y); | ||
160 | |||
161 | return rinfo; | ||
162 | } | ||
163 | |||
164 | public override SimpleRegionInfo GetRegionByName(UUID scopeID, string regionName) | ||
165 | { | ||
166 | SimpleRegionInfo rinfo = m_LocalGridService.GetRegionByName(scopeID, regionName); | ||
167 | if (rinfo == null) | ||
168 | rinfo = base.GetRegionByName(scopeID, regionName); | ||
169 | |||
170 | return rinfo; | ||
171 | } | ||
172 | |||
173 | // Let's not override GetRegionsByName -- let's get them all from the grid server | ||
174 | // Let's not override GetRegionRange -- let's get them all from the grid server | ||
175 | |||
176 | #endregion | ||
119 | } | 177 | } |
120 | } | 178 | } |