aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/GridService/GridService.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/GridService/GridService.cs285
1 files changed, 283 insertions, 2 deletions
diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs
index 7749c37..1368e46 100644
--- a/OpenSim/Services/GridService/GridService.cs
+++ b/OpenSim/Services/GridService/GridService.cs
@@ -34,6 +34,7 @@ using log4net;
34using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenSim.Framework.Console; 35using OpenSim.Framework.Console;
36using OpenSim.Data; 36using OpenSim.Data;
37using OpenSim.Server.Base;
37using OpenSim.Services.Interfaces; 38using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion; 39using GridRegion = OpenSim.Services.Interfaces.GridRegion;
39using OpenMetaverse; 40using OpenMetaverse;
@@ -46,17 +47,58 @@ namespace OpenSim.Services.GridService
46 LogManager.GetLogger( 47 LogManager.GetLogger(
47 MethodBase.GetCurrentMethod().DeclaringType); 48 MethodBase.GetCurrentMethod().DeclaringType);
48 49
50 private bool m_DeleteOnUnregister = true;
51 private static GridService m_RootInstance = null;
52 protected IConfigSource m_config;
53 protected HypergridLinker m_HypergridLinker;
54
55 protected IAuthenticationService m_AuthenticationService = null;
49 protected bool m_AllowDuplicateNames = false; 56 protected bool m_AllowDuplicateNames = false;
57 protected bool m_AllowHypergridMapSearch = false;
50 58
51 public GridService(IConfigSource config) 59 public GridService(IConfigSource config)
52 : base(config) 60 : base(config)
53 { 61 {
54 m_log.DebugFormat("[GRID SERVICE]: Starting..."); 62 m_log.DebugFormat("[GRID SERVICE]: Starting...");
55 63
64 m_config = config;
56 IConfig gridConfig = config.Configs["GridService"]; 65 IConfig gridConfig = config.Configs["GridService"];
57 if (gridConfig != null) 66 if (gridConfig != null)
58 { 67 {
68 m_DeleteOnUnregister = gridConfig.GetBoolean("DeleteOnUnregister", true);
69
70 string authService = gridConfig.GetString("AuthenticationService", String.Empty);
71
72 if (authService != String.Empty)
73 {
74 Object[] args = new Object[] { config };
75 m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authService, args);
76 }
59 m_AllowDuplicateNames = gridConfig.GetBoolean("AllowDuplicateNames", m_AllowDuplicateNames); 77 m_AllowDuplicateNames = gridConfig.GetBoolean("AllowDuplicateNames", m_AllowDuplicateNames);
78 m_AllowHypergridMapSearch = gridConfig.GetBoolean("AllowHypergridMapSearch", m_AllowHypergridMapSearch);
79 }
80
81 if (m_RootInstance == null)
82 {
83 m_RootInstance = this;
84
85 if (MainConsole.Instance != null)
86 {
87 MainConsole.Instance.Commands.AddCommand("grid", true,
88 "show region",
89 "show region <Region name>",
90 "Show details on a region",
91 String.Empty,
92 HandleShowRegion);
93
94 MainConsole.Instance.Commands.AddCommand("grid", true,
95 "set region flags",
96 "set region flags <Region name> <flags>",
97 "Set database flags for region",
98 String.Empty,
99 HandleSetFlags);
100 }
101 m_HypergridLinker = new HypergridLinker(m_config, this, m_Database);
60 } 102 }
61 } 103 }
62 104
@@ -64,9 +106,48 @@ namespace OpenSim.Services.GridService
64 106
65 public string RegisterRegion(UUID scopeID, GridRegion regionInfos) 107 public string RegisterRegion(UUID scopeID, GridRegion regionInfos)
66 { 108 {
109 IConfig gridConfig = m_config.Configs["GridService"];
67 // This needs better sanity testing. What if regionInfo is registering in 110 // This needs better sanity testing. What if regionInfo is registering in
68 // overlapping coords? 111 // overlapping coords?
69 RegionData region = m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID); 112 RegionData region = m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID);
113 if (region != null)
114 {
115 // There is a preexisting record
116 //
117 // Get it's flags
118 //
119 OpenSim.Data.RegionFlags rflags = (OpenSim.Data.RegionFlags)Convert.ToInt32(region.Data["flags"]);
120
121 // Is this a reservation?
122 //
123 if ((rflags & OpenSim.Data.RegionFlags.Reservation) != 0)
124 {
125 // Regions reserved for the null key cannot be taken.
126 //
127 if (region.Data["PrincipalID"] == UUID.Zero.ToString())
128 return "Region location us reserved";
129
130 // Treat it as an auth request
131 //
132 // NOTE: Fudging the flags value here, so these flags
133 // should not be used elsewhere. Don't optimize
134 // this with the later retrieval of the same flags!
135 //
136 rflags |= OpenSim.Data.RegionFlags.Authenticate;
137 }
138
139 if ((rflags & OpenSim.Data.RegionFlags.Authenticate) != 0)
140 {
141 // Can we authenticate at all?
142 //
143 if (m_AuthenticationService == null)
144 return "No authentication possible";
145
146 if (!m_AuthenticationService.Verify(new UUID(region.Data["PrincipalID"].ToString()), regionInfos.Token, 30))
147 return "Bad authentication";
148 }
149 }
150
70 if ((region != null) && (region.RegionID != regionInfos.RegionID)) 151 if ((region != null) && (region.RegionID != regionInfos.RegionID))
71 { 152 {
72 m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.", 153 m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.",
@@ -76,6 +157,9 @@ namespace OpenSim.Services.GridService
76 if ((region != null) && (region.RegionID == regionInfos.RegionID) && 157 if ((region != null) && (region.RegionID == regionInfos.RegionID) &&
77 ((region.posX != regionInfos.RegionLocX) || (region.posY != regionInfos.RegionLocY))) 158 ((region.posX != regionInfos.RegionLocX) || (region.posY != regionInfos.RegionLocY)))
78 { 159 {
160 if ((Convert.ToInt32(region.Data["flags"]) & (int)OpenSim.Data.RegionFlags.NoMove) != 0)
161 return "Can't move this region";
162
79 // Region reregistering in other coordinates. Delete the old entry 163 // Region reregistering in other coordinates. Delete the old entry
80 m_log.DebugFormat("[GRID SERVICE]: Region {0} ({1}) was previously registered at {2}-{3}. Deleting old entry.", 164 m_log.DebugFormat("[GRID SERVICE]: Region {0} ({1}) was previously registered at {2}-{3}. Deleting old entry.",
81 regionInfos.RegionName, regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY); 165 regionInfos.RegionName, regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY);
@@ -110,8 +194,37 @@ namespace OpenSim.Services.GridService
110 // Everything is ok, let's register 194 // Everything is ok, let's register
111 RegionData rdata = RegionInfo2RegionData(regionInfos); 195 RegionData rdata = RegionInfo2RegionData(regionInfos);
112 rdata.ScopeID = scopeID; 196 rdata.ScopeID = scopeID;
197
198 if (region != null)
199 {
200 int oldFlags = Convert.ToInt32(region.Data["flags"]);
201 if ((oldFlags & (int)OpenSim.Data.RegionFlags.LockedOut) != 0)
202 return "Region locked out";
203
204 oldFlags &= ~(int)OpenSim.Data.RegionFlags.Reservation;
205
206 rdata.Data["flags"] = oldFlags.ToString(); // Preserve flags
207 }
208 else
209 {
210 rdata.Data["flags"] = "0";
211 if ((gridConfig != null) && rdata.RegionName != string.Empty)
212 {
213 int newFlags = 0;
214 string regionName = rdata.RegionName.Trim().Replace(' ', '_');
215 newFlags = ParseFlags(newFlags, gridConfig.GetString("Region_" + regionName, String.Empty));
216 newFlags = ParseFlags(newFlags, gridConfig.GetString("Region_" + rdata.RegionID.ToString(), String.Empty));
217 rdata.Data["flags"] = newFlags.ToString();
218 }
219 }
220
221 int flags = Convert.ToInt32(rdata.Data["flags"]);
222 flags |= (int)OpenSim.Data.RegionFlags.RegionOnline;
223 rdata.Data["flags"] = flags.ToString();
224
113 try 225 try
114 { 226 {
227 rdata.Data["last_seen"] = Util.UnixTimeSinceEpoch();
115 m_Database.Store(rdata); 228 m_Database.Store(rdata);
116 } 229 }
117 catch (Exception e) 230 catch (Exception e)
@@ -128,6 +241,30 @@ namespace OpenSim.Services.GridService
128 public bool DeregisterRegion(UUID regionID) 241 public bool DeregisterRegion(UUID regionID)
129 { 242 {
130 m_log.DebugFormat("[GRID SERVICE]: Region {0} deregistered", regionID); 243 m_log.DebugFormat("[GRID SERVICE]: Region {0} deregistered", regionID);
244 RegionData region = m_Database.Get(regionID, UUID.Zero);
245 if (region == null)
246 return false;
247
248 int flags = Convert.ToInt32(region.Data["flags"]);
249
250 if (!m_DeleteOnUnregister || (flags & (int)OpenSim.Data.RegionFlags.Persistent) != 0)
251 {
252 flags &= ~(int)OpenSim.Data.RegionFlags.RegionOnline;
253 region.Data["flags"] = flags.ToString();
254 region.Data["last_seen"] = Util.UnixTimeSinceEpoch();
255 try
256 {
257 m_Database.Store(region);
258 }
259 catch (Exception e)
260 {
261 m_log.DebugFormat("[GRID SERVICE]: Database exception: {0}", e);
262 }
263
264 return true;
265
266 }
267
131 return m_Database.Delete(regionID); 268 return m_Database.Delete(regionID);
132 } 269 }
133 270
@@ -194,6 +331,13 @@ namespace OpenSim.Services.GridService
194 } 331 }
195 } 332 }
196 333
334 if (m_AllowHypergridMapSearch && rdatas == null || (rdatas != null && rdatas.Count == 0) && name.Contains("."))
335 {
336 GridRegion r = m_HypergridLinker.LinkRegion(scopeID, name);
337 if (r != null)
338 rinfos.Add(r);
339 }
340
197 return rinfos; 341 return rinfos;
198 } 342 }
199 343
@@ -216,7 +360,7 @@ namespace OpenSim.Services.GridService
216 360
217 #region Data structure conversions 361 #region Data structure conversions
218 362
219 protected RegionData RegionInfo2RegionData(GridRegion rinfo) 363 public RegionData RegionInfo2RegionData(GridRegion rinfo)
220 { 364 {
221 RegionData rdata = new RegionData(); 365 RegionData rdata = new RegionData();
222 rdata.posX = (int)rinfo.RegionLocX; 366 rdata.posX = (int)rinfo.RegionLocX;
@@ -229,7 +373,7 @@ namespace OpenSim.Services.GridService
229 return rdata; 373 return rdata;
230 } 374 }
231 375
232 protected GridRegion RegionData2RegionInfo(RegionData rdata) 376 public GridRegion RegionData2RegionInfo(RegionData rdata)
233 { 377 {
234 GridRegion rinfo = new GridRegion(rdata.Data); 378 GridRegion rinfo = new GridRegion(rdata.Data);
235 rinfo.RegionLocX = rdata.posX; 379 rinfo.RegionLocX = rdata.posX;
@@ -243,5 +387,142 @@ namespace OpenSim.Services.GridService
243 387
244 #endregion 388 #endregion
245 389
390 public List<GridRegion> GetDefaultRegions(UUID scopeID)
391 {
392 List<GridRegion> ret = new List<GridRegion>();
393
394 List<RegionData> regions = m_Database.GetDefaultRegions(scopeID);
395
396 foreach (RegionData r in regions)
397 {
398 if ((Convert.ToInt32(r.Data["flags"]) & (int)OpenSim.Data.RegionFlags.RegionOnline) != 0)
399 ret.Add(RegionData2RegionInfo(r));
400 }
401
402 return ret;
403 }
404
405 public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y)
406 {
407 List<GridRegion> ret = new List<GridRegion>();
408
409 List<RegionData> regions = m_Database.GetFallbackRegions(scopeID, x, y);
410
411 foreach (RegionData r in regions)
412 {
413 if ((Convert.ToInt32(r.Data["flags"]) & (int)OpenSim.Data.RegionFlags.RegionOnline) != 0)
414 ret.Add(RegionData2RegionInfo(r));
415 }
416
417 m_log.DebugFormat("[GRID SERVICE]: Fallback returned {0} regions", ret.Count);
418 return ret;
419 }
420
421 public int GetRegionFlags(UUID scopeID, UUID regionID)
422 {
423 RegionData region = m_Database.Get(regionID, scopeID);
424
425 if (region != null)
426 {
427 int flags = Convert.ToInt32(region.Data["flags"]);
428 //m_log.DebugFormat("[GRID SERVICE]: Request for flags of {0}: {1}", regionID, flags);
429 return flags;
430 }
431 else
432 return -1;
433 }
434
435 private void HandleShowRegion(string module, string[] cmd)
436 {
437 if (cmd.Length != 3)
438 {
439 MainConsole.Instance.Output("Syntax: show region <region name>");
440 return;
441 }
442 List<RegionData> regions = m_Database.Get(cmd[2], UUID.Zero);
443 if (regions == null || regions.Count < 1)
444 {
445 MainConsole.Instance.Output("Region not found");
446 return;
447 }
448
449 MainConsole.Instance.Output("Region Name Region UUID");
450 MainConsole.Instance.Output("Location URI");
451 MainConsole.Instance.Output("Owner ID Flags");
452 MainConsole.Instance.Output("-------------------------------------------------------------------------------");
453 foreach (RegionData r in regions)
454 {
455 OpenSim.Data.RegionFlags flags = (OpenSim.Data.RegionFlags)Convert.ToInt32(r.Data["flags"]);
456 MainConsole.Instance.Output(String.Format("{0,-20} {1}\n{2,-20} {3}\n{4,-39} {5}\n\n",
457 r.RegionName, r.RegionID,
458 String.Format("{0},{1}", r.posX, r.posY), "http://" + r.Data["serverIP"].ToString() + ":" + r.Data["serverPort"].ToString(),
459 r.Data["owner_uuid"].ToString(), flags.ToString()));
460 }
461 return;
462 }
463
464 private int ParseFlags(int prev, string flags)
465 {
466 OpenSim.Data.RegionFlags f = (OpenSim.Data.RegionFlags)prev;
467
468 string[] parts = flags.Split(new char[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);
469
470 foreach (string p in parts)
471 {
472 int val;
473
474 try
475 {
476 if (p.StartsWith("+"))
477 {
478 val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p.Substring(1));
479 f |= (OpenSim.Data.RegionFlags)val;
480 }
481 else if (p.StartsWith("-"))
482 {
483 val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p.Substring(1));
484 f &= ~(OpenSim.Data.RegionFlags)val;
485 }
486 else
487 {
488 val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p);
489 f |= (OpenSim.Data.RegionFlags)val;
490 }
491 }
492 catch (Exception e)
493 {
494 MainConsole.Instance.Output("Error in flag specification: " + p);
495 }
496 }
497
498 return (int)f;
499 }
500
501 private void HandleSetFlags(string module, string[] cmd)
502 {
503 if (cmd.Length < 5)
504 {
505 MainConsole.Instance.Output("Syntax: set region flags <region name> <flags>");
506 return;
507 }
508
509 List<RegionData> regions = m_Database.Get(cmd[3], UUID.Zero);
510 if (regions == null || regions.Count < 1)
511 {
512 MainConsole.Instance.Output("Region not found");
513 return;
514 }
515
516 foreach (RegionData r in regions)
517 {
518 int flags = Convert.ToInt32(r.Data["flags"]);
519 flags = ParseFlags(flags, cmd[4]);
520 r.Data["flags"] = flags.ToString();
521 OpenSim.Data.RegionFlags f = (OpenSim.Data.RegionFlags)flags;
522
523 MainConsole.Instance.Output(String.Format("Set region {0} to {1}", r.RegionName, f));
524 m_Database.Store(r);
525 }
526 }
246 } 527 }
247} 528}