diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs | 213 |
1 files changed, 211 insertions, 2 deletions
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 | } |