HypergridLinker.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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 = 0;
  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. //try
  157. //{
  158. // Util.GetHostFromDNS(host);
  159. //}
  160. //catch
  161. //{
  162. // reason = "Malformed hostname";
  163. // return null;
  164. //}
  165. GridRegion regInfo;
  166. bool success = TryCreateLink(scopeID, xloc, yloc, regionName, port, host, out regInfo, out reason);
  167. if (success)
  168. {
  169. regInfo.RegionName = mapName;
  170. return regInfo;
  171. }
  172. return null;
  173. }
  174. // From the command line and the 2 above
  175. public bool TryCreateLink(UUID scopeID, int xloc, int yloc,
  176. string externalRegionName, uint externalPort, string externalHostName, out GridRegion regInfo, out string reason)
  177. {
  178. m_log.DebugFormat("[HYPERGRID LINKER]: Link to {0}:{1}:{2}, in {3}-{4}", externalHostName, externalPort, externalRegionName, xloc, yloc);
  179. reason = string.Empty;
  180. regInfo = new GridRegion();
  181. regInfo.RegionName = externalRegionName;
  182. regInfo.HttpPort = externalPort;
  183. regInfo.ExternalHostName = externalHostName;
  184. regInfo.RegionLocX = xloc;
  185. regInfo.RegionLocY = yloc;
  186. regInfo.ScopeID = scopeID;
  187. // Big HACK for Simian Grid !!!
  188. // We need to clean up all URLs used in OpenSim !!!
  189. if (externalHostName.Contains("/"))
  190. regInfo.ServerURI = externalHostName;
  191. try
  192. {
  193. regInfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)0);
  194. }
  195. catch (Exception e)
  196. {
  197. m_log.Warn("[HYPERGRID LINKER]: Wrong format for link-region: " + e.Message);
  198. reason = "Internal error";
  199. return false;
  200. }
  201. // Finally, link it
  202. ulong handle = 0;
  203. UUID regionID = UUID.Zero;
  204. string externalName = string.Empty;
  205. string imageURL = string.Empty;
  206. if (!m_GatekeeperConnector.LinkRegion(regInfo, out regionID, out handle, out externalName, out imageURL, out reason))
  207. return false;
  208. if (regionID != UUID.Zero)
  209. {
  210. GridRegion r = m_GridService.GetRegionByUUID(scopeID, regionID);
  211. if (r != null)
  212. {
  213. m_log.DebugFormat("[HYPERGRID LINKER]: Region already exists in coordinates {0} {1}", r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize);
  214. regInfo = r;
  215. return true;
  216. }
  217. regInfo.RegionID = regionID;
  218. if (regInfo.RegionName == string.Empty)
  219. regInfo.RegionName = regInfo.ExternalHostName;
  220. // Try get the map image
  221. //regInfo.TerrainImage = m_GatekeeperConnector.GetMapImage(regionID, imageURL);
  222. // I need a texture that works for this... the one I tried doesn't seem to be working
  223. regInfo.TerrainImage = m_HGMapImage;
  224. AddHyperlinkRegion(regInfo, handle);
  225. m_log.Info("[HYPERGRID LINKER]: Successfully linked to region_uuid " + regInfo.RegionID);
  226. }
  227. else
  228. {
  229. m_log.Warn("[HYPERGRID LINKER]: Unable to link region");
  230. reason = "Remote region could not be found";
  231. return false;
  232. }
  233. uint x, y;
  234. if (m_Check4096 && !Check4096(handle, out x, out y))
  235. {
  236. RemoveHyperlinkRegion(regInfo.RegionID);
  237. reason = "Region is too far (" + x + ", " + y + ")";
  238. m_log.Info("[HYPERGRID LINKER]: Unable to link, region is too far (" + x + ", " + y + ")");
  239. return false;
  240. }
  241. m_log.Debug("[HYPERGRID LINKER]: link region succeeded");
  242. return true;
  243. }
  244. public bool TryUnlinkRegion(string mapName)
  245. {
  246. m_log.DebugFormat("[HYPERGRID LINKER]: Request to unlink {0}", mapName);
  247. GridRegion regInfo = null;
  248. List<RegionData> regions = m_Database.Get(mapName, m_ScopeID);
  249. if (regions != null && regions.Count > 0)
  250. {
  251. OpenSim.Data.RegionFlags rflags = (OpenSim.Data.RegionFlags)Convert.ToInt32(regions[0].Data["flags"]);
  252. if ((rflags & OpenSim.Data.RegionFlags.Hyperlink) != 0)
  253. {
  254. regInfo = new GridRegion();
  255. regInfo.RegionID = regions[0].RegionID;
  256. regInfo.ScopeID = m_ScopeID;
  257. }
  258. }
  259. //foreach (GridRegion r in m_HyperlinkRegions.Values)
  260. //{
  261. // m_log.DebugFormat("XXX Comparing {0}:{1} with {2}:{3}", host, port, r.ExternalHostName, r.HttpPort);
  262. // if (host.Equals(r.ExternalHostName) && (port == r.HttpPort))
  263. // regInfo = r;
  264. //}
  265. if (regInfo != null)
  266. {
  267. RemoveHyperlinkRegion(regInfo.RegionID);
  268. return true;
  269. }
  270. else
  271. {
  272. m_log.InfoFormat("[HYPERGRID LINKER]: Region {0} not found", mapName);
  273. return false;
  274. }
  275. }
  276. /// <summary>
  277. /// Cope with this viewer limitation.
  278. /// </summary>
  279. /// <param name="regInfo"></param>
  280. /// <returns></returns>
  281. public bool Check4096(ulong realHandle, out uint x, out uint y)
  282. {
  283. uint ux = 0, uy = 0;
  284. Utils.LongToUInts(realHandle, out ux, out uy);
  285. x = ux / Constants.RegionSize;
  286. y = uy / Constants.RegionSize;
  287. const uint limit = (4096 - 1) * Constants.RegionSize;
  288. uint xmin = ux - limit;
  289. uint xmax = ux + limit;
  290. uint ymin = uy - limit;
  291. uint ymax = uy + limit;
  292. // World map boundary checks
  293. if (xmin < 0 || xmin > ux)
  294. xmin = 0;
  295. if (xmax > int.MaxValue || xmax < ux)
  296. xmax = int.MaxValue;
  297. if (ymin < 0 || ymin > uy)
  298. ymin = 0;
  299. if (ymax > int.MaxValue || ymax < uy)
  300. ymax = int.MaxValue;
  301. // Check for any regions that are within the possible teleport range to the linked region
  302. List<GridRegion> regions = m_GridService.GetRegionRange(m_ScopeID, (int)xmin, (int)xmax, (int)ymin, (int)ymax);
  303. if (regions.Count == 0)
  304. {
  305. return false;
  306. }
  307. else
  308. {
  309. // Check for regions which are not linked regions
  310. List<GridRegion> hyperlinks = m_GridService.GetHyperlinks(m_ScopeID);
  311. // would like to use .Except, but doesn't seem to exist
  312. //IEnumerable<GridRegion> availableRegions = regions.Except(hyperlinks);
  313. List<GridRegion> availableRegions = regions.FindAll(delegate(GridRegion region)
  314. {
  315. // Ewww! n^2
  316. if (hyperlinks.Find(delegate(GridRegion r) { return r.RegionID == region.RegionID; }) == null) // not hyperlink. good.
  317. return true;
  318. return false;
  319. });
  320. if (availableRegions.Count == 0)
  321. return false;
  322. }
  323. return true;
  324. }
  325. private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle)
  326. {
  327. RegionData rdata = m_GridService.RegionInfo2RegionData(regionInfo);
  328. int flags = (int)OpenSim.Data.RegionFlags.Hyperlink + (int)OpenSim.Data.RegionFlags.NoDirectLogin + (int)OpenSim.Data.RegionFlags.RegionOnline;
  329. rdata.Data["flags"] = flags.ToString();
  330. m_Database.Store(rdata);
  331. }
  332. private void RemoveHyperlinkRegion(UUID regionID)
  333. {
  334. m_Database.Delete(regionID);
  335. }
  336. #endregion
  337. #region Console Commands
  338. public void HandleShow(string module, string[] cmd)
  339. {
  340. if (cmd.Length != 2)
  341. {
  342. MainConsole.Instance.Output("Syntax: show hyperlinks");
  343. return;
  344. }
  345. List<RegionData> regions = m_Database.GetHyperlinks(UUID.Zero);
  346. if (regions == null || regions.Count < 1)
  347. {
  348. MainConsole.Instance.Output("No hyperlinks");
  349. return;
  350. }
  351. MainConsole.Instance.Output("Region Name Region UUID");
  352. MainConsole.Instance.Output("Location URI");
  353. MainConsole.Instance.Output("-------------------------------------------------------------------------------");
  354. foreach (RegionData r in regions)
  355. {
  356. MainConsole.Instance.Output(String.Format("{0,-39} {1}\n{2,-39} {3}\n",
  357. r.RegionName, r.RegionID,
  358. String.Format("{0},{1} ({2},{3})", r.posX, r.posY, r.posX / 256, r.posY / 256),
  359. "http://" + r.Data["serverIP"].ToString() + ":" + r.Data["serverHttpPort"].ToString()));
  360. }
  361. return;
  362. }
  363. public void RunCommand(string module, string[] cmdparams)
  364. {
  365. List<string> args = new List<string>(cmdparams);
  366. if (args.Count < 1)
  367. return;
  368. string command = args[0];
  369. args.RemoveAt(0);
  370. cmdparams = args.ToArray();
  371. RunHGCommand(command, cmdparams);
  372. }
  373. private void RunHGCommand(string command, string[] cmdparams)
  374. {
  375. if (command.Equals("link-mapping"))
  376. {
  377. if (cmdparams.Length == 2)
  378. {
  379. try
  380. {
  381. m_autoMappingX = Convert.ToUInt32(cmdparams[0]);
  382. m_autoMappingY = Convert.ToUInt32(cmdparams[1]);
  383. m_enableAutoMapping = true;
  384. }
  385. catch (Exception)
  386. {
  387. m_autoMappingX = 0;
  388. m_autoMappingY = 0;
  389. m_enableAutoMapping = false;
  390. }
  391. }
  392. }
  393. else if (command.Equals("link-region"))
  394. {
  395. if (cmdparams.Length < 3)
  396. {
  397. if ((cmdparams.Length == 1) || (cmdparams.Length == 2))
  398. {
  399. LoadXmlLinkFile(cmdparams);
  400. }
  401. else
  402. {
  403. LinkRegionCmdUsage();
  404. }
  405. return;
  406. }
  407. if (cmdparams[2].Contains(":"))
  408. {
  409. // New format
  410. int xloc, yloc;
  411. string mapName;
  412. try
  413. {
  414. xloc = Convert.ToInt32(cmdparams[0]);
  415. yloc = Convert.ToInt32(cmdparams[1]);
  416. mapName = cmdparams[2];
  417. if (cmdparams.Length > 3)
  418. for (int i = 3; i < cmdparams.Length; i++)
  419. mapName += " " + cmdparams[i];
  420. //m_log.Info(">> MapName: " + mapName);
  421. }
  422. catch (Exception e)
  423. {
  424. MainConsole.Instance.Output("[HGrid] Wrong format for link-region command: " + e.Message);
  425. LinkRegionCmdUsage();
  426. return;
  427. }
  428. // Convert cell coordinates given by the user to meters
  429. xloc = xloc * (int)Constants.RegionSize;
  430. yloc = yloc * (int)Constants.RegionSize;
  431. string reason = string.Empty;
  432. if (TryLinkRegionToCoords(UUID.Zero, mapName, xloc, yloc, out reason) == null)
  433. MainConsole.Instance.Output("Failed to link region: " + reason);
  434. else
  435. MainConsole.Instance.Output("Hyperlink established");
  436. }
  437. else
  438. {
  439. // old format
  440. GridRegion regInfo;
  441. int xloc, yloc;
  442. uint externalPort;
  443. string externalHostName;
  444. try
  445. {
  446. xloc = Convert.ToInt32(cmdparams[0]);
  447. yloc = Convert.ToInt32(cmdparams[1]);
  448. externalPort = Convert.ToUInt32(cmdparams[3]);
  449. externalHostName = cmdparams[2];
  450. //internalPort = Convert.ToUInt32(cmdparams[4]);
  451. //remotingPort = Convert.ToUInt32(cmdparams[5]);
  452. }
  453. catch (Exception e)
  454. {
  455. MainConsole.Instance.Output("[HGrid] Wrong format for link-region command: " + e.Message);
  456. LinkRegionCmdUsage();
  457. return;
  458. }
  459. // Convert cell coordinates given by the user to meters
  460. xloc = xloc * (int)Constants.RegionSize;
  461. yloc = yloc * (int)Constants.RegionSize;
  462. string reason = string.Empty;
  463. if (TryCreateLink(UUID.Zero, xloc, yloc, "", externalPort, externalHostName, out regInfo, out reason))
  464. {
  465. if (cmdparams.Length >= 5)
  466. {
  467. regInfo.RegionName = "";
  468. for (int i = 4; i < cmdparams.Length; i++)
  469. regInfo.RegionName += cmdparams[i] + " ";
  470. }
  471. }
  472. }
  473. return;
  474. }
  475. else if (command.Equals("unlink-region"))
  476. {
  477. if (cmdparams.Length < 1)
  478. {
  479. UnlinkRegionCmdUsage();
  480. return;
  481. }
  482. if (TryUnlinkRegion(cmdparams[0]))
  483. MainConsole.Instance.Output("Successfully unlinked " + cmdparams[0]);
  484. else
  485. MainConsole.Instance.Output("Unable to unlink " + cmdparams[0] + ", region not found.");
  486. }
  487. }
  488. private void LoadXmlLinkFile(string[] cmdparams)
  489. {
  490. //use http://www.hgurl.com/hypergrid.xml for test
  491. try
  492. {
  493. XmlReader r = XmlReader.Create(cmdparams[0]);
  494. XmlConfigSource cs = new XmlConfigSource(r);
  495. string[] excludeSections = null;
  496. if (cmdparams.Length == 2)
  497. {
  498. if (cmdparams[1].ToLower().StartsWith("excludelist:"))
  499. {
  500. string excludeString = cmdparams[1].ToLower();
  501. excludeString = excludeString.Remove(0, 12);
  502. char[] splitter = { ';' };
  503. excludeSections = excludeString.Split(splitter);
  504. }
  505. }
  506. for (int i = 0; i < cs.Configs.Count; i++)
  507. {
  508. bool skip = false;
  509. if ((excludeSections != null) && (excludeSections.Length > 0))
  510. {
  511. for (int n = 0; n < excludeSections.Length; n++)
  512. {
  513. if (excludeSections[n] == cs.Configs[i].Name.ToLower())
  514. {
  515. skip = true;
  516. break;
  517. }
  518. }
  519. }
  520. if (!skip)
  521. {
  522. ReadLinkFromConfig(cs.Configs[i]);
  523. }
  524. }
  525. }
  526. catch (Exception e)
  527. {
  528. m_log.Error(e.ToString());
  529. }
  530. }
  531. private void ReadLinkFromConfig(IConfig config)
  532. {
  533. GridRegion regInfo;
  534. int xloc, yloc;
  535. uint externalPort;
  536. string externalHostName;
  537. uint realXLoc, realYLoc;
  538. xloc = Convert.ToInt32(config.GetString("xloc", "0"));
  539. yloc = Convert.ToInt32(config.GetString("yloc", "0"));
  540. externalPort = Convert.ToUInt32(config.GetString("externalPort", "0"));
  541. externalHostName = config.GetString("externalHostName", "");
  542. realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0"));
  543. realYLoc = Convert.ToUInt32(config.GetString("real-yloc", "0"));
  544. if (m_enableAutoMapping)
  545. {
  546. xloc = (int)((xloc % 100) + m_autoMappingX);
  547. yloc = (int)((yloc % 100) + m_autoMappingY);
  548. }
  549. if (((realXLoc == 0) && (realYLoc == 0)) ||
  550. (((realXLoc - xloc < 3896) || (xloc - realXLoc < 3896)) &&
  551. ((realYLoc - yloc < 3896) || (yloc - realYLoc < 3896))))
  552. {
  553. xloc = xloc * (int)Constants.RegionSize;
  554. yloc = yloc * (int)Constants.RegionSize;
  555. string reason = string.Empty;
  556. if (TryCreateLink(UUID.Zero, xloc, yloc, "", externalPort,
  557. externalHostName, out regInfo, out reason))
  558. {
  559. regInfo.RegionName = config.GetString("localName", "");
  560. }
  561. else
  562. MainConsole.Instance.Output("Unable to link " + externalHostName + ": " + reason);
  563. }
  564. }
  565. private void LinkRegionCmdUsage()
  566. {
  567. MainConsole.Instance.Output("Usage: link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>]");
  568. MainConsole.Instance.Output("Usage: link-region <Xloc> <Yloc> <HostName> <HttpPort> [<LocalName>]");
  569. MainConsole.Instance.Output("Usage: link-region <URI_of_xml> [<exclude>]");
  570. }
  571. private void UnlinkRegionCmdUsage()
  572. {
  573. MainConsole.Instance.Output("Usage: unlink-region <HostName>:<HttpPort>");
  574. MainConsole.Instance.Output("Usage: unlink-region <LocalName>");
  575. }
  576. #endregion
  577. }
  578. }