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