1
0

HypergridLinker.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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. using System;
  28. using System.Collections.Generic;
  29. using System.Net;
  30. using System.Reflection;
  31. using System.Xml;
  32. using Nini.Config;
  33. using log4net;
  34. using OpenSim.Framework;
  35. using OpenSim.Framework.Console;
  36. using OpenSim.Data;
  37. using OpenSim.Server.Base;
  38. using OpenSim.Services.Interfaces;
  39. using OpenSim.Services.Connectors.Hypergrid;
  40. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  41. using OpenMetaverse;
  42. namespace OpenSim.Services.GridService
  43. {
  44. public class HypergridLinker
  45. {
  46. private static readonly ILog m_log =
  47. LogManager.GetLogger(
  48. MethodBase.GetCurrentMethod().DeclaringType);
  49. private static UUID m_HGMapImage = new UUID("00000000-0000-1111-9999-000000000013");
  50. private static uint m_autoMappingX = 0;
  51. private static uint m_autoMappingY = 0;
  52. private static bool m_enableAutoMapping = false;
  53. protected IRegionData m_Database;
  54. protected GridService m_GridService;
  55. protected IAssetService m_AssetService;
  56. protected GatekeeperServiceConnector m_GatekeeperConnector;
  57. protected UUID m_ScopeID = UUID.Zero;
  58. protected bool m_Check4096 = true;
  59. // Hyperlink regions are hyperlinks on the map
  60. public readonly Dictionary<UUID, GridRegion> m_HyperlinkRegions = new Dictionary<UUID, GridRegion>();
  61. protected Dictionary<UUID, ulong> m_HyperlinkHandles = new Dictionary<UUID, ulong>();
  62. protected GridRegion m_DefaultRegion;
  63. protected GridRegion DefaultRegion
  64. {
  65. get
  66. {
  67. if (m_DefaultRegion == null)
  68. {
  69. List<GridRegion> defs = m_GridService.GetDefaultRegions(m_ScopeID);
  70. if (defs != null && defs.Count > 0)
  71. m_DefaultRegion = defs[0];
  72. else
  73. {
  74. // Get any region
  75. defs = m_GridService.GetRegionsByName(m_ScopeID, "", 1);
  76. if (defs != null && defs.Count > 0)
  77. m_DefaultRegion = defs[0];
  78. else
  79. {
  80. // This shouldn't happen
  81. m_DefaultRegion = new GridRegion(1000, 1000);
  82. m_log.Error("[HYPERGRID LINKER]: Something is wrong with this grid. It has no regions?");
  83. }
  84. }
  85. }
  86. return m_DefaultRegion;
  87. }
  88. }
  89. public HypergridLinker(IConfigSource config, GridService gridService, IRegionData db)
  90. {
  91. m_log.DebugFormat("[HYPERGRID LINKER]: Starting with db {0}", db.GetType());
  92. m_Database = db;
  93. m_GridService = gridService;
  94. IConfig gridConfig = config.Configs["GridService"];
  95. if (gridConfig != null)
  96. {
  97. string assetService = gridConfig.GetString("AssetService", string.Empty);
  98. Object[] args = new Object[] { config };
  99. if (assetService != string.Empty)
  100. m_AssetService = ServerUtils.LoadPlugin<IAssetService>(assetService, args);
  101. string scope = gridConfig.GetString("ScopeID", string.Empty);
  102. if (scope != string.Empty)
  103. UUID.TryParse(scope, out m_ScopeID);
  104. m_Check4096 = gridConfig.GetBoolean("Check4096", true);
  105. m_GatekeeperConnector = new GatekeeperServiceConnector(m_AssetService);
  106. m_log.DebugFormat("[HYPERGRID LINKER]: Loaded all services...");
  107. }
  108. if (MainConsole.Instance != null)
  109. {
  110. MainConsole.Instance.Commands.AddCommand("hypergrid", false, "link-region",
  111. "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>",
  112. "Link a hypergrid region", RunCommand);
  113. MainConsole.Instance.Commands.AddCommand("hypergrid", false, "unlink-region",
  114. "unlink-region <local name> or <HostName>:<HttpPort> <cr>",
  115. "Unlink a hypergrid region", RunCommand);
  116. MainConsole.Instance.Commands.AddCommand("hypergrid", false, "link-mapping", "link-mapping [<x> <y>] <cr>",
  117. "Set local coordinate to map HG regions to", RunCommand);
  118. MainConsole.Instance.Commands.AddCommand("hypergrid", false, "show hyperlinks", "show hyperlinks <cr>",
  119. "List the HG regions", HandleShow);
  120. }
  121. }
  122. #region Link Region
  123. public GridRegion LinkRegion(UUID scopeID, string regionDescriptor)
  124. {
  125. string reason = string.Empty;
  126. int xloc = random.Next(0, Int16.MaxValue) * (int)Constants.RegionSize;
  127. return TryLinkRegionToCoords(scopeID, regionDescriptor, xloc, 0, out reason);
  128. }
  129. private static Random random = new Random();
  130. // From the command line link-region
  131. public GridRegion TryLinkRegionToCoords(UUID scopeID, string mapName, int xloc, int yloc, out string reason)
  132. {
  133. reason = string.Empty;
  134. string host = "127.0.0.1";
  135. string portstr;
  136. string regionName = "";
  137. uint port = 9000;
  138. string[] parts = mapName.Split(new char[] { ':' });
  139. if (parts.Length >= 1)
  140. {
  141. host = parts[0];
  142. }
  143. if (parts.Length >= 2)
  144. {
  145. portstr = parts[1];
  146. //m_log.Debug("-- port = " + portstr);
  147. if (!UInt32.TryParse(portstr, out port))
  148. regionName = parts[1];
  149. }
  150. // always take the last one
  151. if (parts.Length >= 3)
  152. {
  153. regionName = parts[2];
  154. }
  155. // Sanity check.
  156. //IPAddress ipaddr = null;
  157. try
  158. {
  159. //ipaddr = Util.GetHostFromDNS(host);
  160. Util.GetHostFromDNS(host);
  161. }
  162. catch
  163. {
  164. reason = "Malformed hostname";
  165. return null;
  166. }
  167. GridRegion regInfo;
  168. bool success = TryCreateLink(scopeID, xloc, yloc, regionName, port, host, out regInfo, out reason);
  169. if (success)
  170. {
  171. regInfo.RegionName = mapName;
  172. return regInfo;
  173. }
  174. return null;
  175. }
  176. // From the command line and the 2 above
  177. public bool TryCreateLink(UUID scopeID, int xloc, int yloc,
  178. string externalRegionName, uint externalPort, string externalHostName, out GridRegion regInfo, out string reason)
  179. {
  180. m_log.DebugFormat("[HYPERGRID LINKER]: Link to {0}:{1}:{2}, in {3}-{4}", externalHostName, externalPort, externalRegionName, xloc, yloc);
  181. reason = string.Empty;
  182. regInfo = new GridRegion();
  183. regInfo.RegionName = externalRegionName;
  184. regInfo.HttpPort = externalPort;
  185. regInfo.ExternalHostName = externalHostName;
  186. regInfo.RegionLocX = xloc;
  187. regInfo.RegionLocY = yloc;
  188. regInfo.ScopeID = scopeID;
  189. try
  190. {
  191. regInfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)0);
  192. }
  193. catch (Exception e)
  194. {
  195. m_log.Warn("[HYPERGRID LINKER]: Wrong format for link-region: " + e.Message);
  196. reason = "Internal error";
  197. return false;
  198. }
  199. // Finally, link it
  200. ulong handle = 0;
  201. UUID regionID = UUID.Zero;
  202. string externalName = string.Empty;
  203. string imageURL = string.Empty;
  204. if (!m_GatekeeperConnector.LinkRegion(regInfo, out regionID, out handle, out externalName, out imageURL, out reason))
  205. return false;
  206. if (regionID != UUID.Zero)
  207. {
  208. GridRegion r = m_GridService.GetRegionByUUID(scopeID, regionID);
  209. if (r != null)
  210. {
  211. m_log.DebugFormat("[HYPERGRID LINKER]: Region already exists in coordinates {0} {1}", r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize);
  212. regInfo = r;
  213. return true;
  214. }
  215. regInfo.RegionID = regionID;
  216. Uri uri = null;
  217. try
  218. {
  219. uri = new Uri(externalName);
  220. regInfo.ExternalHostName = uri.Host;
  221. regInfo.HttpPort = (uint)uri.Port;
  222. }
  223. catch
  224. {
  225. m_log.WarnFormat("[HYPERGRID LINKER]: Remote Gatekeeper at {0} provided malformed ExternalName {1}", regInfo.ExternalHostName, externalName);
  226. }
  227. string name = regInfo.RegionName;
  228. regInfo.RegionName = regInfo.ExternalHostName + ":" + regInfo.HttpPort;
  229. if (name != string.Empty)
  230. regInfo.RegionName += ":" + name;
  231. // Try get the map image
  232. //regInfo.TerrainImage = m_GatekeeperConnector.GetMapImage(regionID, imageURL);
  233. // I need a texture that works for this... the one I tried doesn't seem to be working
  234. regInfo.TerrainImage = m_HGMapImage;
  235. AddHyperlinkRegion(regInfo, handle);
  236. m_log.Info("[HYPERGRID LINKER]: Successfully linked to region_uuid " + regInfo.RegionID);
  237. }
  238. else
  239. {
  240. m_log.Warn("[HYPERGRID LINKER]: Unable to link region");
  241. reason = "Remote region could not be found";
  242. return false;
  243. }
  244. uint x, y;
  245. if (m_Check4096 && !Check4096(handle, out x, out y))
  246. {
  247. RemoveHyperlinkRegion(regInfo.RegionID);
  248. reason = "Region is too far (" + x + ", " + y + ")";
  249. m_log.Info("[HYPERGRID LINKER]: Unable to link, region is too far (" + x + ", " + y + ")");
  250. return false;
  251. }
  252. m_log.Debug("[HYPERGRID LINKER]: link region succeeded");
  253. return true;
  254. }
  255. public bool TryUnlinkRegion(string mapName)
  256. {
  257. m_log.DebugFormat("[HYPERGRID LINKER]: Request to unlink {0}", mapName);
  258. GridRegion regInfo = null;
  259. List<RegionData> regions = m_Database.Get(mapName, m_ScopeID);
  260. if (regions != null && regions.Count > 0)
  261. {
  262. OpenSim.Data.RegionFlags rflags = (OpenSim.Data.RegionFlags)Convert.ToInt32(regions[0].Data["flags"]);
  263. if ((rflags & OpenSim.Data.RegionFlags.Hyperlink) != 0)
  264. {
  265. regInfo = new GridRegion();
  266. regInfo.RegionID = regions[0].RegionID;
  267. regInfo.ScopeID = m_ScopeID;
  268. }
  269. }
  270. //foreach (GridRegion r in m_HyperlinkRegions.Values)
  271. //{
  272. // m_log.DebugFormat("XXX Comparing {0}:{1} with {2}:{3}", host, port, r.ExternalHostName, r.HttpPort);
  273. // if (host.Equals(r.ExternalHostName) && (port == r.HttpPort))
  274. // regInfo = r;
  275. //}
  276. if (regInfo != null)
  277. {
  278. RemoveHyperlinkRegion(regInfo.RegionID);
  279. return true;
  280. }
  281. else
  282. {
  283. m_log.InfoFormat("[HYPERGRID LINKER]: Region {0} not found", mapName);
  284. return false;
  285. }
  286. }
  287. /// <summary>
  288. /// Cope with this viewer limitation.
  289. /// </summary>
  290. /// <param name="regInfo"></param>
  291. /// <returns></returns>
  292. public bool Check4096(ulong realHandle, out uint x, out uint y)
  293. {
  294. uint ux = 0, uy = 0;
  295. Utils.LongToUInts(realHandle, out ux, out uy);
  296. x = ux / Constants.RegionSize;
  297. y = uy / Constants.RegionSize;
  298. const uint limit = (4096 - 1) * Constants.RegionSize;
  299. uint xmin = ux - limit;
  300. uint xmax = ux + limit;
  301. uint ymin = uy - limit;
  302. uint ymax = uy + limit;
  303. // World map boundary checks
  304. if (xmin < 0 || xmin > ux)
  305. xmin = 0;
  306. if (xmax > int.MaxValue || xmax < ux)
  307. xmax = int.MaxValue;
  308. if (ymin < 0 || ymin > uy)
  309. ymin = 0;
  310. if (ymax > int.MaxValue || ymax < uy)
  311. ymax = int.MaxValue;
  312. // Check for any regions that are within the possible teleport range to the linked region
  313. List<GridRegion> regions = m_GridService.GetRegionRange(m_ScopeID, (int)xmin, (int)xmax, (int)ymin, (int)ymax);
  314. if (regions.Count == 0)
  315. {
  316. return false;
  317. }
  318. else
  319. {
  320. // Check for regions which are not linked regions
  321. List<GridRegion> hyperlinks = m_GridService.GetHyperlinks(m_ScopeID);
  322. // would like to use .Except, but doesn't seem to exist
  323. //IEnumerable<GridRegion> availableRegions = regions.Except(hyperlinks);
  324. List<GridRegion> availableRegions = regions.FindAll(delegate(GridRegion region)
  325. {
  326. // Ewww! n^2
  327. if (hyperlinks.Find(delegate(GridRegion r) { return r.RegionID == region.RegionID; }) == null) // not hyperlink. good.
  328. return true;
  329. return false;
  330. });
  331. if (availableRegions.Count == 0)
  332. return false;
  333. }
  334. return true;
  335. }
  336. private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle)
  337. {
  338. //m_HyperlinkRegions[regionInfo.RegionID] = regionInfo;
  339. //m_HyperlinkHandles[regionInfo.RegionID] = regionHandle;
  340. RegionData rdata = m_GridService.RegionInfo2RegionData(regionInfo);
  341. int flags = (int)OpenSim.Data.RegionFlags.Hyperlink + (int)OpenSim.Data.RegionFlags.NoDirectLogin + (int)OpenSim.Data.RegionFlags.RegionOnline;
  342. rdata.Data["flags"] = flags.ToString();
  343. m_Database.Store(rdata);
  344. }
  345. private void RemoveHyperlinkRegion(UUID regionID)
  346. {
  347. //// Try the hyperlink collection
  348. //if (m_HyperlinkRegions.ContainsKey(regionID))
  349. //{
  350. // m_HyperlinkRegions.Remove(regionID);
  351. // m_HyperlinkHandles.Remove(regionID);
  352. //}
  353. m_Database.Delete(regionID);
  354. }
  355. #endregion
  356. #region Console Commands
  357. public void HandleShow(string module, string[] cmd)
  358. {
  359. if (cmd.Length != 2)
  360. {
  361. MainConsole.Instance.Output("Syntax: show hyperlinks");
  362. return;
  363. }
  364. List<RegionData> regions = m_Database.GetHyperlinks(UUID.Zero);
  365. if (regions == null || regions.Count < 1)
  366. {
  367. MainConsole.Instance.Output("No hyperlinks");
  368. return;
  369. }
  370. MainConsole.Instance.Output("Region Name Region UUID");
  371. MainConsole.Instance.Output("Location URI");
  372. MainConsole.Instance.Output("-------------------------------------------------------------------------------");
  373. foreach (RegionData r in regions)
  374. {
  375. MainConsole.Instance.Output(String.Format("{0,-39} {1}\n{2,-39} {3}\n",
  376. r.RegionName, r.RegionID,
  377. String.Format("{0},{1} ({2},{3})", r.posX, r.posY, r.posX / 256, r.posY / 256),
  378. "http://" + r.Data["serverIP"].ToString() + ":" + r.Data["serverHttpPort"].ToString()));
  379. }
  380. return;
  381. }
  382. public void RunCommand(string module, string[] cmdparams)
  383. {
  384. List<string> args = new List<string>(cmdparams);
  385. if (args.Count < 1)
  386. return;
  387. string command = args[0];
  388. args.RemoveAt(0);
  389. cmdparams = args.ToArray();
  390. RunHGCommand(command, cmdparams);
  391. }
  392. private void RunHGCommand(string command, string[] cmdparams)
  393. {
  394. if (command.Equals("link-mapping"))
  395. {
  396. if (cmdparams.Length == 2)
  397. {
  398. try
  399. {
  400. m_autoMappingX = Convert.ToUInt32(cmdparams[0]);
  401. m_autoMappingY = Convert.ToUInt32(cmdparams[1]);
  402. m_enableAutoMapping = true;
  403. }
  404. catch (Exception)
  405. {
  406. m_autoMappingX = 0;
  407. m_autoMappingY = 0;
  408. m_enableAutoMapping = false;
  409. }
  410. }
  411. }
  412. else if (command.Equals("link-region"))
  413. {
  414. if (cmdparams.Length < 3)
  415. {
  416. if ((cmdparams.Length == 1) || (cmdparams.Length == 2))
  417. {
  418. LoadXmlLinkFile(cmdparams);
  419. }
  420. else
  421. {
  422. LinkRegionCmdUsage();
  423. }
  424. return;
  425. }
  426. if (cmdparams[2].Contains(":"))
  427. {
  428. // New format
  429. int xloc, yloc;
  430. string mapName;
  431. try
  432. {
  433. xloc = Convert.ToInt32(cmdparams[0]);
  434. yloc = Convert.ToInt32(cmdparams[1]);
  435. mapName = cmdparams[2];
  436. if (cmdparams.Length > 3)
  437. for (int i = 3; i < cmdparams.Length; i++)
  438. mapName += " " + cmdparams[i];
  439. //m_log.Info(">> MapName: " + mapName);
  440. }
  441. catch (Exception e)
  442. {
  443. MainConsole.Instance.Output("[HGrid] Wrong format for link-region command: " + e.Message);
  444. LinkRegionCmdUsage();
  445. return;
  446. }
  447. // Convert cell coordinates given by the user to meters
  448. xloc = xloc * (int)Constants.RegionSize;
  449. yloc = yloc * (int)Constants.RegionSize;
  450. string reason = string.Empty;
  451. if (TryLinkRegionToCoords(UUID.Zero, mapName, xloc, yloc, out reason) == null)
  452. MainConsole.Instance.Output("Failed to link region: " + reason);
  453. else
  454. MainConsole.Instance.Output("Hyperlink established");
  455. }
  456. else
  457. {
  458. // old format
  459. GridRegion regInfo;
  460. int xloc, yloc;
  461. uint externalPort;
  462. string externalHostName;
  463. try
  464. {
  465. xloc = Convert.ToInt32(cmdparams[0]);
  466. yloc = Convert.ToInt32(cmdparams[1]);
  467. externalPort = Convert.ToUInt32(cmdparams[3]);
  468. externalHostName = cmdparams[2];
  469. //internalPort = Convert.ToUInt32(cmdparams[4]);
  470. //remotingPort = Convert.ToUInt32(cmdparams[5]);
  471. }
  472. catch (Exception e)
  473. {
  474. MainConsole.Instance.Output("[HGrid] Wrong format for link-region command: " + e.Message);
  475. LinkRegionCmdUsage();
  476. return;
  477. }
  478. // Convert cell coordinates given by the user to meters
  479. xloc = xloc * (int)Constants.RegionSize;
  480. yloc = yloc * (int)Constants.RegionSize;
  481. string reason = string.Empty;
  482. if (TryCreateLink(UUID.Zero, xloc, yloc, "", externalPort, externalHostName, out regInfo, out reason))
  483. {
  484. if (cmdparams.Length >= 5)
  485. {
  486. regInfo.RegionName = "";
  487. for (int i = 4; i < cmdparams.Length; i++)
  488. regInfo.RegionName += cmdparams[i] + " ";
  489. }
  490. }
  491. }
  492. return;
  493. }
  494. else if (command.Equals("unlink-region"))
  495. {
  496. if (cmdparams.Length < 1)
  497. {
  498. UnlinkRegionCmdUsage();
  499. return;
  500. }
  501. if (TryUnlinkRegion(cmdparams[0]))
  502. MainConsole.Instance.Output("Successfully unlinked " + cmdparams[0]);
  503. else
  504. MainConsole.Instance.Output("Unable to unlink " + cmdparams[0] + ", region not found.");
  505. }
  506. }
  507. private void LoadXmlLinkFile(string[] cmdparams)
  508. {
  509. //use http://www.hgurl.com/hypergrid.xml for test
  510. try
  511. {
  512. XmlReader r = XmlReader.Create(cmdparams[0]);
  513. XmlConfigSource cs = new XmlConfigSource(r);
  514. string[] excludeSections = null;
  515. if (cmdparams.Length == 2)
  516. {
  517. if (cmdparams[1].ToLower().StartsWith("excludelist:"))
  518. {
  519. string excludeString = cmdparams[1].ToLower();
  520. excludeString = excludeString.Remove(0, 12);
  521. char[] splitter = { ';' };
  522. excludeSections = excludeString.Split(splitter);
  523. }
  524. }
  525. for (int i = 0; i < cs.Configs.Count; i++)
  526. {
  527. bool skip = false;
  528. if ((excludeSections != null) && (excludeSections.Length > 0))
  529. {
  530. for (int n = 0; n < excludeSections.Length; n++)
  531. {
  532. if (excludeSections[n] == cs.Configs[i].Name.ToLower())
  533. {
  534. skip = true;
  535. break;
  536. }
  537. }
  538. }
  539. if (!skip)
  540. {
  541. ReadLinkFromConfig(cs.Configs[i]);
  542. }
  543. }
  544. }
  545. catch (Exception e)
  546. {
  547. m_log.Error(e.ToString());
  548. }
  549. }
  550. private void ReadLinkFromConfig(IConfig config)
  551. {
  552. GridRegion regInfo;
  553. int xloc, yloc;
  554. uint externalPort;
  555. string externalHostName;
  556. uint realXLoc, realYLoc;
  557. xloc = Convert.ToInt32(config.GetString("xloc", "0"));
  558. yloc = Convert.ToInt32(config.GetString("yloc", "0"));
  559. externalPort = Convert.ToUInt32(config.GetString("externalPort", "0"));
  560. externalHostName = config.GetString("externalHostName", "");
  561. realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0"));
  562. realYLoc = Convert.ToUInt32(config.GetString("real-yloc", "0"));
  563. if (m_enableAutoMapping)
  564. {
  565. xloc = (int)((xloc % 100) + m_autoMappingX);
  566. yloc = (int)((yloc % 100) + m_autoMappingY);
  567. }
  568. if (((realXLoc == 0) && (realYLoc == 0)) ||
  569. (((realXLoc - xloc < 3896) || (xloc - realXLoc < 3896)) &&
  570. ((realYLoc - yloc < 3896) || (yloc - realYLoc < 3896))))
  571. {
  572. xloc = xloc * (int)Constants.RegionSize;
  573. yloc = yloc * (int)Constants.RegionSize;
  574. string reason = string.Empty;
  575. if (TryCreateLink(UUID.Zero, xloc, yloc, "", externalPort,
  576. externalHostName, out regInfo, out reason))
  577. {
  578. regInfo.RegionName = config.GetString("localName", "");
  579. }
  580. else
  581. MainConsole.Instance.Output("Unable to link " + externalHostName + ": " + reason);
  582. }
  583. }
  584. private void LinkRegionCmdUsage()
  585. {
  586. MainConsole.Instance.Output("Usage: link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>]");
  587. MainConsole.Instance.Output("Usage: link-region <Xloc> <Yloc> <HostName> <HttpPort> [<LocalName>]");
  588. MainConsole.Instance.Output("Usage: link-region <URI_of_xml> [<exclude>]");
  589. }
  590. private void UnlinkRegionCmdUsage()
  591. {
  592. MainConsole.Instance.Output("Usage: unlink-region <HostName>:<HttpPort>");
  593. MainConsole.Instance.Output("Usage: unlink-region <LocalName>");
  594. }
  595. #endregion
  596. }
  597. }