diff options
Diffstat (limited to 'OpenSim/Services/GridService')
-rw-r--r-- | OpenSim/Services/GridService/GridService.cs | 286 | ||||
-rw-r--r-- | OpenSim/Services/GridService/HypergridLinker.cs | 641 |
2 files changed, 925 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; | |||
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 | ||
@@ -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 | } |
diff --git a/OpenSim/Services/GridService/HypergridLinker.cs b/OpenSim/Services/GridService/HypergridLinker.cs new file mode 100644 index 0000000..af603b2 --- /dev/null +++ b/OpenSim/Services/GridService/HypergridLinker.cs | |||
@@ -0,0 +1,641 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Net; | ||
31 | using System.Reflection; | ||
32 | using System.Xml; | ||
33 | |||
34 | using Nini.Config; | ||
35 | using log4net; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Framework.Console; | ||
38 | using OpenSim.Data; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Services.Connectors.Hypergrid; | ||
42 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
43 | using OpenMetaverse; | ||
44 | |||
45 | namespace OpenSim.Services.GridService | ||
46 | { | ||
47 | public class HypergridLinker | ||
48 | { | ||
49 | private static readonly ILog m_log = | ||
50 | LogManager.GetLogger( | ||
51 | MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | private static UUID m_HGMapImage = new UUID("00000000-0000-1111-9999-000000000013"); | ||
54 | |||
55 | private static uint m_autoMappingX = 0; | ||
56 | private static uint m_autoMappingY = 0; | ||
57 | private static bool m_enableAutoMapping = false; | ||
58 | |||
59 | protected IRegionData m_Database; | ||
60 | protected GridService m_GridService; | ||
61 | protected IAssetService m_AssetService; | ||
62 | protected GatekeeperServiceConnector m_GatekeeperConnector; | ||
63 | |||
64 | protected UUID m_ScopeID = UUID.Zero; | ||
65 | |||
66 | // Hyperlink regions are hyperlinks on the map | ||
67 | public readonly Dictionary<UUID, GridRegion> m_HyperlinkRegions = new Dictionary<UUID, GridRegion>(); | ||
68 | protected Dictionary<UUID, ulong> m_HyperlinkHandles = new Dictionary<UUID, ulong>(); | ||
69 | |||
70 | protected GridRegion m_DefaultRegion; | ||
71 | protected GridRegion DefaultRegion | ||
72 | { | ||
73 | get | ||
74 | { | ||
75 | if (m_DefaultRegion == null) | ||
76 | { | ||
77 | List<GridRegion> defs = m_GridService.GetDefaultRegions(m_ScopeID); | ||
78 | if (defs != null && defs.Count > 0) | ||
79 | m_DefaultRegion = defs[0]; | ||
80 | else | ||
81 | { | ||
82 | // Get any region | ||
83 | defs = m_GridService.GetRegionsByName(m_ScopeID, "", 1); | ||
84 | if (defs != null && defs.Count > 0) | ||
85 | m_DefaultRegion = defs[0]; | ||
86 | else | ||
87 | { | ||
88 | // This shouldn't happen | ||
89 | m_DefaultRegion = new GridRegion(1000, 1000); | ||
90 | m_log.Error("[HYPERGRID LINKER]: Something is wrong with this grid. It has no regions?"); | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | return m_DefaultRegion; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | public HypergridLinker(IConfigSource config, GridService gridService, IRegionData db) | ||
99 | { | ||
100 | m_log.DebugFormat("[HYPERGRID LINKER]: Starting with db {0}", db.GetType()); | ||
101 | |||
102 | m_Database = db; | ||
103 | m_GridService = gridService; | ||
104 | |||
105 | IConfig gridConfig = config.Configs["GridService"]; | ||
106 | if (gridConfig != null) | ||
107 | { | ||
108 | string assetService = gridConfig.GetString("AssetService", string.Empty); | ||
109 | |||
110 | Object[] args = new Object[] { config }; | ||
111 | |||
112 | if (assetService != string.Empty) | ||
113 | m_AssetService = ServerUtils.LoadPlugin<IAssetService>(assetService, args); | ||
114 | |||
115 | string scope = gridConfig.GetString("ScopeID", string.Empty); | ||
116 | if (scope != string.Empty) | ||
117 | UUID.TryParse(scope, out m_ScopeID); | ||
118 | |||
119 | m_GatekeeperConnector = new GatekeeperServiceConnector(m_AssetService); | ||
120 | |||
121 | m_log.DebugFormat("[HYPERGRID LINKER]: Loaded all services..."); | ||
122 | } | ||
123 | |||
124 | if (MainConsole.Instance != null) | ||
125 | { | ||
126 | MainConsole.Instance.Commands.AddCommand("hypergrid", false, "link-region", | ||
127 | "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>", | ||
128 | "Link a hypergrid region", RunCommand); | ||
129 | MainConsole.Instance.Commands.AddCommand("hypergrid", false, "unlink-region", | ||
130 | "unlink-region <local name> or <HostName>:<HttpPort> <cr>", | ||
131 | "Unlink a hypergrid region", RunCommand); | ||
132 | MainConsole.Instance.Commands.AddCommand("hypergrid", false, "link-mapping", "link-mapping [<x> <y>] <cr>", | ||
133 | "Set local coordinate to map HG regions to", RunCommand); | ||
134 | MainConsole.Instance.Commands.AddCommand("hypergrid", false, "show hyperlinks", "show hyperlinks <cr>", | ||
135 | "List the HG regions", HandleShow); | ||
136 | } | ||
137 | } | ||
138 | |||
139 | |||
140 | #region Link Region | ||
141 | |||
142 | public GridRegion LinkRegion(UUID scopeID, string regionDescriptor) | ||
143 | { | ||
144 | string reason = string.Empty; | ||
145 | int xloc = random.Next(0, Int16.MaxValue) * (int)Constants.RegionSize; | ||
146 | return TryLinkRegionToCoords(scopeID, regionDescriptor, xloc, 0, out reason); | ||
147 | } | ||
148 | |||
149 | private static Random random = new Random(); | ||
150 | |||
151 | // From the command line link-region | ||
152 | public GridRegion TryLinkRegionToCoords(UUID scopeID, string mapName, int xloc, int yloc, out string reason) | ||
153 | { | ||
154 | reason = string.Empty; | ||
155 | string host = "127.0.0.1"; | ||
156 | string portstr; | ||
157 | string regionName = ""; | ||
158 | uint port = 9000; | ||
159 | string[] parts = mapName.Split(new char[] { ':' }); | ||
160 | if (parts.Length >= 1) | ||
161 | { | ||
162 | host = parts[0]; | ||
163 | } | ||
164 | if (parts.Length >= 2) | ||
165 | { | ||
166 | portstr = parts[1]; | ||
167 | //m_log.Debug("-- port = " + portstr); | ||
168 | if (!UInt32.TryParse(portstr, out port)) | ||
169 | regionName = parts[1]; | ||
170 | } | ||
171 | // always take the last one | ||
172 | if (parts.Length >= 3) | ||
173 | { | ||
174 | regionName = parts[2]; | ||
175 | } | ||
176 | |||
177 | // Sanity check. | ||
178 | //IPAddress ipaddr = null; | ||
179 | try | ||
180 | { | ||
181 | //ipaddr = Util.GetHostFromDNS(host); | ||
182 | Util.GetHostFromDNS(host); | ||
183 | } | ||
184 | catch | ||
185 | { | ||
186 | reason = "Malformed hostname"; | ||
187 | return null; | ||
188 | } | ||
189 | |||
190 | GridRegion regInfo; | ||
191 | bool success = TryCreateLink(scopeID, xloc, yloc, regionName, port, host, out regInfo, out reason); | ||
192 | if (success) | ||
193 | { | ||
194 | regInfo.RegionName = mapName; | ||
195 | return regInfo; | ||
196 | } | ||
197 | |||
198 | return null; | ||
199 | } | ||
200 | |||
201 | |||
202 | // From the command line and the 2 above | ||
203 | public bool TryCreateLink(UUID scopeID, int xloc, int yloc, | ||
204 | string externalRegionName, uint externalPort, string externalHostName, out GridRegion regInfo, out string reason) | ||
205 | { | ||
206 | m_log.DebugFormat("[HYPERGRID LINKER]: Link to {0}:{1}:{2}, in {3}-{4}", externalHostName, externalPort, externalRegionName, xloc, yloc); | ||
207 | |||
208 | reason = string.Empty; | ||
209 | regInfo = new GridRegion(); | ||
210 | regInfo.RegionName = externalRegionName; | ||
211 | regInfo.HttpPort = externalPort; | ||
212 | regInfo.ExternalHostName = externalHostName; | ||
213 | regInfo.RegionLocX = xloc; | ||
214 | regInfo.RegionLocY = yloc; | ||
215 | regInfo.ScopeID = scopeID; | ||
216 | |||
217 | try | ||
218 | { | ||
219 | regInfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)0); | ||
220 | } | ||
221 | catch (Exception e) | ||
222 | { | ||
223 | m_log.Warn("[HYPERGRID LINKER]: Wrong format for link-region: " + e.Message); | ||
224 | reason = "Internal error"; | ||
225 | return false; | ||
226 | } | ||
227 | |||
228 | // Finally, link it | ||
229 | ulong handle = 0; | ||
230 | UUID regionID = UUID.Zero; | ||
231 | string externalName = string.Empty; | ||
232 | string imageURL = string.Empty; | ||
233 | if (!m_GatekeeperConnector.LinkRegion(regInfo, out regionID, out handle, out externalName, out imageURL, out reason)) | ||
234 | return false; | ||
235 | |||
236 | if (regionID != UUID.Zero) | ||
237 | { | ||
238 | GridRegion r = m_GridService.GetRegionByUUID(scopeID, regionID); | ||
239 | if (r != null) | ||
240 | { | ||
241 | m_log.DebugFormat("[HYPERGRID LINKER]: Region already exists in coordinates {0} {1}", r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize); | ||
242 | regInfo = r; | ||
243 | return true; | ||
244 | } | ||
245 | |||
246 | regInfo.RegionID = regionID; | ||
247 | Uri uri = null; | ||
248 | try | ||
249 | { | ||
250 | uri = new Uri(externalName); | ||
251 | regInfo.ExternalHostName = uri.Host; | ||
252 | regInfo.HttpPort = (uint)uri.Port; | ||
253 | } | ||
254 | catch | ||
255 | { | ||
256 | m_log.WarnFormat("[HYPERGRID LINKER]: Remote Gatekeeper at {0} provided malformed ExternalName {1}", regInfo.ExternalHostName, externalName); | ||
257 | } | ||
258 | regInfo.RegionName = regInfo.ExternalHostName + ":" + regInfo.HttpPort + ":" + regInfo.RegionName; | ||
259 | // Try get the map image | ||
260 | //regInfo.TerrainImage = m_GatekeeperConnector.GetMapImage(regionID, imageURL); | ||
261 | // I need a texture that works for this... the one I tried doesn't seem to be working | ||
262 | regInfo.TerrainImage = m_HGMapImage; | ||
263 | |||
264 | AddHyperlinkRegion(regInfo, handle); | ||
265 | m_log.Info("[HYPERGRID LINKER]: Successfully linked to region_uuid " + regInfo.RegionID); | ||
266 | |||
267 | } | ||
268 | else | ||
269 | { | ||
270 | m_log.Warn("[HYPERGRID LINKER]: Unable to link region"); | ||
271 | reason = "Remote region could not be found"; | ||
272 | return false; | ||
273 | } | ||
274 | |||
275 | uint x, y; | ||
276 | if (!Check4096(handle, out x, out y)) | ||
277 | { | ||
278 | RemoveHyperlinkRegion(regInfo.RegionID); | ||
279 | reason = "Region is too far (" + x + ", " + y + ")"; | ||
280 | m_log.Info("[HYPERGRID LINKER]: Unable to link, region is too far (" + x + ", " + y + ")"); | ||
281 | return false; | ||
282 | } | ||
283 | |||
284 | m_log.Debug("[HYPERGRID LINKER]: link region succeeded"); | ||
285 | return true; | ||
286 | } | ||
287 | |||
288 | public bool TryUnlinkRegion(string mapName) | ||
289 | { | ||
290 | m_log.DebugFormat("[HYPERGRID LINKER]: Request to unlink {0}", mapName); | ||
291 | GridRegion regInfo = null; | ||
292 | |||
293 | List<RegionData> regions = m_Database.Get(mapName, m_ScopeID); | ||
294 | if (regions != null && regions.Count > 0) | ||
295 | { | ||
296 | OpenSim.Data.RegionFlags rflags = (OpenSim.Data.RegionFlags)Convert.ToInt32(regions[0].Data["flags"]); | ||
297 | if ((rflags & OpenSim.Data.RegionFlags.Hyperlink) != 0) | ||
298 | { | ||
299 | regInfo = new GridRegion(); | ||
300 | regInfo.RegionID = regions[0].RegionID; | ||
301 | regInfo.ScopeID = m_ScopeID; | ||
302 | } | ||
303 | } | ||
304 | |||
305 | //foreach (GridRegion r in m_HyperlinkRegions.Values) | ||
306 | //{ | ||
307 | // m_log.DebugFormat("XXX Comparing {0}:{1} with {2}:{3}", host, port, r.ExternalHostName, r.HttpPort); | ||
308 | // if (host.Equals(r.ExternalHostName) && (port == r.HttpPort)) | ||
309 | // regInfo = r; | ||
310 | //} | ||
311 | |||
312 | if (regInfo != null) | ||
313 | { | ||
314 | RemoveHyperlinkRegion(regInfo.RegionID); | ||
315 | return true; | ||
316 | } | ||
317 | else | ||
318 | { | ||
319 | m_log.InfoFormat("[HYPERGRID LINKER]: Region {0} not found", mapName); | ||
320 | return false; | ||
321 | } | ||
322 | } | ||
323 | |||
324 | /// <summary> | ||
325 | /// Cope with this viewer limitation. | ||
326 | /// </summary> | ||
327 | /// <param name="regInfo"></param> | ||
328 | /// <returns></returns> | ||
329 | public bool Check4096(ulong realHandle, out uint x, out uint y) | ||
330 | { | ||
331 | GridRegion defRegion = DefaultRegion; | ||
332 | |||
333 | uint ux = 0, uy = 0; | ||
334 | Utils.LongToUInts(realHandle, out ux, out uy); | ||
335 | x = ux / Constants.RegionSize; | ||
336 | y = uy / Constants.RegionSize; | ||
337 | |||
338 | if ((Math.Abs((int)defRegion.RegionLocX - ux) >= 4096 * Constants.RegionSize) || | ||
339 | (Math.Abs((int)defRegion.RegionLocY - uy) >= 4096 * Constants.RegionSize)) | ||
340 | { | ||
341 | return false; | ||
342 | } | ||
343 | return true; | ||
344 | } | ||
345 | |||
346 | private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle) | ||
347 | { | ||
348 | //m_HyperlinkRegions[regionInfo.RegionID] = regionInfo; | ||
349 | //m_HyperlinkHandles[regionInfo.RegionID] = regionHandle; | ||
350 | |||
351 | RegionData rdata = m_GridService.RegionInfo2RegionData(regionInfo); | ||
352 | int flags = (int)OpenSim.Data.RegionFlags.Hyperlink + (int)OpenSim.Data.RegionFlags.NoDirectLogin + (int)OpenSim.Data.RegionFlags.RegionOnline; | ||
353 | rdata.Data["flags"] = flags.ToString(); | ||
354 | |||
355 | m_Database.Store(rdata); | ||
356 | |||
357 | } | ||
358 | |||
359 | private void RemoveHyperlinkRegion(UUID regionID) | ||
360 | { | ||
361 | //// Try the hyperlink collection | ||
362 | //if (m_HyperlinkRegions.ContainsKey(regionID)) | ||
363 | //{ | ||
364 | // m_HyperlinkRegions.Remove(regionID); | ||
365 | // m_HyperlinkHandles.Remove(regionID); | ||
366 | //} | ||
367 | m_Database.Delete(regionID); | ||
368 | } | ||
369 | |||
370 | #endregion | ||
371 | |||
372 | |||
373 | #region Console Commands | ||
374 | |||
375 | public void HandleShow(string module, string[] cmd) | ||
376 | { | ||
377 | MainConsole.Instance.Output("Not Implemented Yet"); | ||
378 | //if (cmd.Length != 2) | ||
379 | //{ | ||
380 | // MainConsole.Instance.Output("Syntax: show hyperlinks"); | ||
381 | // return; | ||
382 | //} | ||
383 | //List<GridRegion> regions = new List<GridRegion>(m_HypergridService.m_HyperlinkRegions.Values); | ||
384 | //if (regions == null || regions.Count < 1) | ||
385 | //{ | ||
386 | // MainConsole.Instance.Output("No hyperlinks"); | ||
387 | // return; | ||
388 | //} | ||
389 | |||
390 | //MainConsole.Instance.Output("Region Name Region UUID"); | ||
391 | //MainConsole.Instance.Output("Location URI"); | ||
392 | //MainConsole.Instance.Output("Owner ID "); | ||
393 | //MainConsole.Instance.Output("-------------------------------------------------------------------------------"); | ||
394 | //foreach (GridRegion r in regions) | ||
395 | //{ | ||
396 | // MainConsole.Instance.Output(String.Format("{0,-20} {1}\n{2,-20} {3}\n{4,-39} \n\n", | ||
397 | // r.RegionName, r.RegionID, | ||
398 | // String.Format("{0},{1}", r.RegionLocX, r.RegionLocY), "http://" + r.ExternalHostName + ":" + r.HttpPort.ToString(), | ||
399 | // r.EstateOwner.ToString())); | ||
400 | //} | ||
401 | //return; | ||
402 | } | ||
403 | public void RunCommand(string module, string[] cmdparams) | ||
404 | { | ||
405 | List<string> args = new List<string>(cmdparams); | ||
406 | if (args.Count < 1) | ||
407 | return; | ||
408 | |||
409 | string command = args[0]; | ||
410 | args.RemoveAt(0); | ||
411 | |||
412 | cmdparams = args.ToArray(); | ||
413 | |||
414 | RunHGCommand(command, cmdparams); | ||
415 | |||
416 | } | ||
417 | |||
418 | private void RunHGCommand(string command, string[] cmdparams) | ||
419 | { | ||
420 | if (command.Equals("link-mapping")) | ||
421 | { | ||
422 | if (cmdparams.Length == 2) | ||
423 | { | ||
424 | try | ||
425 | { | ||
426 | m_autoMappingX = Convert.ToUInt32(cmdparams[0]); | ||
427 | m_autoMappingY = Convert.ToUInt32(cmdparams[1]); | ||
428 | m_enableAutoMapping = true; | ||
429 | } | ||
430 | catch (Exception) | ||
431 | { | ||
432 | m_autoMappingX = 0; | ||
433 | m_autoMappingY = 0; | ||
434 | m_enableAutoMapping = false; | ||
435 | } | ||
436 | } | ||
437 | } | ||
438 | else if (command.Equals("link-region")) | ||
439 | { | ||
440 | if (cmdparams.Length < 3) | ||
441 | { | ||
442 | if ((cmdparams.Length == 1) || (cmdparams.Length == 2)) | ||
443 | { | ||
444 | LoadXmlLinkFile(cmdparams); | ||
445 | } | ||
446 | else | ||
447 | { | ||
448 | LinkRegionCmdUsage(); | ||
449 | } | ||
450 | return; | ||
451 | } | ||
452 | |||
453 | if (cmdparams[2].Contains(":")) | ||
454 | { | ||
455 | // New format | ||
456 | int xloc, yloc; | ||
457 | string mapName; | ||
458 | try | ||
459 | { | ||
460 | xloc = Convert.ToInt32(cmdparams[0]); | ||
461 | yloc = Convert.ToInt32(cmdparams[1]); | ||
462 | mapName = cmdparams[2]; | ||
463 | if (cmdparams.Length > 3) | ||
464 | for (int i = 3; i < cmdparams.Length; i++) | ||
465 | mapName += " " + cmdparams[i]; | ||
466 | |||
467 | //m_log.Info(">> MapName: " + mapName); | ||
468 | } | ||
469 | catch (Exception e) | ||
470 | { | ||
471 | MainConsole.Instance.Output("[HGrid] Wrong format for link-region command: " + e.Message); | ||
472 | LinkRegionCmdUsage(); | ||
473 | return; | ||
474 | } | ||
475 | |||
476 | // Convert cell coordinates given by the user to meters | ||
477 | xloc = xloc * (int)Constants.RegionSize; | ||
478 | yloc = yloc * (int)Constants.RegionSize; | ||
479 | string reason = string.Empty; | ||
480 | if (TryLinkRegionToCoords(UUID.Zero, mapName, xloc, yloc, out reason) == null) | ||
481 | MainConsole.Instance.Output("Failed to link region: " + reason); | ||
482 | else | ||
483 | MainConsole.Instance.Output("Hyperlink established"); | ||
484 | } | ||
485 | else | ||
486 | { | ||
487 | // old format | ||
488 | GridRegion regInfo; | ||
489 | int xloc, yloc; | ||
490 | uint externalPort; | ||
491 | string externalHostName; | ||
492 | try | ||
493 | { | ||
494 | xloc = Convert.ToInt32(cmdparams[0]); | ||
495 | yloc = Convert.ToInt32(cmdparams[1]); | ||
496 | externalPort = Convert.ToUInt32(cmdparams[3]); | ||
497 | externalHostName = cmdparams[2]; | ||
498 | //internalPort = Convert.ToUInt32(cmdparams[4]); | ||
499 | //remotingPort = Convert.ToUInt32(cmdparams[5]); | ||
500 | } | ||
501 | catch (Exception e) | ||
502 | { | ||
503 | MainConsole.Instance.Output("[HGrid] Wrong format for link-region command: " + e.Message); | ||
504 | LinkRegionCmdUsage(); | ||
505 | return; | ||
506 | } | ||
507 | |||
508 | // Convert cell coordinates given by the user to meters | ||
509 | xloc = xloc * (int)Constants.RegionSize; | ||
510 | yloc = yloc * (int)Constants.RegionSize; | ||
511 | string reason = string.Empty; | ||
512 | if (TryCreateLink(UUID.Zero, xloc, yloc, "", externalPort, externalHostName, out regInfo, out reason)) | ||
513 | { | ||
514 | if (cmdparams.Length >= 5) | ||
515 | { | ||
516 | regInfo.RegionName = ""; | ||
517 | for (int i = 4; i < cmdparams.Length; i++) | ||
518 | regInfo.RegionName += cmdparams[i] + " "; | ||
519 | } | ||
520 | } | ||
521 | } | ||
522 | return; | ||
523 | } | ||
524 | else if (command.Equals("unlink-region")) | ||
525 | { | ||
526 | if (cmdparams.Length < 1) | ||
527 | { | ||
528 | UnlinkRegionCmdUsage(); | ||
529 | return; | ||
530 | } | ||
531 | if (TryUnlinkRegion(cmdparams[0])) | ||
532 | MainConsole.Instance.Output("Successfully unlinked " + cmdparams[0]); | ||
533 | else | ||
534 | MainConsole.Instance.Output("Unable to unlink " + cmdparams[0] + ", region not found."); | ||
535 | } | ||
536 | } | ||
537 | |||
538 | private void LoadXmlLinkFile(string[] cmdparams) | ||
539 | { | ||
540 | //use http://www.hgurl.com/hypergrid.xml for test | ||
541 | try | ||
542 | { | ||
543 | XmlReader r = XmlReader.Create(cmdparams[0]); | ||
544 | XmlConfigSource cs = new XmlConfigSource(r); | ||
545 | string[] excludeSections = null; | ||
546 | |||
547 | if (cmdparams.Length == 2) | ||
548 | { | ||
549 | if (cmdparams[1].ToLower().StartsWith("excludelist:")) | ||
550 | { | ||
551 | string excludeString = cmdparams[1].ToLower(); | ||
552 | excludeString = excludeString.Remove(0, 12); | ||
553 | char[] splitter = { ';' }; | ||
554 | |||
555 | excludeSections = excludeString.Split(splitter); | ||
556 | } | ||
557 | } | ||
558 | |||
559 | for (int i = 0; i < cs.Configs.Count; i++) | ||
560 | { | ||
561 | bool skip = false; | ||
562 | if ((excludeSections != null) && (excludeSections.Length > 0)) | ||
563 | { | ||
564 | for (int n = 0; n < excludeSections.Length; n++) | ||
565 | { | ||
566 | if (excludeSections[n] == cs.Configs[i].Name.ToLower()) | ||
567 | { | ||
568 | skip = true; | ||
569 | break; | ||
570 | } | ||
571 | } | ||
572 | } | ||
573 | if (!skip) | ||
574 | { | ||
575 | ReadLinkFromConfig(cs.Configs[i]); | ||
576 | } | ||
577 | } | ||
578 | } | ||
579 | catch (Exception e) | ||
580 | { | ||
581 | m_log.Error(e.ToString()); | ||
582 | } | ||
583 | } | ||
584 | |||
585 | |||
586 | private void ReadLinkFromConfig(IConfig config) | ||
587 | { | ||
588 | GridRegion regInfo; | ||
589 | int xloc, yloc; | ||
590 | uint externalPort; | ||
591 | string externalHostName; | ||
592 | uint realXLoc, realYLoc; | ||
593 | |||
594 | xloc = Convert.ToInt32(config.GetString("xloc", "0")); | ||
595 | yloc = Convert.ToInt32(config.GetString("yloc", "0")); | ||
596 | externalPort = Convert.ToUInt32(config.GetString("externalPort", "0")); | ||
597 | externalHostName = config.GetString("externalHostName", ""); | ||
598 | realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0")); | ||
599 | realYLoc = Convert.ToUInt32(config.GetString("real-yloc", "0")); | ||
600 | |||
601 | if (m_enableAutoMapping) | ||
602 | { | ||
603 | xloc = (int)((xloc % 100) + m_autoMappingX); | ||
604 | yloc = (int)((yloc % 100) + m_autoMappingY); | ||
605 | } | ||
606 | |||
607 | if (((realXLoc == 0) && (realYLoc == 0)) || | ||
608 | (((realXLoc - xloc < 3896) || (xloc - realXLoc < 3896)) && | ||
609 | ((realYLoc - yloc < 3896) || (yloc - realYLoc < 3896)))) | ||
610 | { | ||
611 | xloc = xloc * (int)Constants.RegionSize; | ||
612 | yloc = yloc * (int)Constants.RegionSize; | ||
613 | string reason = string.Empty; | ||
614 | if (TryCreateLink(UUID.Zero, xloc, yloc, "", externalPort, | ||
615 | externalHostName, out regInfo, out reason)) | ||
616 | { | ||
617 | regInfo.RegionName = config.GetString("localName", ""); | ||
618 | } | ||
619 | else | ||
620 | MainConsole.Instance.Output("Unable to link " + externalHostName + ": " + reason); | ||
621 | } | ||
622 | } | ||
623 | |||
624 | |||
625 | private void LinkRegionCmdUsage() | ||
626 | { | ||
627 | MainConsole.Instance.Output("Usage: link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>]"); | ||
628 | MainConsole.Instance.Output("Usage: link-region <Xloc> <Yloc> <HostName> <HttpPort> [<LocalName>]"); | ||
629 | MainConsole.Instance.Output("Usage: link-region <URI_of_xml> [<exclude>]"); | ||
630 | } | ||
631 | |||
632 | private void UnlinkRegionCmdUsage() | ||
633 | { | ||
634 | MainConsole.Instance.Output("Usage: unlink-region <HostName>:<HttpPort>"); | ||
635 | MainConsole.Instance.Output("Usage: unlink-region <LocalName>"); | ||
636 | } | ||
637 | |||
638 | #endregion | ||
639 | |||
640 | } | ||
641 | } | ||