HypergridLinker.cs 28 KB

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