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.cs259
1 files changed, 259 insertions, 0 deletions
diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs
index 7749c37..e912705 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,6 +47,11 @@ 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
54 protected IAuthenticationService m_AuthenticationService = null;
49 protected bool m_AllowDuplicateNames = false; 55 protected bool m_AllowDuplicateNames = false;
50 56
51 public GridService(IConfigSource config) 57 public GridService(IConfigSource config)
@@ -53,20 +59,88 @@ namespace OpenSim.Services.GridService
53 { 59 {
54 m_log.DebugFormat("[GRID SERVICE]: Starting..."); 60 m_log.DebugFormat("[GRID SERVICE]: Starting...");
55 61
62 m_config = config;
56 IConfig gridConfig = config.Configs["GridService"]; 63 IConfig gridConfig = config.Configs["GridService"];
57 if (gridConfig != null) 64 if (gridConfig != null)
58 { 65 {
66 m_DeleteOnUnregister = gridConfig.GetBoolean("DeleteOnUnregister", true);
67
68 string authService = gridConfig.GetString("AuthenticationService", String.Empty);
69
70 if (authService != String.Empty)
71 {
72 Object[] args = new Object[] { config };
73 m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authService, args);
74 }
59 m_AllowDuplicateNames = gridConfig.GetBoolean("AllowDuplicateNames", m_AllowDuplicateNames); 75 m_AllowDuplicateNames = gridConfig.GetBoolean("AllowDuplicateNames", m_AllowDuplicateNames);
60 } 76 }
77
78 if (m_RootInstance == null)
79 {
80 m_RootInstance = this;
81
82 MainConsole.Instance.Commands.AddCommand("grid", true,
83 "show region",
84 "show region <Region name>",
85 "Show details on a region",
86 String.Empty,
87 HandleShowRegion);
88
89 MainConsole.Instance.Commands.AddCommand("grid", true,
90 "set region flags",
91 "set region flags <Region name> <flags>",
92 "Set database flags for region",
93 String.Empty,
94 HandleSetFlags);
95 }
61 } 96 }
62 97
63 #region IGridService 98 #region IGridService
64 99
65 public string RegisterRegion(UUID scopeID, GridRegion regionInfos) 100 public string RegisterRegion(UUID scopeID, GridRegion regionInfos)
66 { 101 {
102 IConfig gridConfig = m_config.Configs["GridService"];
67 // This needs better sanity testing. What if regionInfo is registering in 103 // This needs better sanity testing. What if regionInfo is registering in
68 // overlapping coords? 104 // overlapping coords?
69 RegionData region = m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID); 105 RegionData region = m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID);
106 if (region != null)
107 {
108 // There is a preexisting record
109 //
110 // Get it's flags
111 //
112 OpenSim.Data.RegionFlags rflags = (OpenSim.Data.RegionFlags)Convert.ToInt32(region.Data["Flags"]);
113
114 // Is this a reservation?
115 //
116 if ((rflags & OpenSim.Data.RegionFlags.Reservation) != 0)
117 {
118 // Regions reserved for the null key cannot be taken.
119 //
120 if (region.Data["PrincipalID"] == UUID.Zero.ToString())
121 return "Region location us reserved";
122
123 // Treat it as an auth request
124 //
125 // NOTE: Fudging the flags value here, so these flags
126 // should not be used elsewhere. Don't optimize
127 // this with the later retrieval of the same flags!
128 //
129 rflags |= OpenSim.Data.RegionFlags.Authenticate;
130 }
131
132 if ((rflags & OpenSim.Data.RegionFlags.Authenticate) != 0)
133 {
134 // Can we authenticate at all?
135 //
136 if (m_AuthenticationService == null)
137 return "No authentication possible";
138
139 if (!m_AuthenticationService.Verify(new UUID(region.Data["PrincipalID"].ToString()), regionInfos.Token, 30))
140 return "Bad authentication";
141 }
142 }
143
70 if ((region != null) && (region.RegionID != regionInfos.RegionID)) 144 if ((region != null) && (region.RegionID != regionInfos.RegionID))
71 { 145 {
72 m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.", 146 m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.",
@@ -76,6 +150,9 @@ namespace OpenSim.Services.GridService
76 if ((region != null) && (region.RegionID == regionInfos.RegionID) && 150 if ((region != null) && (region.RegionID == regionInfos.RegionID) &&
77 ((region.posX != regionInfos.RegionLocX) || (region.posY != regionInfos.RegionLocY))) 151 ((region.posX != regionInfos.RegionLocX) || (region.posY != regionInfos.RegionLocY)))
78 { 152 {
153 if ((Convert.ToInt32(region.Data["flags"]) & (int)OpenSim.Data.RegionFlags.NoMove) != 0)
154 return "Can't move this region";
155
79 // Region reregistering in other coordinates. Delete the old entry 156 // 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.", 157 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); 158 regionInfos.RegionName, regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY);
@@ -110,8 +187,37 @@ namespace OpenSim.Services.GridService
110 // Everything is ok, let's register 187 // Everything is ok, let's register
111 RegionData rdata = RegionInfo2RegionData(regionInfos); 188 RegionData rdata = RegionInfo2RegionData(regionInfos);
112 rdata.ScopeID = scopeID; 189 rdata.ScopeID = scopeID;
190
191 if (region != null)
192 {
193 int oldFlags = Convert.ToInt32(region.Data["flags"]);
194 if ((oldFlags & (int)OpenSim.Data.RegionFlags.LockedOut) != 0)
195 return "Region locked out";
196
197 oldFlags &= ~(int)OpenSim.Data.RegionFlags.Reservation;
198
199 rdata.Data["flags"] = oldFlags.ToString(); // Preserve flags
200 }
201 else
202 {
203 rdata.Data["flags"] = "0";
204 if ((gridConfig != null) && rdata.RegionName != string.Empty)
205 {
206 int newFlags = 0;
207 string regionName = rdata.RegionName.Trim().Replace(' ', '_');
208 newFlags = ParseFlags(newFlags, gridConfig.GetString("Region_" + regionName, String.Empty));
209 newFlags = ParseFlags(newFlags, gridConfig.GetString("Region_" + rdata.RegionID.ToString(), String.Empty));
210 rdata.Data["flags"] = newFlags.ToString();
211 }
212 }
213
214 int flags = Convert.ToInt32(rdata.Data["flags"]);
215 flags |= (int)OpenSim.Data.RegionFlags.RegionOnline;
216 rdata.Data["flags"] = flags.ToString();
217
113 try 218 try
114 { 219 {
220 rdata.Data["last_seen"] = Util.UnixTimeSinceEpoch();
115 m_Database.Store(rdata); 221 m_Database.Store(rdata);
116 } 222 }
117 catch (Exception e) 223 catch (Exception e)
@@ -128,6 +234,30 @@ namespace OpenSim.Services.GridService
128 public bool DeregisterRegion(UUID regionID) 234 public bool DeregisterRegion(UUID regionID)
129 { 235 {
130 m_log.DebugFormat("[GRID SERVICE]: Region {0} deregistered", regionID); 236 m_log.DebugFormat("[GRID SERVICE]: Region {0} deregistered", regionID);
237 RegionData region = m_Database.Get(regionID, UUID.Zero);
238 if (region == null)
239 return false;
240
241 int flags = Convert.ToInt32(region.Data["flags"]);
242
243 if (!m_DeleteOnUnregister || (flags & (int)OpenSim.Data.RegionFlags.Persistent) != 0)
244 {
245 flags &= ~(int)OpenSim.Data.RegionFlags.RegionOnline;
246 region.Data["flags"] = flags.ToString();
247 region.Data["last_seen"] = Util.UnixTimeSinceEpoch();
248 try
249 {
250 m_Database.Store(region);
251 }
252 catch (Exception e)
253 {
254 m_log.DebugFormat("[GRID SERVICE]: Database exception: {0}", e);
255 }
256
257 return true;
258
259 }
260
131 return m_Database.Delete(regionID); 261 return m_Database.Delete(regionID);
132 } 262 }
133 263
@@ -243,5 +373,134 @@ namespace OpenSim.Services.GridService
243 373
244 #endregion 374 #endregion
245 375
376 public List<GridRegion> GetDefaultRegions(UUID scopeID)
377 {
378 List<GridRegion> ret = new List<GridRegion>();
379
380 List<RegionData> regions = m_Database.GetDefaultRegions(scopeID);
381
382 foreach (RegionData r in regions)
383 {
384 if ((Convert.ToInt32(r.Data["flags"]) & (int)OpenSim.Data.RegionFlags.RegionOnline) != 0)
385 ret.Add(RegionData2RegionInfo(r));
386 }
387
388 return ret;
389 }
390
391 public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y)
392 {
393 List<GridRegion> ret = new List<GridRegion>();
394
395 List<RegionData> regions = m_Database.GetFallbackRegions(scopeID, x, y);
396
397 foreach (RegionData r in regions)
398 {
399 if ((Convert.ToInt32(r.Data["flags"]) & (int)OpenSim.Data.RegionFlags.RegionOnline) != 0)
400 ret.Add(RegionData2RegionInfo(r));
401 }
402
403 return ret;
404 }
405
406 public int GetRegionFlags(UUID scopeID, UUID regionID)
407 {
408 RegionData region = m_Database.Get(regionID, scopeID);
409
410 return Convert.ToInt32(region.Data["flags"]);
411 }
412
413 private void HandleShowRegion(string module, string[] cmd)
414 {
415 if (cmd.Length != 3)
416 {
417 MainConsole.Instance.Output("Syntax: show region <region name>");
418 return;
419 }
420 List<RegionData> regions = m_Database.Get(cmd[2], UUID.Zero);
421 if (regions == null || regions.Count < 1)
422 {
423 MainConsole.Instance.Output("Region not found");
424 return;
425 }
426
427 MainConsole.Instance.Output("Region Name Region UUID");
428 MainConsole.Instance.Output("Location URI");
429 MainConsole.Instance.Output("Owner ID Flags");
430 MainConsole.Instance.Output("-------------------------------------------------------------------------------");
431 foreach (RegionData r in regions)
432 {
433 OpenSim.Data.RegionFlags flags = (OpenSim.Data.RegionFlags)Convert.ToInt32(r.Data["flags"]);
434 MainConsole.Instance.Output(String.Format("{0,-20} {1}\n{2,-20} {3}\n{4,-39} {5}\n\n",
435 r.RegionName, r.RegionID,
436 String.Format("{0},{1}", r.posX, r.posY), "http://" + r.Data["serverIP"].ToString() + ":" + r.Data["serverPort"].ToString(),
437 r.Data["owner_uuid"].ToString(), flags.ToString()));
438 }
439 return;
440 }
441
442 private int ParseFlags(int prev, string flags)
443 {
444 OpenSim.Data.RegionFlags f = (OpenSim.Data.RegionFlags)prev;
445
446 string[] parts = flags.Split(new char[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);
447
448 foreach (string p in parts)
449 {
450 int val;
451
452 try
453 {
454 if (p.StartsWith("+"))
455 {
456 val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p.Substring(1));
457 f |= (OpenSim.Data.RegionFlags)val;
458 }
459 else if (p.StartsWith("-"))
460 {
461 val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p.Substring(1));
462 f &= ~(OpenSim.Data.RegionFlags)val;
463 }
464 else
465 {
466 val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p);
467 f |= (OpenSim.Data.RegionFlags)val;
468 }
469 }
470 catch (Exception e)
471 {
472 MainConsole.Instance.Output("Error in flag specification: " + p);
473 }
474 }
475
476 return (int)f;
477 }
478
479 private void HandleSetFlags(string module, string[] cmd)
480 {
481 if (cmd.Length < 5)
482 {
483 MainConsole.Instance.Output("Syntax: set region flags <region name> <flags>");
484 return;
485 }
486
487 List<RegionData> regions = m_Database.Get(cmd[3], UUID.Zero);
488 if (regions == null || regions.Count < 1)
489 {
490 MainConsole.Instance.Output("Region not found");
491 return;
492 }
493
494 foreach (RegionData r in regions)
495 {
496 int flags = Convert.ToInt32(r.Data["flags"]);
497 flags = ParseFlags(flags, cmd[4]);
498 r.Data["flags"] = flags.ToString();
499 OpenSim.Data.RegionFlags f = (OpenSim.Data.RegionFlags)flags;
500
501 MainConsole.Instance.Output(String.Format("Set region {0} to {1}", r.RegionName, f));
502 m_Database.Store(r);
503 }
504 }
246 } 505 }
247} 506}