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.cs287
1 files changed, 285 insertions, 2 deletions
diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs
index 7749c37..7c98642 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;
@@ -187,6 +324,7 @@ namespace OpenSim.Services.GridService
187 324
188 if (rdatas != null) 325 if (rdatas != null)
189 { 326 {
327 m_log.DebugFormat("[GRID SERVICE]: Found {0} regions", rdatas.Count);
190 foreach (RegionData rdata in rdatas) 328 foreach (RegionData rdata in rdatas)
191 { 329 {
192 if (count++ < maxNumber) 330 if (count++ < maxNumber)
@@ -194,6 +332,13 @@ namespace OpenSim.Services.GridService
194 } 332 }
195 } 333 }
196 334
335 if (m_AllowHypergridMapSearch && (rdatas == null || (rdatas != null && rdatas.Count == 0)) && name.Contains("."))
336 {
337 GridRegion r = m_HypergridLinker.LinkRegion(scopeID, name);
338 if (r != null)
339 rinfos.Add(r);
340 }
341
197 return rinfos; 342 return rinfos;
198 } 343 }
199 344
@@ -216,7 +361,7 @@ namespace OpenSim.Services.GridService
216 361
217 #region Data structure conversions 362 #region Data structure conversions
218 363
219 protected RegionData RegionInfo2RegionData(GridRegion rinfo) 364 public RegionData RegionInfo2RegionData(GridRegion rinfo)
220 { 365 {
221 RegionData rdata = new RegionData(); 366 RegionData rdata = new RegionData();
222 rdata.posX = (int)rinfo.RegionLocX; 367 rdata.posX = (int)rinfo.RegionLocX;
@@ -229,7 +374,7 @@ namespace OpenSim.Services.GridService
229 return rdata; 374 return rdata;
230 } 375 }
231 376
232 protected GridRegion RegionData2RegionInfo(RegionData rdata) 377 public GridRegion RegionData2RegionInfo(RegionData rdata)
233 { 378 {
234 GridRegion rinfo = new GridRegion(rdata.Data); 379 GridRegion rinfo = new GridRegion(rdata.Data);
235 rinfo.RegionLocX = rdata.posX; 380 rinfo.RegionLocX = rdata.posX;
@@ -243,5 +388,143 @@ namespace OpenSim.Services.GridService
243 388
244 #endregion 389 #endregion
245 390
391 public List<GridRegion> GetDefaultRegions(UUID scopeID)
392 {
393 List<GridRegion> ret = new List<GridRegion>();
394
395 List<RegionData> regions = m_Database.GetDefaultRegions(scopeID);
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 m_log.DebugFormat("[GRID SERVICE]: GetDefaultRegions returning {0} regions", ret.Count);
404 return ret;
405 }
406
407 public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y)
408 {
409 List<GridRegion> ret = new List<GridRegion>();
410
411 List<RegionData> regions = m_Database.GetFallbackRegions(scopeID, x, y);
412
413 foreach (RegionData r in regions)
414 {
415 if ((Convert.ToInt32(r.Data["flags"]) & (int)OpenSim.Data.RegionFlags.RegionOnline) != 0)
416 ret.Add(RegionData2RegionInfo(r));
417 }
418
419 m_log.DebugFormat("[GRID SERVICE]: Fallback returned {0} regions", ret.Count);
420 return ret;
421 }
422
423 public int GetRegionFlags(UUID scopeID, UUID regionID)
424 {
425 RegionData region = m_Database.Get(regionID, scopeID);
426
427 if (region != null)
428 {
429 int flags = Convert.ToInt32(region.Data["flags"]);
430 //m_log.DebugFormat("[GRID SERVICE]: Request for flags of {0}: {1}", regionID, flags);
431 return flags;
432 }
433 else
434 return -1;
435 }
436
437 private void HandleShowRegion(string module, string[] cmd)
438 {
439 if (cmd.Length != 3)
440 {
441 MainConsole.Instance.Output("Syntax: show region <region name>");
442 return;
443 }
444 List<RegionData> regions = m_Database.Get(cmd[2], UUID.Zero);
445 if (regions == null || regions.Count < 1)
446 {
447 MainConsole.Instance.Output("Region not found");
448 return;
449 }
450
451 MainConsole.Instance.Output("Region Name Region UUID");
452 MainConsole.Instance.Output("Location URI");
453 MainConsole.Instance.Output("Owner ID Flags");
454 MainConsole.Instance.Output("-------------------------------------------------------------------------------");
455 foreach (RegionData r in regions)
456 {
457 OpenSim.Data.RegionFlags flags = (OpenSim.Data.RegionFlags)Convert.ToInt32(r.Data["flags"]);
458 MainConsole.Instance.Output(String.Format("{0,-20} {1}\n{2,-20} {3}\n{4,-39} {5}\n\n",
459 r.RegionName, r.RegionID,
460 String.Format("{0},{1}", r.posX, r.posY), "http://" + r.Data["serverIP"].ToString() + ":" + r.Data["serverPort"].ToString(),
461 r.Data["owner_uuid"].ToString(), flags.ToString()));
462 }
463 return;
464 }
465
466 private int ParseFlags(int prev, string flags)
467 {
468 OpenSim.Data.RegionFlags f = (OpenSim.Data.RegionFlags)prev;
469
470 string[] parts = flags.Split(new char[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);
471
472 foreach (string p in parts)
473 {
474 int val;
475
476 try
477 {
478 if (p.StartsWith("+"))
479 {
480 val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p.Substring(1));
481 f |= (OpenSim.Data.RegionFlags)val;
482 }
483 else if (p.StartsWith("-"))
484 {
485 val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p.Substring(1));
486 f &= ~(OpenSim.Data.RegionFlags)val;
487 }
488 else
489 {
490 val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p);
491 f |= (OpenSim.Data.RegionFlags)val;
492 }
493 }
494 catch (Exception)
495 {
496 MainConsole.Instance.Output("Error in flag specification: " + p);
497 }
498 }
499
500 return (int)f;
501 }
502
503 private void HandleSetFlags(string module, string[] cmd)
504 {
505 if (cmd.Length < 5)
506 {
507 MainConsole.Instance.Output("Syntax: set region flags <region name> <flags>");
508 return;
509 }
510
511 List<RegionData> regions = m_Database.Get(cmd[3], UUID.Zero);
512 if (regions == null || regions.Count < 1)
513 {
514 MainConsole.Instance.Output("Region not found");
515 return;
516 }
517
518 foreach (RegionData r in regions)
519 {
520 int flags = Convert.ToInt32(r.Data["flags"]);
521 flags = ParseFlags(flags, cmd[4]);
522 r.Data["flags"] = flags.ToString();
523 OpenSim.Data.RegionFlags f = (OpenSim.Data.RegionFlags)flags;
524
525 MainConsole.Instance.Output(String.Format("Set region {0} to {1}", r.RegionName, f));
526 m_Database.Store(r);
527 }
528 }
246 } 529 }
247} 530}