aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/GridService/HypergridLinker.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/GridService/HypergridLinker.cs')
-rw-r--r--OpenSim/Services/GridService/HypergridLinker.cs181
1 files changed, 84 insertions, 97 deletions
diff --git a/OpenSim/Services/GridService/HypergridLinker.cs b/OpenSim/Services/GridService/HypergridLinker.cs
index d5d0195..643d0fc 100644
--- a/OpenSim/Services/GridService/HypergridLinker.cs
+++ b/OpenSim/Services/GridService/HypergridLinker.cs
@@ -26,7 +26,9 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections;
29using System.Collections.Generic; 30using System.Collections.Generic;
31using System.IO;
30using System.Linq; 32using System.Linq;
31using System.Net; 33using System.Net;
32using System.Reflection; 34using System.Reflection;
@@ -51,8 +53,6 @@ namespace OpenSim.Services.GridService
51 LogManager.GetLogger( 53 LogManager.GetLogger(
52 MethodBase.GetCurrentMethod().DeclaringType); 54 MethodBase.GetCurrentMethod().DeclaringType);
53 55
54 private static UUID m_HGMapImage = new UUID("00000000-0000-1111-9999-000000000013");
55
56 private static uint m_autoMappingX = 0; 56 private static uint m_autoMappingX = 0;
57 private static uint m_autoMappingY = 0; 57 private static uint m_autoMappingY = 0;
58 private static bool m_enableAutoMapping = false; 58 private static bool m_enableAutoMapping = false;
@@ -64,6 +64,7 @@ namespace OpenSim.Services.GridService
64 64
65 protected UUID m_ScopeID = UUID.Zero; 65 protected UUID m_ScopeID = UUID.Zero;
66 protected bool m_Check4096 = true; 66 protected bool m_Check4096 = true;
67 protected string m_MapTileDirectory = string.Empty;
67 68
68 // Hyperlink regions are hyperlinks on the map 69 // Hyperlink regions are hyperlinks on the map
69 public readonly Dictionary<UUID, GridRegion> m_HyperlinkRegions = new Dictionary<UUID, GridRegion>(); 70 public readonly Dictionary<UUID, GridRegion> m_HyperlinkRegions = new Dictionary<UUID, GridRegion>();
@@ -120,9 +121,24 @@ namespace OpenSim.Services.GridService
120 121
121 m_Check4096 = gridConfig.GetBoolean("Check4096", true); 122 m_Check4096 = gridConfig.GetBoolean("Check4096", true);
122 123
124 m_MapTileDirectory = gridConfig.GetString("MapTileDirectory", string.Empty);
125
123 m_GatekeeperConnector = new GatekeeperServiceConnector(m_AssetService); 126 m_GatekeeperConnector = new GatekeeperServiceConnector(m_AssetService);
124 127
125 m_log.DebugFormat("[HYPERGRID LINKER]: Loaded all services..."); 128 m_log.Debug("[HYPERGRID LINKER]: Loaded all services...");
129 }
130
131 if (!string.IsNullOrEmpty(m_MapTileDirectory))
132 {
133 try
134 {
135 Directory.CreateDirectory(m_MapTileDirectory);
136 }
137 catch (Exception e)
138 {
139 m_log.WarnFormat("[HYPERGRID LINKER]: Could not create map tile storage directory {0}: {1}", m_MapTileDirectory, e);
140 m_MapTileDirectory = string.Empty;
141 }
126 } 142 }
127 143
128 if (MainConsole.Instance != null) 144 if (MainConsole.Instance != null)
@@ -215,7 +231,9 @@ namespace OpenSim.Services.GridService
215 231
216 public bool TryCreateLink(UUID scopeID, int xloc, int yloc, string remoteRegionName, uint externalPort, string externalHostName, string serverURI, UUID ownerID, out GridRegion regInfo, out string reason) 232 public bool TryCreateLink(UUID scopeID, int xloc, int yloc, string remoteRegionName, uint externalPort, string externalHostName, string serverURI, UUID ownerID, out GridRegion regInfo, out string reason)
217 { 233 {
218 m_log.DebugFormat("[HYPERGRID LINKER]: Link to {0}:{1}:{2}, in {3}-{4}", externalHostName, externalPort, remoteRegionName, xloc, yloc); 234 m_log.DebugFormat("[HYPERGRID LINKER]: Link to {0}:{1}, in {2}-{3}",
235 ((serverURI == null) ? (externalHostName + ":" + externalPort) : serverURI),
236 remoteRegionName, xloc / Constants.RegionSize, yloc / Constants.RegionSize);
219 237
220 reason = string.Empty; 238 reason = string.Empty;
221 regInfo = new GridRegion(); 239 regInfo = new GridRegion();
@@ -242,7 +260,9 @@ namespace OpenSim.Services.GridService
242 GridRegion region = m_GridService.GetRegionByPosition(regInfo.ScopeID, regInfo.RegionLocX, regInfo.RegionLocY); 260 GridRegion region = m_GridService.GetRegionByPosition(regInfo.ScopeID, regInfo.RegionLocX, regInfo.RegionLocY);
243 if (region != null) 261 if (region != null)
244 { 262 {
245 m_log.WarnFormat("[HYPERGRID LINKER]: Coordinates {0}-{1} are already occupied by region {2} with uuid {3}", regInfo.RegionLocX, regInfo.RegionLocY, region.RegionName, region.RegionID); 263 m_log.WarnFormat("[HYPERGRID LINKER]: Coordinates {0}-{1} are already occupied by region {2} with uuid {3}",
264 regInfo.RegionLocX / Constants.RegionSize, regInfo.RegionLocY / Constants.RegionSize,
265 region.RegionName, region.RegionID);
246 reason = "Coordinates are already in use"; 266 reason = "Coordinates are already in use";
247 return false; 267 return false;
248 } 268 }
@@ -266,41 +286,22 @@ namespace OpenSim.Services.GridService
266 if (!m_GatekeeperConnector.LinkRegion(regInfo, out regionID, out handle, out externalName, out imageURL, out reason)) 286 if (!m_GatekeeperConnector.LinkRegion(regInfo, out regionID, out handle, out externalName, out imageURL, out reason))
267 return false; 287 return false;
268 288
269 if (regionID != UUID.Zero) 289 if (regionID == UUID.Zero)
270 {
271 region = m_GridService.GetRegionByUUID(scopeID, regionID);
272 if (region != null)
273 {
274 m_log.DebugFormat("[HYPERGRID LINKER]: Region already exists in coordinates {0} {1}", region.RegionLocX / Constants.RegionSize, region.RegionLocY / Constants.RegionSize);
275 regInfo = region;
276 return true;
277 }
278
279 regInfo.RegionID = regionID;
280
281 if ( externalName == string.Empty )
282 regInfo.RegionName = regInfo.ServerURI;
283 else
284 regInfo.RegionName = externalName;
285
286 m_log.Debug("[HYPERGRID LINKER]: naming linked region " + regInfo.RegionName);
287
288 // Try get the map image
289 //regInfo.TerrainImage = m_GatekeeperConnector.GetMapImage(regionID, imageURL);
290 // I need a texture that works for this... the one I tried doesn't seem to be working
291 regInfo.TerrainImage = m_HGMapImage;
292
293 AddHyperlinkRegion(regInfo, handle);
294 m_log.Info("[HYPERGRID LINKER]: Successfully linked to region_uuid " + regInfo.RegionID);
295
296 }
297 else
298 { 290 {
299 m_log.Warn("[HYPERGRID LINKER]: Unable to link region"); 291 m_log.Warn("[HYPERGRID LINKER]: Unable to link region");
300 reason = "Remote region could not be found"; 292 reason = "Remote region could not be found";
301 return false; 293 return false;
302 } 294 }
303 295
296 region = m_GridService.GetRegionByUUID(scopeID, regionID);
297 if (region != null)
298 {
299 m_log.DebugFormat("[HYPERGRID LINKER]: Region already exists in coordinates {0} {1}",
300 region.RegionLocX / Constants.RegionSize, region.RegionLocY / Constants.RegionSize);
301 regInfo = region;
302 return true;
303 }
304
304 uint x, y; 305 uint x, y;
305 if (m_Check4096 && !Check4096(handle, out x, out y)) 306 if (m_Check4096 && !Check4096(handle, out x, out y))
306 { 307 {
@@ -310,7 +311,20 @@ namespace OpenSim.Services.GridService
310 return false; 311 return false;
311 } 312 }
312 313
313 m_log.Debug("[HYPERGRID LINKER]: link region succeeded"); 314 regInfo.RegionID = regionID;
315
316 if ( externalName == string.Empty )
317 regInfo.RegionName = regInfo.ServerURI;
318 else
319 regInfo.RegionName = externalName;
320
321 m_log.Debug("[HYPERGRID LINKER]: naming linked region " + regInfo.RegionName);
322
323 // Get the map image
324 regInfo.TerrainImage = m_GatekeeperConnector.GetMapImage(regionID, imageURL, m_MapTileDirectory);
325
326 AddHyperlinkRegion(regInfo, handle);
327 m_log.Info("[HYPERGRID LINKER]: Successfully linked to region_uuid " + regInfo.RegionID);
314 return true; 328 return true;
315 } 329 }
316 330
@@ -423,15 +437,14 @@ namespace OpenSim.Services.GridService
423 return; 437 return;
424 } 438 }
425 439
426 MainConsole.Instance.Output("Region Name Region UUID"); 440 MainConsole.Instance.Output("Region Name");
427 MainConsole.Instance.Output("Location URI"); 441 MainConsole.Instance.Output("Location Region UUID");
428 MainConsole.Instance.Output("-------------------------------------------------------------------------------"); 442 MainConsole.Instance.Output(new string('-', 72));
429 foreach (RegionData r in regions) 443 foreach (RegionData r in regions)
430 { 444 {
431 MainConsole.Instance.Output(String.Format("{0,-39} {1}\n{2,-39} {3}\n", 445 MainConsole.Instance.Output(String.Format("{0}\n{2,-32} {1}\n",
432 r.RegionName, r.RegionID, 446 r.RegionName, r.RegionID, String.Format("{0},{1} ({2},{3})", r.posX, r.posY,
433 String.Format("{0},{1} ({2},{3})", r.posX, r.posY, r.posX / 256, r.posY / 256), 447 r.posX / Constants.RegionSize, r.posY / Constants.RegionSize)));
434 "http://" + r.Data["serverIP"].ToString() + ":" + r.Data["serverHttpPort"].ToString()));
435 } 448 }
436 return; 449 return;
437 } 450 }
@@ -459,11 +472,14 @@ namespace OpenSim.Services.GridService
459 xloc = Convert.ToInt32(cmdparams[0]) * (int)Constants.RegionSize; 472 xloc = Convert.ToInt32(cmdparams[0]) * (int)Constants.RegionSize;
460 yloc = Convert.ToInt32(cmdparams[1]) * (int)Constants.RegionSize; 473 yloc = Convert.ToInt32(cmdparams[1]) * (int)Constants.RegionSize;
461 serverURI = cmdparams[2]; 474 serverURI = cmdparams[2];
462 if (cmdparams.Length == 4) 475 if (cmdparams.Length > 3)
463 remoteName = cmdparams[3]; 476 remoteName = string.Join(" ", cmdparams, 3, cmdparams.Length - 3);
464 string reason = string.Empty; 477 string reason = string.Empty;
465 GridRegion regInfo; 478 GridRegion regInfo;
466 TryCreateLink(UUID.Zero, xloc, yloc, remoteName, 0, null, serverURI, UUID.Zero, out regInfo, out reason); 479 if (TryCreateLink(UUID.Zero, xloc, yloc, remoteName, 0, null, serverURI, UUID.Zero, out regInfo, out reason))
480 MainConsole.Instance.Output("Hyperlink established");
481 else
482 MainConsole.Instance.Output("Failed to link region: " + reason);
467 } 483 }
468 484
469 private void RunHGCommand(string command, string[] cmdparams) 485 private void RunHGCommand(string command, string[] cmdparams)
@@ -488,18 +504,6 @@ namespace OpenSim.Services.GridService
488 } 504 }
489 else if (command.Equals("link-region")) 505 else if (command.Equals("link-region"))
490 { 506 {
491 if (cmdparams.Length > 0 && cmdparams.Length < 5)
492 {
493 RunLinkRegionCommand(cmdparams);
494 }
495 else
496 {
497 LinkRegionCmdUsage();
498 }
499 return;
500 }
501 else if (command.Equals("link-region"))
502 {
503 if (cmdparams.Length < 3) 507 if (cmdparams.Length < 3)
504 { 508 {
505 if ((cmdparams.Length == 1) || (cmdparams.Length == 2)) 509 if ((cmdparams.Length == 1) || (cmdparams.Length == 2))
@@ -514,40 +518,24 @@ namespace OpenSim.Services.GridService
514 } 518 }
515 519
516 //this should be the prefererred way of setting up hg links now 520 //this should be the prefererred way of setting up hg links now
517 if ( cmdparams[2].StartsWith("http") && ( cmdparams.Length >= 3 && cmdparams.Length <= 5 )) { 521 if (cmdparams[2].StartsWith("http"))
522 {
518 RunLinkRegionCommand(cmdparams); 523 RunLinkRegionCommand(cmdparams);
519 } 524 }
520 else if (cmdparams[2].Contains(":")) 525 else if (cmdparams[2].Contains(":"))
521 { 526 {
522 // New format 527 // New format
523 int xloc, yloc; 528 string[] parts = cmdparams[2].Split(':');
524 string mapName; 529 if (parts.Length > 2)
525 try
526 { 530 {
527 xloc = Convert.ToInt32(cmdparams[0]); 531 // Insert remote region name
528 yloc = Convert.ToInt32(cmdparams[1]); 532 ArrayList parameters = new ArrayList(cmdparams);
529 mapName = cmdparams[2]; 533 parameters.Insert(3, parts[2]);
530 if (cmdparams.Length > 3) 534 cmdparams = (string[])parameters.ToArray(typeof(string));
531 for (int i = 3; i < cmdparams.Length; i++)
532 mapName += " " + cmdparams[i];
533
534 //m_log.Info(">> MapName: " + mapName);
535 }
536 catch (Exception e)
537 {
538 MainConsole.Instance.Output("[HGrid] Wrong format for link-region command: " + e.Message);
539 LinkRegionCmdUsage();
540 return;
541 } 535 }
536 cmdparams[2] = "http://" + parts[0] + ':' + parts[1];
542 537
543 // Convert cell coordinates given by the user to meters 538 RunLinkRegionCommand(cmdparams);
544 xloc = xloc * (int)Constants.RegionSize;
545 yloc = yloc * (int)Constants.RegionSize;
546 string reason = string.Empty;
547 if (TryLinkRegionToCoords(UUID.Zero, mapName, xloc, yloc, out reason) == null)
548 MainConsole.Instance.Output("Failed to link region: " + reason);
549 else
550 MainConsole.Instance.Output("Hyperlink established");
551 } 539 }
552 else 540 else
553 { 541 {
@@ -556,16 +544,12 @@ namespace OpenSim.Services.GridService
556 int xloc, yloc; 544 int xloc, yloc;
557 uint externalPort; 545 uint externalPort;
558 string externalHostName; 546 string externalHostName;
559 string serverURI;
560 try 547 try
561 { 548 {
562 xloc = Convert.ToInt32(cmdparams[0]); 549 xloc = Convert.ToInt32(cmdparams[0]);
563 yloc = Convert.ToInt32(cmdparams[1]); 550 yloc = Convert.ToInt32(cmdparams[1]);
564 externalPort = Convert.ToUInt32(cmdparams[3]); 551 externalPort = Convert.ToUInt32(cmdparams[3]);
565 externalHostName = cmdparams[2]; 552 externalHostName = cmdparams[2];
566 if ( cmdparams.Length == 4 ) {
567
568 }
569 //internalPort = Convert.ToUInt32(cmdparams[4]); 553 //internalPort = Convert.ToUInt32(cmdparams[4]);
570 //remotingPort = Convert.ToUInt32(cmdparams[5]); 554 //remotingPort = Convert.ToUInt32(cmdparams[5]);
571 } 555 }
@@ -582,27 +566,30 @@ namespace OpenSim.Services.GridService
582 string reason = string.Empty; 566 string reason = string.Empty;
583 if (TryCreateLink(UUID.Zero, xloc, yloc, string.Empty, externalPort, externalHostName, UUID.Zero, out regInfo, out reason)) 567 if (TryCreateLink(UUID.Zero, xloc, yloc, string.Empty, externalPort, externalHostName, UUID.Zero, out regInfo, out reason))
584 { 568 {
585 if (cmdparams.Length >= 5) 569 // What is this? The GridRegion instance will be discarded anyway,
586 { 570 // which effectively ignores any local name given with the command.
587 regInfo.RegionName = ""; 571 //if (cmdparams.Length >= 5)
588 for (int i = 4; i < cmdparams.Length; i++) 572 //{
589 regInfo.RegionName += cmdparams[i] + " "; 573 // regInfo.RegionName = "";
590 } 574 // for (int i = 4; i < cmdparams.Length; i++)
575 // regInfo.RegionName += cmdparams[i] + " ";
576 //}
591 } 577 }
592 } 578 }
593 return; 579 return;
594 } 580 }
595 else if (command.Equals("unlink-region")) 581 else if (command.Equals("unlink-region"))
596 { 582 {
597 if (cmdparams.Length < 1 || cmdparams.Length > 1) 583 if (cmdparams.Length < 1)
598 { 584 {
599 UnlinkRegionCmdUsage(); 585 UnlinkRegionCmdUsage();
600 return; 586 return;
601 } 587 }
602 if (TryUnlinkRegion(cmdparams[0])) 588 string region = string.Join(" ", cmdparams);
603 MainConsole.Instance.Output("Successfully unlinked " + cmdparams[0]); 589 if (TryUnlinkRegion(region))
590 MainConsole.Instance.Output("Successfully unlinked " + region);
604 else 591 else
605 MainConsole.Instance.Output("Unable to unlink " + cmdparams[0] + ", region not found."); 592 MainConsole.Instance.Output("Unable to unlink " + region + ", region not found.");
606 } 593 }
607 } 594 }
608 595