aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/GridService/GridService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/GridService/GridService.cs')
-rw-r--r--OpenSim/Services/GridService/GridService.cs264
1 files changed, 230 insertions, 34 deletions
diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs
index 6f610f8..8293c18 100644
--- a/OpenSim/Services/GridService/GridService.cs
+++ b/OpenSim/Services/GridService/GridService.cs
@@ -46,6 +46,7 @@ namespace OpenSim.Services.GridService
46 private static readonly ILog m_log = 46 private static readonly ILog m_log =
47 LogManager.GetLogger( 47 LogManager.GetLogger(
48 MethodBase.GetCurrentMethod().DeclaringType); 48 MethodBase.GetCurrentMethod().DeclaringType);
49 private string LogHeader = "[GRID SERVICE]";
49 50
50 private bool m_DeleteOnUnregister = true; 51 private bool m_DeleteOnUnregister = true;
51 private static GridService m_RootInstance = null; 52 private static GridService m_RootInstance = null;
@@ -56,7 +57,13 @@ namespace OpenSim.Services.GridService
56 protected bool m_AllowDuplicateNames = false; 57 protected bool m_AllowDuplicateNames = false;
57 protected bool m_AllowHypergridMapSearch = false; 58 protected bool m_AllowHypergridMapSearch = false;
58 59
60<<<<<<< HEAD
61 protected bool m_SuppressVarregionOverlapCheckOnRegistration = false;
62
63 private static Dictionary<string,object> m_ExtraFeatures = new Dictionary<string, object>();
64=======
59 private static Dictionary<string, object> m_ExtraFeatures = new Dictionary<string, object>(); 65 private static Dictionary<string, object> m_ExtraFeatures = new Dictionary<string, object>();
66>>>>>>> avn/ubitvar
60 67
61 public GridService(IConfigSource config) 68 public GridService(IConfigSource config)
62 : base(config) 69 : base(config)
@@ -65,6 +72,9 @@ namespace OpenSim.Services.GridService
65 72
66 m_config = config; 73 m_config = config;
67 IConfig gridConfig = config.Configs["GridService"]; 74 IConfig gridConfig = config.Configs["GridService"];
75
76 bool suppressConsoleCommands = false;
77
68 if (gridConfig != null) 78 if (gridConfig != null)
69 { 79 {
70 m_DeleteOnUnregister = gridConfig.GetBoolean("DeleteOnUnregister", true); 80 m_DeleteOnUnregister = gridConfig.GetBoolean("DeleteOnUnregister", true);
@@ -78,13 +88,19 @@ namespace OpenSim.Services.GridService
78 } 88 }
79 m_AllowDuplicateNames = gridConfig.GetBoolean("AllowDuplicateNames", m_AllowDuplicateNames); 89 m_AllowDuplicateNames = gridConfig.GetBoolean("AllowDuplicateNames", m_AllowDuplicateNames);
80 m_AllowHypergridMapSearch = gridConfig.GetBoolean("AllowHypergridMapSearch", m_AllowHypergridMapSearch); 90 m_AllowHypergridMapSearch = gridConfig.GetBoolean("AllowHypergridMapSearch", m_AllowHypergridMapSearch);
91
92 m_SuppressVarregionOverlapCheckOnRegistration = gridConfig.GetBoolean("SuppressVarregionOverlapCheckOnRegistration", m_SuppressVarregionOverlapCheckOnRegistration);
93
94 // This service is also used locally by a simulator running in grid mode. This switches prevents
95 // inappropriate console commands from being registered
96 suppressConsoleCommands = gridConfig.GetBoolean("SuppressConsoleCommands", suppressConsoleCommands);
81 } 97 }
82 98
83 if (m_RootInstance == null) 99 if (m_RootInstance == null)
84 { 100 {
85 m_RootInstance = this; 101 m_RootInstance = this;
86 102
87 if (MainConsole.Instance != null) 103 if (!suppressConsoleCommands && MainConsole.Instance != null)
88 { 104 {
89 MainConsole.Instance.Commands.AddCommand("Regions", true, 105 MainConsole.Instance.Commands.AddCommand("Regions", true,
90 "deregister region id", 106 "deregister region id",
@@ -93,17 +109,12 @@ namespace OpenSim.Services.GridService
93 String.Empty, 109 String.Empty,
94 HandleDeregisterRegion); 110 HandleDeregisterRegion);
95 111
96 // A messy way of stopping this command being added if we are in standalone (since the simulator 112 MainConsole.Instance.Commands.AddCommand("Regions", true,
97 // has an identically named command 113 "show regions",
98 // 114 "show regions",
99 // XXX: We're relying on the OpenSimulator version being registered first, which is not well defined. 115 "Show details on all regions",
100 if (MainConsole.Instance.Commands.Resolve(new string[] { "show", "regions" }).Length == 0) 116 String.Empty,
101 MainConsole.Instance.Commands.AddCommand("Regions", true, 117 HandleShowRegions);
102 "show regions",
103 "show regions",
104 "Show details on all regions",
105 String.Empty,
106 HandleShowRegions);
107 118
108 MainConsole.Instance.Commands.AddCommand("Regions", true, 119 MainConsole.Instance.Commands.AddCommand("Regions", true,
109 "show region name", 120 "show region name",
@@ -119,13 +130,24 @@ namespace OpenSim.Services.GridService
119 "For example, show region at 1000 1000", 130 "For example, show region at 1000 1000",
120 HandleShowRegionAt); 131 HandleShowRegionAt);
121 132
122 MainConsole.Instance.Commands.AddCommand("Regions", true, 133 MainConsole.Instance.Commands.AddCommand("General", true,
123 "set region flags", 134 "show grid size",
124 "set region flags <Region name> <flags>", 135 "show grid size",
125 "Set database flags for region", 136 "Show the current grid size (excluding hyperlink references)",
126 String.Empty, 137 String.Empty,
127 HandleSetFlags); 138 HandleShowGridSize);
139
140 MainConsole.Instance.Commands.AddCommand("Regions", true,
141 "set region flags",
142 "set region flags <Region name> <flags>",
143 "Set database flags for region",
144 String.Empty,
145 HandleSetFlags);
128 } 146 }
147
148 if (!suppressConsoleCommands)
149 SetExtraServiceURLs(config);
150
129 m_HypergridLinker = new HypergridLinker(m_config, this, m_Database); 151 m_HypergridLinker = new HypergridLinker(m_config, this, m_Database);
130 } 152 }
131 } 153 }
@@ -137,9 +159,15 @@ namespace OpenSim.Services.GridService
137 159
138 if (loginConfig == null || gridConfig == null) 160 if (loginConfig == null || gridConfig == null)
139 return; 161 return;
162<<<<<<< HEAD
163
164 string configVal;
165
166=======
140 167
141 string configVal; 168 string configVal;
142 169
170>>>>>>> avn/ubitvar
143 configVal = loginConfig.GetString("SearchURL", string.Empty); 171 configVal = loginConfig.GetString("SearchURL", string.Empty);
144 if (!string.IsNullOrEmpty(configVal)) 172 if (!string.IsNullOrEmpty(configVal))
145 m_ExtraFeatures["search-server-url"] = configVal; 173 m_ExtraFeatures["search-server-url"] = configVal;
@@ -183,14 +211,26 @@ namespace OpenSim.Services.GridService
183 if (regionInfos.RegionID == UUID.Zero) 211 if (regionInfos.RegionID == UUID.Zero)
184 return "Invalid RegionID - cannot be zero UUID"; 212 return "Invalid RegionID - cannot be zero UUID";
185 213
214<<<<<<< HEAD
215 String reason = "Region overlaps another region";
216 RegionData region = FindAnyConflictingRegion(regionInfos, scopeID, out reason);
217 // If there is a conflicting region, if it has the same ID and same coordinates
218 // then it is a region re-registering (permissions and ownership checked later).
219 if ((region != null)
220 && ( (region.coordX != regionInfos.RegionCoordX)
221 || (region.coordY != regionInfos.RegionCoordY)
222 || (region.RegionID != regionInfos.RegionID) )
223 )
224=======
186 // we should not need to check for overlaps 225 // we should not need to check for overlaps
187 226
188 RegionData region = m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID); 227 RegionData region = m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID);
189 if ((region != null) && (region.RegionID != regionInfos.RegionID)) 228 if ((region != null) && (region.RegionID != regionInfos.RegionID))
229>>>>>>> avn/ubitvar
190 { 230 {
191 m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.", 231 // If not same ID and same coordinates, this new region has conflicts and can't be registered.
192 regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID); 232 m_log.WarnFormat("{0} Register region conflict in scope {1}. {2}", LogHeader, scopeID, reason);
193 return "Region overlaps another region"; 233 return reason;
194 } 234 }
195 235
196 if (region != null) 236 if (region != null)
@@ -313,13 +353,121 @@ namespace OpenSim.Services.GridService
313 m_log.DebugFormat("[GRID SERVICE]: Database exception: {0}", e); 353 m_log.DebugFormat("[GRID SERVICE]: Database exception: {0}", e);
314 } 354 }
315 355
316 m_log.DebugFormat("[GRID SERVICE]: Region {0} ({1}) registered successfully at {2}-{3} with flags {4}", 356 m_log.DebugFormat
317 regionInfos.RegionName, regionInfos.RegionID, regionInfos.RegionCoordX, regionInfos.RegionCoordY, 357 ("[GRID SERVICE]: Region {0} ({1}, {2}x{3}) registered at {4},{5} with flags {6}",
358 regionInfos.RegionName, regionInfos.RegionID, regionInfos.RegionSizeX, regionInfos.RegionSizeY,
359 regionInfos.RegionCoordX, regionInfos.RegionCoordY,
318 (OpenSim.Framework.RegionFlags)flags); 360 (OpenSim.Framework.RegionFlags)flags);
319 361
320 return String.Empty; 362 return String.Empty;
321 } 363 }
322 364
365 /// <summary>
366 /// Search the region map for regions conflicting with this region.
367 /// The region to be added is passed and we look for any existing regions that are
368 /// in the requested location, that are large varregions that overlap this region, or
369 /// are previously defined regions that would lie under this new region.
370 /// </summary>
371 /// <param name="regionInfos">Information on region requested to be added to the world map</param>
372 /// <param name="scopeID">Grid id for region</param>
373 /// <param name="reason">The reason the returned region conflicts with passed region</param>
374 /// <returns></returns>
375 private RegionData FindAnyConflictingRegion(GridRegion regionInfos, UUID scopeID, out string reason)
376 {
377 reason = "Reregistration";
378 // First see if there is an existing region right where this region is trying to go
379 // (We keep this result so it can be returned if suppressing errors)
380 RegionData noErrorRegion = m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID);
381 RegionData region = noErrorRegion;
382 if (region != null
383 && region.RegionID == regionInfos.RegionID
384 && region.sizeX == regionInfos.RegionSizeX
385 && region.sizeY == regionInfos.RegionSizeY)
386 {
387 // If this seems to be exactly the same region, return this as it could be
388 // a re-registration (permissions checked by calling routine).
389 m_log.DebugFormat("{0} FindAnyConflictingRegion: re-register of {1}",
390 LogHeader, RegionString(regionInfos));
391 return region;
392 }
393
394 // No region exactly there or we're resizing an existing region.
395 // Fetch regions that could be varregions overlapping requested location.
396 int xmin = regionInfos.RegionLocX - (int)Constants.MaximumRegionSize + 10;
397 int xmax = regionInfos.RegionLocX;
398 int ymin = regionInfos.RegionLocY - (int)Constants.MaximumRegionSize + 10;
399 int ymax = regionInfos.RegionLocY;
400 List<RegionData> rdatas = m_Database.Get(xmin, ymin, xmax, ymax, scopeID);
401 foreach (RegionData rdata in rdatas)
402 {
403 // m_log.DebugFormat("{0} FindAnyConflictingRegion: find existing. Checking {1}", LogHeader, RegionString(rdata) );
404 if ( (rdata.posX + rdata.sizeX > regionInfos.RegionLocX)
405 && (rdata.posY + rdata.sizeY > regionInfos.RegionLocY) )
406 {
407 region = rdata;
408 m_log.WarnFormat("{0} FindAnyConflictingRegion: conflict of {1} by existing varregion {2}",
409 LogHeader, RegionString(regionInfos), RegionString(region));
410 reason = String.Format("Region location is overlapped by existing varregion {0}",
411 RegionString(region));
412
413 if (m_SuppressVarregionOverlapCheckOnRegistration)
414 region = noErrorRegion;
415 return region;
416 }
417 }
418
419 // There isn't a region that overlaps this potential region.
420 // See if this potential region overlaps an existing region.
421 // First, a shortcut of not looking for overlap if new region is legacy region sized
422 // and connot overlap anything.
423 if (regionInfos.RegionSizeX != Constants.RegionSize
424 || regionInfos.RegionSizeY != Constants.RegionSize)
425 {
426 // trim range looked for so we don't pick up neighbor regions just off the edges
427 xmin = regionInfos.RegionLocX;
428 xmax = regionInfos.RegionLocX + regionInfos.RegionSizeX - 10;
429 ymin = regionInfos.RegionLocY;
430 ymax = regionInfos.RegionLocY + regionInfos.RegionSizeY - 10;
431 rdatas = m_Database.Get(xmin, ymin, xmax, ymax, scopeID);
432
433 // If the region is being resized, the found region could be ourself.
434 foreach (RegionData rdata in rdatas)
435 {
436 // m_log.DebugFormat("{0} FindAnyConflictingRegion: see if overlap. Checking {1}", LogHeader, RegionString(rdata) );
437 if (region == null || region.RegionID != regionInfos.RegionID)
438 {
439 region = rdata;
440 m_log.WarnFormat("{0} FindAnyConflictingRegion: conflict of varregion {1} overlaps existing region {2}",
441 LogHeader, RegionString(regionInfos), RegionString(region));
442 reason = String.Format("Region {0} would overlap existing region {1}",
443 RegionString(regionInfos), RegionString(region));
444
445 if (m_SuppressVarregionOverlapCheckOnRegistration)
446 region = noErrorRegion;
447 return region;
448 }
449 }
450 }
451
452 // If we get here, region is either null (nothing found here) or
453 // is the non-conflicting region found at the location being requested.
454 return region;
455 }
456
457 // String describing name and region location of passed region
458 private String RegionString(RegionData reg)
459 {
460 return String.Format("{0}/{1} at <{2},{3}>",
461 reg.RegionName, reg.RegionID, reg.coordX, reg.coordY);
462 }
463
464 // String describing name and region location of passed region
465 private String RegionString(GridRegion reg)
466 {
467 return String.Format("{0}/{1} at <{2},{3}>",
468 reg.RegionName, reg.RegionID, reg.RegionCoordX, reg.RegionCoordY);
469 }
470
323 public bool DeregisterRegion(UUID regionID) 471 public bool DeregisterRegion(UUID regionID)
324 { 472 {
325 RegionData region = m_Database.Get(regionID, UUID.Zero); 473 RegionData region = m_Database.Get(regionID, UUID.Zero);
@@ -360,7 +508,11 @@ namespace OpenSim.Services.GridService
360 if (region != null) 508 if (region != null)
361 { 509 {
362 // Not really? Maybe? 510 // Not really? Maybe?
511<<<<<<< HEAD
512 // The adjacent regions are presumed to be the same size as the current region
513=======
363/* this fails wiht var regions. My_sql db should now handle var regions 514/* this fails wiht var regions. My_sql db should now handle var regions
515>>>>>>> avn/ubitvar
364 List<RegionData> rdatas = m_Database.Get( 516 List<RegionData> rdatas = m_Database.Get(
365 region.posX - region.sizeX - 1, region.posY - region.sizeY - 1, 517 region.posX - region.sizeX - 1, region.posY - region.sizeY - 1,
366 region.posX + region.sizeX + 1, region.posY + region.sizeY + 1, scopeID); 518 region.posX + region.sizeX + 1, region.posY + region.sizeY + 1, scopeID);
@@ -380,7 +532,11 @@ namespace OpenSim.Services.GridService
380 } 532 }
381 } 533 }
382 534
383// m_log.DebugFormat("[GRID SERVICE]: region {0} has {1} neighbours", region.RegionName, rinfos.Count); 535 // string rNames = "";
536 // foreach (GridRegion gr in rinfos)
537 // rNames += gr.RegionName + ",";
538 // m_log.DebugFormat("{0} region {1} has {2} neighbours ({3})",
539 // LogHeader, region.RegionName, rinfos.Count, rNames);
384 } 540 }
385 else 541 else
386 { 542 {
@@ -409,13 +565,24 @@ namespace OpenSim.Services.GridService
409 565
410 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) 566 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
411 { 567 {
412 int snapX = (int)(x / Constants.RegionSize) * (int)Constants.RegionSize; 568 uint regionX = Util.WorldToRegionLoc((uint)x);
413 int snapY = (int)(y / Constants.RegionSize) * (int)Constants.RegionSize; 569 uint regionY = Util.WorldToRegionLoc((uint)y);
570 int snapX = (int)Util.RegionToWorldLoc(regionX);
571 int snapY = (int)Util.RegionToWorldLoc(regionY);
572
414 RegionData rdata = m_Database.Get(snapX, snapY, scopeID); 573 RegionData rdata = m_Database.Get(snapX, snapY, scopeID);
415 if (rdata != null) 574 if (rdata != null)
575 {
576 m_log.DebugFormat("{0} GetRegionByPosition. Found region {1} in database. Pos=<{2},{3}>",
577 LogHeader, rdata.RegionName, regionX, regionY);
416 return RegionData2RegionInfo(rdata); 578 return RegionData2RegionInfo(rdata);
417 579 }
418 return null; 580 else
581 {
582 m_log.DebugFormat("{0} GetRegionByPosition. Did not find region in database. Pos=<{1},{2}>",
583 LogHeader, regionX, regionY);
584 return null;
585 }
419 } 586 }
420 587
421 public GridRegion GetRegionByName(UUID scopeID, string name) 588 public GridRegion GetRegionByName(UUID scopeID, string name)
@@ -668,6 +835,27 @@ namespace OpenSim.Services.GridService
668 OutputRegionsToConsoleSummary(regions); 835 OutputRegionsToConsoleSummary(regions);
669 } 836 }
670 837
838 private void HandleShowGridSize(string module, string[] cmd)
839 {
840 List<RegionData> regions = m_Database.Get(int.MinValue, int.MinValue, int.MaxValue, int.MaxValue, UUID.Zero);
841
842 double size = 0;
843
844 foreach (RegionData region in regions)
845 {
846 int flags = Convert.ToInt32(region.Data["flags"]);
847
848 if ((flags & (int)Framework.RegionFlags.Hyperlink) == 0)
849 size += region.sizeX * region.sizeY;
850 }
851
852 MainConsole.Instance.Output("This is a very rough approximation.");
853 MainConsole.Instance.Output("Although it will not count regions that are actually links to others over the Hypergrid, ");
854 MainConsole.Instance.Output("it will count regions that are inactive but were not deregistered from the grid service");
855 MainConsole.Instance.Output("(e.g. simulator crashed rather than shutting down cleanly).\n");
856
857 MainConsole.Instance.OutputFormat("Grid size: {0} km squared.", size / 1000000);
858 }
671 859
672 private void HandleShowRegion(string module, string[] cmd) 860 private void HandleShowRegion(string module, string[] cmd)
673 { 861 {
@@ -697,20 +885,24 @@ namespace OpenSim.Services.GridService
697 return; 885 return;
698 } 886 }
699 887
700 int x, y; 888 uint x, y;
701 if (!int.TryParse(cmd[3], out x)) 889 if (!uint.TryParse(cmd[3], out x))
702 { 890 {
703 MainConsole.Instance.Output("x-coord must be an integer"); 891 MainConsole.Instance.Output("x-coord must be an integer");
704 return; 892 return;
705 } 893 }
706 894
707 if (!int.TryParse(cmd[4], out y)) 895 if (!uint.TryParse(cmd[4], out y))
708 { 896 {
709 MainConsole.Instance.Output("y-coord must be an integer"); 897 MainConsole.Instance.Output("y-coord must be an integer");
710 return; 898 return;
711 } 899 }
712 900
901<<<<<<< HEAD
902 RegionData region = m_Database.Get((int)Util.RegionToWorldLoc(x), (int)Util.RegionToWorldLoc(y), UUID.Zero);
903=======
713 RegionData region = m_Database.Get((int)Util.RegionToWorldLoc((uint)x), (int)Util.RegionToWorldLoc((uint)y), UUID.Zero); 904 RegionData region = m_Database.Get((int)Util.RegionToWorldLoc((uint)x), (int)Util.RegionToWorldLoc((uint)y), UUID.Zero);
905>>>>>>> avn/ubitvar
714 if (region == null) 906 if (region == null)
715 { 907 {
716 MainConsole.Instance.OutputFormat("No region found at {0},{1}", x, y); 908 MainConsole.Instance.OutputFormat("No region found at {0},{1}", x, y);
@@ -727,7 +919,11 @@ namespace OpenSim.Services.GridService
727 ConsoleDisplayList dispList = new ConsoleDisplayList(); 919 ConsoleDisplayList dispList = new ConsoleDisplayList();
728 dispList.AddRow("Region Name", r.RegionName); 920 dispList.AddRow("Region Name", r.RegionName);
729 dispList.AddRow("Region ID", r.RegionID); 921 dispList.AddRow("Region ID", r.RegionID);
922<<<<<<< HEAD
923 dispList.AddRow("Position", string.Format("{0},{1}", r.coordX, r.coordY));
924=======
730 dispList.AddRow("Location", string.Format("{0},{1}", r.coordX, r.coordY)); 925 dispList.AddRow("Location", string.Format("{0},{1}", r.coordX, r.coordY));
926>>>>>>> avn/ubitvar
731 dispList.AddRow("Size", string.Format("{0}x{1}", r.sizeX, r.sizeY)); 927 dispList.AddRow("Size", string.Format("{0}x{1}", r.sizeX, r.sizeY));
732 dispList.AddRow("URI", r.Data["serverURI"]); 928 dispList.AddRow("URI", r.Data["serverURI"]);
733 dispList.AddRow("Owner ID", r.Data["owner_uuid"]); 929 dispList.AddRow("Owner ID", r.Data["owner_uuid"]);
@@ -745,10 +941,10 @@ namespace OpenSim.Services.GridService
745 private void OutputRegionsToConsoleSummary(List<RegionData> regions) 941 private void OutputRegionsToConsoleSummary(List<RegionData> regions)
746 { 942 {
747 ConsoleDisplayTable dispTable = new ConsoleDisplayTable(); 943 ConsoleDisplayTable dispTable = new ConsoleDisplayTable();
748 dispTable.AddColumn("Name", 16); 944 dispTable.AddColumn("Name", 44);
749 dispTable.AddColumn("ID", 36); 945 dispTable.AddColumn("ID", 36);
750 dispTable.AddColumn("Position", 11); 946 dispTable.AddColumn("Position", 11);
751 dispTable.AddColumn("Owner ID", 36); 947 dispTable.AddColumn("Size", 11);
752 dispTable.AddColumn("Flags", 60); 948 dispTable.AddColumn("Flags", 60);
753 949
754 foreach (RegionData r in regions) 950 foreach (RegionData r in regions)
@@ -758,7 +954,7 @@ namespace OpenSim.Services.GridService
758 r.RegionName, 954 r.RegionName,
759 r.RegionID.ToString(), 955 r.RegionID.ToString(),
760 string.Format("{0},{1}", r.coordX, r.coordY), 956 string.Format("{0},{1}", r.coordX, r.coordY),
761 r.Data["owner_uuid"].ToString(), 957 string.Format("{0}x{1}", r.sizeX, r.sizeY),
762 flags.ToString()); 958 flags.ToString());
763 } 959 }
764 960