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.cs286
1 files changed, 284 insertions, 2 deletions
diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs
index 7749c37..4089fce 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,46 @@ 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 if ((string)region.Data["PrincipalID"] == UUID.Zero.ToString())
127 return "Region location us reserved";
128
129 // Treat it as an auth request
130 //
131 // NOTE: Fudging the flags value here, so these flags
132 // should not be used elsewhere. Don't optimize
133 // this with the later retrieval of the same flags!
134 rflags |= OpenSim.Data.RegionFlags.Authenticate;
135 }
136
137 if ((rflags & OpenSim.Data.RegionFlags.Authenticate) != 0)
138 {
139 // Can we authenticate at all?
140 //
141 if (m_AuthenticationService == null)
142 return "No authentication possible";
143
144 if (!m_AuthenticationService.Verify(new UUID(region.Data["PrincipalID"].ToString()), regionInfos.Token, 30))
145 return "Bad authentication";
146 }
147 }
148
70 if ((region != null) && (region.RegionID != regionInfos.RegionID)) 149 if ((region != null) && (region.RegionID != regionInfos.RegionID))
71 { 150 {
72 m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.", 151 m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.",
@@ -76,6 +155,9 @@ namespace OpenSim.Services.GridService
76 if ((region != null) && (region.RegionID == regionInfos.RegionID) && 155 if ((region != null) && (region.RegionID == regionInfos.RegionID) &&
77 ((region.posX != regionInfos.RegionLocX) || (region.posY != regionInfos.RegionLocY))) 156 ((region.posX != regionInfos.RegionLocX) || (region.posY != regionInfos.RegionLocY)))
78 { 157 {
158 if ((Convert.ToInt32(region.Data["flags"]) & (int)OpenSim.Data.RegionFlags.NoMove) != 0)
159 return "Can't move this region";
160
79 // Region reregistering in other coordinates. Delete the old entry 161 // 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.", 162 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); 163 regionInfos.RegionName, regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY);
@@ -110,8 +192,37 @@ namespace OpenSim.Services.GridService
110 // Everything is ok, let's register 192 // Everything is ok, let's register
111 RegionData rdata = RegionInfo2RegionData(regionInfos); 193 RegionData rdata = RegionInfo2RegionData(regionInfos);
112 rdata.ScopeID = scopeID; 194 rdata.ScopeID = scopeID;
195
196 if (region != null)
197 {
198 int oldFlags = Convert.ToInt32(region.Data["flags"]);
199 if ((oldFlags & (int)OpenSim.Data.RegionFlags.LockedOut) != 0)
200 return "Region locked out";
201
202 oldFlags &= ~(int)OpenSim.Data.RegionFlags.Reservation;
203
204 rdata.Data["flags"] = oldFlags.ToString(); // Preserve flags
205 }
206 else
207 {
208 rdata.Data["flags"] = "0";
209 if ((gridConfig != null) && rdata.RegionName != string.Empty)
210 {
211 int newFlags = 0;
212 string regionName = rdata.RegionName.Trim().Replace(' ', '_');
213 newFlags = ParseFlags(newFlags, gridConfig.GetString("Region_" + regionName, String.Empty));
214 newFlags = ParseFlags(newFlags, gridConfig.GetString("Region_" + rdata.RegionID.ToString(), String.Empty));
215 rdata.Data["flags"] = newFlags.ToString();
216 }
217 }
218
219 int flags = Convert.ToInt32(rdata.Data["flags"]);
220 flags |= (int)OpenSim.Data.RegionFlags.RegionOnline;
221 rdata.Data["flags"] = flags.ToString();
222
113 try 223 try
114 { 224 {
225 rdata.Data["last_seen"] = Util.UnixTimeSinceEpoch();
115 m_Database.Store(rdata); 226 m_Database.Store(rdata);
116 } 227 }
117 catch (Exception e) 228 catch (Exception e)
@@ -128,6 +239,30 @@ namespace OpenSim.Services.GridService
128 public bool DeregisterRegion(UUID regionID) 239 public bool DeregisterRegion(UUID regionID)
129 { 240 {
130 m_log.DebugFormat("[GRID SERVICE]: Region {0} deregistered", regionID); 241 m_log.DebugFormat("[GRID SERVICE]: Region {0} deregistered", regionID);
242 RegionData region = m_Database.Get(regionID, UUID.Zero);
243 if (region == null)
244 return false;
245
246 int flags = Convert.ToInt32(region.Data["flags"]);
247
248 if (!m_DeleteOnUnregister || (flags & (int)OpenSim.Data.RegionFlags.Persistent) != 0)
249 {
250 flags &= ~(int)OpenSim.Data.RegionFlags.RegionOnline;
251 region.Data["flags"] = flags.ToString();
252 region.Data["last_seen"] = Util.UnixTimeSinceEpoch();
253 try
254 {
255 m_Database.Store(region);
256 }
257 catch (Exception e)
258 {
259 m_log.DebugFormat("[GRID SERVICE]: Database exception: {0}", e);
260 }
261
262 return true;
263
264 }
265
131 return m_Database.Delete(regionID); 266 return m_Database.Delete(regionID);
132 } 267 }
133 268
@@ -180,6 +315,8 @@ namespace OpenSim.Services.GridService
180 315
181 public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber) 316 public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
182 { 317 {
318 m_log.DebugFormat("[GRID SERVICE]: GetRegionsByName {0}", name);
319
183 List<RegionData> rdatas = m_Database.Get("%" + name + "%", scopeID); 320 List<RegionData> rdatas = m_Database.Get("%" + name + "%", scopeID);
184 321
185 int count = 0; 322 int count = 0;
@@ -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,143 @@ 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 m_log.DebugFormat("[GRID SERVICE]: GetDefaultRegions returning {0} regions", ret.Count);
403 return ret;
404 }
405
406 public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y)
407 {
408 List<GridRegion> ret = new List<GridRegion>();
409
410 List<RegionData> regions = m_Database.GetFallbackRegions(scopeID, x, y);
411
412 foreach (RegionData r in regions)
413 {
414 if ((Convert.ToInt32(r.Data["flags"]) & (int)OpenSim.Data.RegionFlags.RegionOnline) != 0)
415 ret.Add(RegionData2RegionInfo(r));
416 }
417
418 m_log.DebugFormat("[GRID SERVICE]: Fallback returned {0} regions", ret.Count);
419 return ret;
420 }
421
422 public int GetRegionFlags(UUID scopeID, UUID regionID)
423 {
424 RegionData region = m_Database.Get(regionID, scopeID);
425
426 if (region != null)
427 {
428 int flags = Convert.ToInt32(region.Data["flags"]);
429 //m_log.DebugFormat("[GRID SERVICE]: Request for flags of {0}: {1}", regionID, flags);
430 return flags;
431 }
432 else
433 return -1;
434 }
435
436 private void HandleShowRegion(string module, string[] cmd)
437 {
438 if (cmd.Length != 3)
439 {
440 MainConsole.Instance.Output("Syntax: show region <region name>");
441 return;
442 }
443 List<RegionData> regions = m_Database.Get(cmd[2], UUID.Zero);
444 if (regions == null || regions.Count < 1)
445 {
446 MainConsole.Instance.Output("Region not found");
447 return;
448 }
449
450 MainConsole.Instance.Output("Region Name Region UUID");
451 MainConsole.Instance.Output("Location URI");
452 MainConsole.Instance.Output("Owner ID Flags");
453 MainConsole.Instance.Output("-------------------------------------------------------------------------------");
454 foreach (RegionData r in regions)
455 {
456 OpenSim.Data.RegionFlags flags = (OpenSim.Data.RegionFlags)Convert.ToInt32(r.Data["flags"]);
457 MainConsole.Instance.Output(String.Format("{0,-20} {1}\n{2,-20} {3}\n{4,-39} {5}\n\n",
458 r.RegionName, r.RegionID,
459 String.Format("{0},{1}", r.posX, r.posY), "http://" + r.Data["serverIP"].ToString() + ":" + r.Data["serverPort"].ToString(),
460 r.Data["owner_uuid"].ToString(), flags.ToString()));
461 }
462 return;
463 }
464
465 private int ParseFlags(int prev, string flags)
466 {
467 OpenSim.Data.RegionFlags f = (OpenSim.Data.RegionFlags)prev;
468
469 string[] parts = flags.Split(new char[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);
470
471 foreach (string p in parts)
472 {
473 int val;
474
475 try
476 {
477 if (p.StartsWith("+"))
478 {
479 val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p.Substring(1));
480 f |= (OpenSim.Data.RegionFlags)val;
481 }
482 else if (p.StartsWith("-"))
483 {
484 val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p.Substring(1));
485 f &= ~(OpenSim.Data.RegionFlags)val;
486 }
487 else
488 {
489 val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p);
490 f |= (OpenSim.Data.RegionFlags)val;
491 }
492 }
493 catch (Exception)
494 {
495 MainConsole.Instance.Output("Error in flag specification: " + p);
496 }
497 }
498
499 return (int)f;
500 }
501
502 private void HandleSetFlags(string module, string[] cmd)
503 {
504 if (cmd.Length < 5)
505 {
506 MainConsole.Instance.Output("Syntax: set region flags <region name> <flags>");
507 return;
508 }
509
510 List<RegionData> regions = m_Database.Get(cmd[3], UUID.Zero);
511 if (regions == null || regions.Count < 1)
512 {
513 MainConsole.Instance.Output("Region not found");
514 return;
515 }
516
517 foreach (RegionData r in regions)
518 {
519 int flags = Convert.ToInt32(r.Data["flags"]);
520 flags = ParseFlags(flags, cmd[4]);
521 r.Data["flags"] = flags.ToString();
522 OpenSim.Data.RegionFlags f = (OpenSim.Data.RegionFlags)flags;
523
524 MainConsole.Instance.Output(String.Format("Set region {0} to {1}", r.RegionName, f));
525 m_Database.Store(r);
526 }
527 }
246 } 528 }
247} 529}