1
0

RegionInfo.cs 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209
  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.Net.Sockets;
  31. using System.Reflection;
  32. using System.Xml;
  33. using System.IO;
  34. using log4net;
  35. using Nini.Config;
  36. using OpenMetaverse;
  37. using OpenMetaverse.StructuredData;
  38. //using OpenSim.Framework.Console;
  39. namespace OpenSim.Framework
  40. {
  41. public class RegionInfo
  42. {
  43. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  44. private static readonly string LogHeader = "[REGION INFO]";
  45. public bool commFailTF = false;
  46. public ConfigurationMember configMember;
  47. public string DataStore = String.Empty;
  48. public string RegionFile = String.Empty;
  49. public bool isSandbox = false;
  50. public bool Persistent = true;
  51. private EstateSettings m_estateSettings;
  52. private RegionSettings m_regionSettings;
  53. // private IConfigSource m_configSource = null;
  54. public UUID originRegionID = UUID.Zero;
  55. public string proxyUrl = "";
  56. public int ProxyOffset = 0;
  57. public string regionSecret = UUID.Random().ToString();
  58. public string osSecret;
  59. public UUID lastMapUUID = UUID.Zero;
  60. public string lastMapRefresh = "0";
  61. private float m_nonphysPrimMin = 0;
  62. private int m_nonphysPrimMax = 0;
  63. private float m_physPrimMin = 0;
  64. private int m_physPrimMax = 0;
  65. private bool m_clampPrimSize = false;
  66. private int m_objectCapacity = 15000;
  67. private int m_maxPrimsPerUser = -1;
  68. private int m_linksetCapacity = 0;
  69. private string m_regionType = String.Empty;
  70. protected uint m_httpPort;
  71. protected string m_serverURI;
  72. protected string m_regionName = String.Empty;
  73. protected string m_externalHostName;
  74. protected IPEndPoint m_internalEndPoint;
  75. protected uint m_remotingPort;
  76. public UUID RegionID = UUID.Zero;
  77. public string RemotingAddress;
  78. public UUID ScopeID = UUID.Zero;
  79. private UUID m_maptileStaticUUID = UUID.Zero;
  80. private bool m_resolveAddress = false;
  81. public uint WorldLocX = 0;
  82. public uint WorldLocY = 0;
  83. public uint WorldLocZ = 0;
  84. /// <summary>
  85. /// X dimension of the region.
  86. /// </summary>
  87. /// <remarks>
  88. /// If this is a varregion then the default size set here will be replaced when we load the region config.
  89. /// </remarks>
  90. public uint RegionSizeX = Constants.RegionSize;
  91. /// <summary>
  92. /// X dimension of the region.
  93. /// </summary>
  94. /// <remarks>
  95. /// If this is a varregion then the default size set here will be replaced when we load the region config.
  96. /// </remarks>
  97. public uint RegionSizeY = Constants.RegionSize;
  98. /// <summary>
  99. /// Z dimension of the region.
  100. /// </summary>
  101. /// <remarks>
  102. /// XXX: Unknown if this accounts for regions with negative Z.
  103. /// </remarks>
  104. public uint RegionSizeZ = Constants.RegionHeight;
  105. // If entering avatar has no specific coords, this is where they land
  106. public Vector3 DefaultLandingPoint = new Vector3(128, 128, 30);
  107. private Dictionary<String, String> m_extraSettings = new Dictionary<string, string>();
  108. // Apparently, we're applying the same estatesettings regardless of whether it's local or remote.
  109. // MT: Yes. Estates can't span trust boundaries. Therefore, it can be
  110. // assumed that all instances belonging to one estate are able to
  111. // access the same database server. Since estate settings are lodaed
  112. // from there, that should be sufficient for full remote administration
  113. // File based loading
  114. //
  115. public RegionInfo(string description, string filename, bool skipConsoleConfig, IConfigSource configSource) : this(description, filename, skipConsoleConfig, configSource, String.Empty)
  116. {
  117. }
  118. public RegionInfo(string description, string filename, bool skipConsoleConfig, IConfigSource configSource, string configName)
  119. {
  120. // m_configSource = configSource;
  121. if (filename.ToLower().EndsWith(".ini"))
  122. {
  123. if (!File.Exists(filename)) // New region config request
  124. {
  125. IniConfigSource newFile = new IniConfigSource();
  126. ReadNiniConfig(newFile, configName);
  127. newFile.Save(filename);
  128. RegionFile = filename;
  129. return;
  130. }
  131. IniConfigSource source = new IniConfigSource(filename);
  132. bool saveFile = false;
  133. if (source.Configs[configName] == null)
  134. saveFile = true;
  135. ReadNiniConfig(source, configName);
  136. if (configName != String.Empty && saveFile)
  137. source.Save(filename);
  138. RegionFile = filename;
  139. return;
  140. }
  141. try
  142. {
  143. // This will throw if it's not legal Nini XML format
  144. //
  145. IConfigSource xmlsource = new XmlConfigSource(filename);
  146. ReadNiniConfig(xmlsource, configName);
  147. RegionFile = filename;
  148. return;
  149. }
  150. catch (Exception)
  151. {
  152. }
  153. }
  154. // The web loader uses this
  155. //
  156. public RegionInfo(string description, XmlNode xmlNode, bool skipConsoleConfig, IConfigSource configSource)
  157. {
  158. XmlElement elem = (XmlElement)xmlNode;
  159. string name = elem.GetAttribute("Name");
  160. string xmlstr = "<Nini>" + xmlNode.OuterXml + "</Nini>";
  161. XmlConfigSource source = new XmlConfigSource(XmlReader.Create(new StringReader(xmlstr)));
  162. ReadNiniConfig(source, name);
  163. m_serverURI = string.Empty;
  164. }
  165. public RegionInfo(uint legacyRegionLocX, uint legacyRegionLocY, IPEndPoint internalEndPoint, string externalUri)
  166. {
  167. RegionLocX = legacyRegionLocX;
  168. RegionLocY = legacyRegionLocY;
  169. RegionSizeX = Constants.RegionSize;
  170. RegionSizeY = Constants.RegionSize;
  171. m_internalEndPoint = internalEndPoint;
  172. m_externalHostName = externalUri;
  173. m_serverURI = string.Empty;
  174. }
  175. public RegionInfo()
  176. {
  177. m_serverURI = string.Empty;
  178. }
  179. public EstateSettings EstateSettings
  180. {
  181. get
  182. {
  183. if (m_estateSettings == null)
  184. {
  185. m_estateSettings = new EstateSettings();
  186. }
  187. return m_estateSettings;
  188. }
  189. set { m_estateSettings = value; }
  190. }
  191. public RegionSettings RegionSettings
  192. {
  193. get
  194. {
  195. if (m_regionSettings == null)
  196. {
  197. m_regionSettings = new RegionSettings();
  198. }
  199. return m_regionSettings;
  200. }
  201. set { m_regionSettings = value; }
  202. }
  203. public float NonphysPrimMin
  204. {
  205. get { return m_nonphysPrimMin; }
  206. }
  207. public int NonphysPrimMax
  208. {
  209. get { return m_nonphysPrimMax; }
  210. }
  211. public float PhysPrimMin
  212. {
  213. get { return m_physPrimMin; }
  214. }
  215. public int PhysPrimMax
  216. {
  217. get { return m_physPrimMax; }
  218. }
  219. public bool ClampPrimSize
  220. {
  221. get { return m_clampPrimSize; }
  222. }
  223. public int ObjectCapacity
  224. {
  225. get { return m_objectCapacity; }
  226. }
  227. public int MaxPrimsPerUser
  228. {
  229. get { return m_maxPrimsPerUser; }
  230. }
  231. public int LinksetCapacity
  232. {
  233. get { return m_linksetCapacity; }
  234. }
  235. public int AgentCapacity { get; set; }
  236. public byte AccessLevel
  237. {
  238. get { return (byte)Util.ConvertMaturityToAccessLevel((uint)RegionSettings.Maturity); }
  239. }
  240. public string RegionType
  241. {
  242. get { return m_regionType; }
  243. }
  244. public UUID MaptileStaticUUID
  245. {
  246. get { return m_maptileStaticUUID; }
  247. }
  248. public string MaptileStaticFile { get; private set; }
  249. /// <summary>
  250. /// The port by which http communication occurs with the region (most noticeably, CAPS communication)
  251. /// </summary>
  252. public uint HttpPort
  253. {
  254. get { return m_httpPort; }
  255. set { m_httpPort = value; }
  256. }
  257. /// <summary>
  258. /// A well-formed URI for the host region server (namely "http://" + ExternalHostName)
  259. /// </summary>
  260. public string ServerURI
  261. {
  262. get {
  263. if ( m_serverURI != string.Empty ) {
  264. return m_serverURI;
  265. } else {
  266. return "http://" + m_externalHostName + ":" + m_httpPort + "/";
  267. }
  268. }
  269. set {
  270. if ( value.EndsWith("/") ) {
  271. m_serverURI = value;
  272. } else {
  273. m_serverURI = value + '/';
  274. }
  275. }
  276. }
  277. public string RegionName
  278. {
  279. get { return m_regionName; }
  280. set { m_regionName = value; }
  281. }
  282. public uint RemotingPort
  283. {
  284. get { return m_remotingPort; }
  285. set { m_remotingPort = value; }
  286. }
  287. /// <value>
  288. /// This accessor can throw all the exceptions that Dns.GetHostAddresses can throw.
  289. ///
  290. /// XXX Isn't this really doing too much to be a simple getter, rather than an explict method?
  291. /// </value>
  292. public IPEndPoint ExternalEndPoint
  293. {
  294. get { return Util.getEndPoint(m_externalHostName, m_internalEndPoint.Port); }
  295. set { m_externalHostName = value.ToString(); }
  296. }
  297. public string ExternalHostName
  298. {
  299. get { return m_externalHostName; }
  300. set { m_externalHostName = value; }
  301. }
  302. public IPEndPoint InternalEndPoint
  303. {
  304. get { return m_internalEndPoint; }
  305. set { m_internalEndPoint = value; }
  306. }
  307. /// <summary>
  308. /// The x co-ordinate of this region in map tiles (e.g. 1000).
  309. /// Coordinate is scaled as world coordinates divided by the legacy region size
  310. /// and is thus is the number of legacy regions.
  311. /// </summary>
  312. public uint RegionLocX
  313. {
  314. get { return WorldLocX / Constants.RegionSize; }
  315. set { WorldLocX = value * Constants.RegionSize; }
  316. }
  317. /// <summary>
  318. /// The y co-ordinate of this region in map tiles (e.g. 1000).
  319. /// Coordinate is scaled as world coordinates divided by the legacy region size
  320. /// and is thus is the number of legacy regions.
  321. /// </summary>
  322. public uint RegionLocY
  323. {
  324. get { return WorldLocY / Constants.RegionSize; }
  325. set { WorldLocY = value * Constants.RegionSize; }
  326. }
  327. public void SetDefaultRegionSize()
  328. {
  329. WorldLocX = 0;
  330. WorldLocY = 0;
  331. WorldLocZ = 0;
  332. RegionSizeX = Constants.RegionSize;
  333. RegionSizeY = Constants.RegionSize;
  334. RegionSizeZ = Constants.RegionHeight;
  335. }
  336. // A unique region handle is created from the region's world coordinates.
  337. // This cannot be changed because some code expects to receive the region handle and then
  338. // compute the region coordinates from it.
  339. public ulong RegionHandle
  340. {
  341. get { return Util.UIntsToLong(WorldLocX, WorldLocY); }
  342. }
  343. public void SetEndPoint(string ipaddr, int port)
  344. {
  345. IPAddress tmpIP = IPAddress.Parse(ipaddr);
  346. IPEndPoint tmpEPE = new IPEndPoint(tmpIP, port);
  347. m_internalEndPoint = tmpEPE;
  348. }
  349. public string GetSetting(string key)
  350. {
  351. string val;
  352. string keylower = key.ToLower();
  353. if (m_extraSettings.TryGetValue(keylower, out val))
  354. return val;
  355. m_log.DebugFormat("[RegionInfo] Could not locate value for parameter {0}", key);
  356. return null;
  357. }
  358. public void SetExtraSetting(string key, string value)
  359. {
  360. string keylower = key.ToLower();
  361. m_extraSettings[keylower] = value;
  362. }
  363. private void ReadNiniConfig(IConfigSource source, string name)
  364. {
  365. bool creatingNew = false;
  366. if (source.Configs.Count == 0)
  367. {
  368. MainConsole.Instance.Output("=====================================\n");
  369. MainConsole.Instance.Output("We are now going to ask a couple of questions about your region.\n");
  370. MainConsole.Instance.Output("You can press 'enter' without typing anything to use the default\n");
  371. MainConsole.Instance.Output("the default is displayed between [ ] brackets.\n");
  372. MainConsole.Instance.Output("=====================================\n");
  373. if (name.Length == 0)
  374. {
  375. while (name.Trim().Length == 0)
  376. {
  377. name = MainConsole.Instance.Prompt("New region name", name);
  378. if (name.Trim().Length == 0)
  379. {
  380. MainConsole.Instance.Output("Cannot interactively create region with no name");
  381. }
  382. }
  383. }
  384. source.AddConfig(name);
  385. creatingNew = true;
  386. }
  387. if (name.Length == 0)
  388. name = source.Configs[0].Name;
  389. if (source.Configs[name] == null)
  390. {
  391. source.AddConfig(name);
  392. }
  393. RegionName = name;
  394. IConfig config = source.Configs[name];
  395. // Track all of the keys in this config and remove as they are processed
  396. // The remaining keys will be added to generic key-value storage for
  397. // whoever might need it
  398. HashSet<String> allKeys = new HashSet<String>();
  399. foreach (string s in config.GetKeys())
  400. {
  401. allKeys.Add(s);
  402. }
  403. // RegionUUID
  404. //
  405. allKeys.Remove("RegionUUID");
  406. string regionUUID = config.GetString("RegionUUID", string.Empty);
  407. if (!UUID.TryParse(regionUUID.Trim(), out RegionID))
  408. {
  409. UUID newID = UUID.Random();
  410. while (RegionID.IsZero())
  411. {
  412. regionUUID = MainConsole.Instance.Prompt("RegionUUID", newID.ToString());
  413. if (!UUID.TryParse(regionUUID.Trim(), out RegionID))
  414. {
  415. MainConsole.Instance.Output("RegionUUID must be a valid UUID");
  416. }
  417. }
  418. config.Set("RegionUUID", regionUUID);
  419. }
  420. originRegionID = RegionID; // What IS this?! (Needed for RegionCombinerModule?)
  421. // Location
  422. //
  423. allKeys.Remove("Location");
  424. string location = config.GetString("Location", String.Empty);
  425. if (location.Length == 0)
  426. {
  427. location = MainConsole.Instance.Prompt("Region Location", "1000,1000");
  428. config.Set("Location", location);
  429. }
  430. string[] locationElements = location.Split(Util.SplitCommaArray);
  431. RegionLocX = Convert.ToUInt32(locationElements[0]);
  432. RegionLocY = Convert.ToUInt32(locationElements[1]);
  433. // Region size
  434. // Default to legacy region size if not specified.
  435. allKeys.Remove("SizeX");
  436. string configSizeX = config.GetString("SizeX", Constants.RegionSize.ToString());
  437. config.Set("SizeX", configSizeX);
  438. RegionSizeX = Convert.ToUInt32(configSizeX);
  439. allKeys.Remove("SizeY");
  440. string configSizeY = config.GetString("SizeY", Constants.RegionSize.ToString());
  441. config.Set("SizeY", configSizeX);
  442. RegionSizeY = Convert.ToUInt32(configSizeY);
  443. allKeys.Remove("SizeZ");
  444. string configSizeZ = config.GetString("SizeZ", Constants.RegionHeight.ToString());
  445. config.Set("SizeZ", configSizeX);
  446. RegionSizeZ = Convert.ToUInt32(configSizeZ);
  447. DoRegionSizeSanityChecks();
  448. // InternalAddress
  449. //
  450. IPAddress address;
  451. allKeys.Remove("InternalAddress");
  452. if (config.Contains("InternalAddress"))
  453. {
  454. address = IPAddress.Parse(config.GetString("InternalAddress", String.Empty));
  455. }
  456. else
  457. {
  458. address = IPAddress.Parse(MainConsole.Instance.Prompt("Internal IP address", "0.0.0.0"));
  459. config.Set("InternalAddress", address.ToString());
  460. }
  461. // InternalPort
  462. //
  463. int port;
  464. allKeys.Remove("InternalPort");
  465. if (config.Contains("InternalPort"))
  466. {
  467. port = config.GetInt("InternalPort", 9000);
  468. }
  469. else
  470. {
  471. port = Convert.ToInt32(MainConsole.Instance.Prompt("Internal port", "9000"));
  472. config.Set("InternalPort", port);
  473. }
  474. m_internalEndPoint = new IPEndPoint(address, port);
  475. // ResolveAddress
  476. //
  477. allKeys.Remove("ResolveAddress");
  478. if (config.Contains("ResolveAddress"))
  479. {
  480. m_resolveAddress = config.GetBoolean("ResolveAddress", false);
  481. }
  482. else
  483. {
  484. if (creatingNew)
  485. m_resolveAddress = Convert.ToBoolean(MainConsole.Instance.Prompt("Resolve hostname to IP on start (for running inside Docker)", "False"));
  486. config.Set("ResolveAddress", m_resolveAddress.ToString());
  487. }
  488. // ExternalHostName
  489. //
  490. allKeys.Remove("ExternalHostName");
  491. string externalName;
  492. if (config.Contains("ExternalHostName"))
  493. {
  494. externalName = config.GetString("ExternalHostName", "SYSTEMIP");
  495. }
  496. else
  497. {
  498. externalName = MainConsole.Instance.Prompt("External host name", "SYSTEMIP");
  499. config.Set("ExternalHostName", externalName);
  500. }
  501. if (externalName == "SYSTEMIP")
  502. {
  503. m_externalHostName = Util.GetLocalHost().ToString();
  504. m_log.InfoFormat(
  505. "[REGIONINFO]: Resolving SYSTEMIP to {0} for external hostname of region {1}",
  506. m_externalHostName, name);
  507. }
  508. else if (!m_resolveAddress)
  509. {
  510. m_externalHostName = externalName;
  511. }
  512. else
  513. {
  514. IPAddress[] addrs = Dns.GetHostAddresses(externalName);
  515. if (addrs.Length != 1) // If it is ambiguous or not resolveable, use it literally
  516. m_externalHostName = externalName;
  517. else
  518. m_externalHostName = addrs[0].ToString();
  519. }
  520. // RegionType
  521. m_regionType = config.GetString("RegionType", String.Empty);
  522. allKeys.Remove("RegionType");
  523. // Get Default Landing Location (Defaults to 128,128)
  524. string temp_location = config.GetString("DefaultLanding", "<128, 128, 30>");
  525. Vector3 temp_vector;
  526. if (Vector3.TryParse(temp_location, out temp_vector))
  527. DefaultLandingPoint = temp_vector;
  528. else
  529. m_log.ErrorFormat("[RegionInfo]: Unable to parse DefaultLanding for '{0}'. The value given was '{1}'", RegionName, temp_location);
  530. allKeys.Remove("DefaultLanding");
  531. DoDefaultLandingSanityChecks();
  532. #region Prim and map stuff
  533. m_nonphysPrimMin = config.GetFloat("NonPhysicalPrimMin", 0);
  534. allKeys.Remove("NonPhysicalPrimMin");
  535. m_nonphysPrimMax = config.GetInt("NonPhysicalPrimMax", 0);
  536. allKeys.Remove("NonPhysicalPrimMax");
  537. m_physPrimMin = config.GetFloat("PhysicalPrimMin", 0);
  538. allKeys.Remove("PhysicalPrimMin");
  539. m_physPrimMax = config.GetInt("PhysicalPrimMax", 0);
  540. allKeys.Remove("PhysicalPrimMax");
  541. m_clampPrimSize = config.GetBoolean("ClampPrimSize", false);
  542. allKeys.Remove("ClampPrimSize");
  543. m_objectCapacity = config.GetInt("MaxPrims", m_objectCapacity);
  544. allKeys.Remove("MaxPrims");
  545. m_maxPrimsPerUser = config.GetInt("MaxPrimsPerUser", -1);
  546. allKeys.Remove("MaxPrimsPerUser");
  547. m_linksetCapacity = config.GetInt("LinksetPrims", 0);
  548. allKeys.Remove("LinksetPrims");
  549. allKeys.Remove("MaptileStaticUUID");
  550. string mapTileStaticUUID = config.GetString("MaptileStaticUUID", UUID.Zero.ToString());
  551. if (UUID.TryParse(mapTileStaticUUID.Trim(), out m_maptileStaticUUID))
  552. {
  553. config.Set("MaptileStaticUUID", m_maptileStaticUUID.ToString());
  554. }
  555. MaptileStaticFile = config.GetString("MaptileStaticFile", String.Empty);
  556. allKeys.Remove("MaptileStaticFile");
  557. #endregion
  558. AgentCapacity = config.GetInt("MaxAgents", 100);
  559. allKeys.Remove("MaxAgents");
  560. // Multi-tenancy
  561. //
  562. ScopeID = new UUID(config.GetString("ScopeID", UUID.Zero.ToString()));
  563. allKeys.Remove("ScopeID");
  564. foreach (String s in allKeys)
  565. {
  566. SetExtraSetting(s, config.GetString(s));
  567. }
  568. }
  569. // Make sure DefaultLanding is within region borders with a buffer zone 5 meters from borders
  570. private void DoDefaultLandingSanityChecks()
  571. {
  572. // Sanity Check Default Landing
  573. float buffer_zone = 5f;
  574. bool ValuesCapped = false;
  575. // Minimum Positions
  576. if (DefaultLandingPoint.X < buffer_zone)
  577. {
  578. DefaultLandingPoint.X = buffer_zone;
  579. ValuesCapped = true;
  580. }
  581. if (DefaultLandingPoint.Y < buffer_zone)
  582. {
  583. DefaultLandingPoint.Y = buffer_zone;
  584. ValuesCapped = true;
  585. }
  586. // Maximum Positions
  587. if (DefaultLandingPoint.X > RegionSizeX - buffer_zone)
  588. {
  589. DefaultLandingPoint.X = RegionSizeX - buffer_zone;
  590. ValuesCapped = true;
  591. }
  592. if (DefaultLandingPoint.Y > RegionSizeY - buffer_zone)
  593. {
  594. DefaultLandingPoint.Y = RegionSizeY - buffer_zone;
  595. ValuesCapped = true;
  596. }
  597. // Height
  598. if (DefaultLandingPoint.Z < 0f)
  599. DefaultLandingPoint.Z = 0f;
  600. if (ValuesCapped)
  601. m_log.WarnFormat("[RegionInfo]: The default landing location for {0} has been capped to {1}", RegionName, DefaultLandingPoint);
  602. }
  603. // Make sure user specified region sizes are sane.
  604. // Must be multiples of legacy region size (256).
  605. private void DoRegionSizeSanityChecks()
  606. {
  607. if (RegionSizeX != Constants.RegionSize || RegionSizeY != Constants.RegionSize)
  608. {
  609. // Doing non-legacy region sizes.
  610. // Enforce region size to be multiples of the legacy region size (256)
  611. uint partial = RegionSizeX % Constants.RegionSize;
  612. if (partial != 0)
  613. {
  614. RegionSizeX -= partial;
  615. if (RegionSizeX == 0)
  616. RegionSizeX = Constants.RegionSize;
  617. m_log.ErrorFormat("{0} Region size must be multiple of {1}. Enforcing {2}.RegionSizeX={3} instead of specified {4}",
  618. LogHeader, Constants.RegionSize, m_regionName, RegionSizeX, RegionSizeX + partial);
  619. }
  620. partial = RegionSizeY % Constants.RegionSize;
  621. if (partial != 0)
  622. {
  623. RegionSizeY -= partial;
  624. if (RegionSizeY == 0)
  625. RegionSizeY = Constants.RegionSize;
  626. m_log.ErrorFormat("{0} Region size must be multiple of {1}. Enforcing {2}.RegionSizeY={3} instead of specified {4}",
  627. LogHeader, Constants.RegionSize, m_regionName, RegionSizeY, RegionSizeY + partial);
  628. }
  629. // Because of things in the viewer, regions MUST be square.
  630. // Remove this check when viewers have been updated.
  631. if (RegionSizeX != RegionSizeY)
  632. {
  633. uint minSize = Math.Min(RegionSizeX, RegionSizeY);
  634. RegionSizeX = minSize;
  635. RegionSizeY = minSize;
  636. m_log.ErrorFormat("{0} Regions must be square until viewers are updated. Forcing region {1} size to <{2},{3}>",
  637. LogHeader, m_regionName, RegionSizeX, RegionSizeY);
  638. }
  639. // There is a practical limit to region size.
  640. if (RegionSizeX > Constants.MaximumRegionSize || RegionSizeY > Constants.MaximumRegionSize)
  641. {
  642. RegionSizeX = Math.Clamp(RegionSizeX, Constants.RegionSize, Constants.MaximumRegionSize);
  643. RegionSizeY = Math.Clamp(RegionSizeY, Constants.RegionSize, Constants.MaximumRegionSize);
  644. m_log.ErrorFormat("{0} Region dimensions must be less than {1}. Clamping {2}'s size to <{3},{4}>",
  645. LogHeader, Constants.MaximumRegionSize, m_regionName, RegionSizeX, RegionSizeY);
  646. }
  647. m_log.InfoFormat("{0} Region {1} size set to <{2},{3}>", LogHeader, m_regionName, RegionSizeX, RegionSizeY);
  648. }
  649. }
  650. private void WriteNiniConfig(IConfigSource source)
  651. {
  652. IConfig config = source.Configs[RegionName];
  653. if (config != null)
  654. source.Configs.Remove(config);
  655. config = source.AddConfig(RegionName);
  656. config.Set("RegionUUID", RegionID.ToString());
  657. string location = String.Format("{0},{1}", RegionLocX, RegionLocY);
  658. config.Set("Location", location);
  659. if (DataStore != String.Empty)
  660. config.Set("Datastore", DataStore);
  661. if (RegionSizeX != Constants.RegionSize || RegionSizeY != Constants.RegionSize)
  662. {
  663. config.Set("SizeX", RegionSizeX);
  664. config.Set("SizeY", RegionSizeY);
  665. // if (RegionSizeZ > 0)
  666. // config.Set("SizeZ", RegionSizeZ);
  667. }
  668. config.Set("InternalAddress", m_internalEndPoint.Address.ToString());
  669. config.Set("InternalPort", m_internalEndPoint.Port);
  670. config.Set("ExternalHostName", m_externalHostName);
  671. if (m_nonphysPrimMin > 0)
  672. config.Set("NonphysicalPrimMin", m_nonphysPrimMin);
  673. if (m_nonphysPrimMax > 0)
  674. config.Set("NonphysicalPrimMax", m_nonphysPrimMax);
  675. if (m_physPrimMin > 0)
  676. config.Set("PhysicalPrimMin", m_physPrimMin);
  677. if (m_physPrimMax > 0)
  678. config.Set("PhysicalPrimMax", m_physPrimMax);
  679. config.Set("ClampPrimSize", m_clampPrimSize.ToString());
  680. if (m_objectCapacity > 0)
  681. config.Set("MaxPrims", m_objectCapacity);
  682. if (m_maxPrimsPerUser > -1)
  683. config.Set("MaxPrimsPerUser", m_maxPrimsPerUser);
  684. if (m_linksetCapacity > 0)
  685. config.Set("LinksetPrims", m_linksetCapacity);
  686. if (AgentCapacity > 0)
  687. config.Set("MaxAgents", AgentCapacity);
  688. if (!ScopeID.IsZero())
  689. config.Set("ScopeID", ScopeID.ToString());
  690. if (RegionType != String.Empty)
  691. config.Set("RegionType", RegionType);
  692. if (!m_maptileStaticUUID.IsZero())
  693. config.Set("MaptileStaticUUID", m_maptileStaticUUID.ToString());
  694. if (MaptileStaticFile != null && MaptileStaticFile != String.Empty)
  695. config.Set("MaptileStaticFile", MaptileStaticFile);
  696. }
  697. public void SaveRegionToFile(string description, string filename)
  698. {
  699. if (filename.ToLower().EndsWith(".ini"))
  700. {
  701. IniConfigSource source = new IniConfigSource();
  702. try
  703. {
  704. source = new IniConfigSource(filename); // Load if it exists
  705. }
  706. catch (Exception)
  707. {
  708. }
  709. WriteNiniConfig(source);
  710. source.Save(filename);
  711. return;
  712. }
  713. else
  714. throw new Exception("Invalid file type for region persistence.");
  715. }
  716. public void loadConfigurationOptionsFromMe()
  717. {
  718. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID_NULL_FREE,
  719. "UUID of Region (Default is recommended, random UUID)",
  720. RegionID.ToString(), true);
  721. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  722. "Region Name", RegionName, true);
  723. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  724. "Grid Location (X Axis)", RegionLocX.ToString(), true);
  725. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  726. "Grid Location (Y Axis)", RegionLocY.ToString(), true);
  727. configMember.addConfigurationOption("sim_size_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  728. "Size of region in X dimension", RegionSizeX.ToString(), true);
  729. configMember.addConfigurationOption("sim_size_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  730. "Size of region in Y dimension", RegionSizeY.ToString(), true);
  731. configMember.addConfigurationOption("sim_size_z", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  732. "Size of region in Z dimension", RegionSizeZ.ToString(), true);
  733. //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  734. configMember.addConfigurationOption("internal_ip_address",
  735. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  736. "Internal IP Address for incoming UDP client connections",
  737. m_internalEndPoint.Address.ToString(),
  738. true);
  739. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  740. "Internal IP Port for incoming UDP client connections",
  741. m_internalEndPoint.Port.ToString(), true);
  742. configMember.addConfigurationOption("external_host_name",
  743. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  744. "External Host Name", m_externalHostName, true);
  745. configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  746. "Last Map UUID", lastMapUUID.ToString(), true);
  747. configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  748. "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
  749. configMember.addConfigurationOption("nonphysical_prim_min", ConfigurationOption.ConfigurationTypes.TYPE_FLOAT,
  750. "Minimum size for nonphysical prims", m_nonphysPrimMin.ToString(), true);
  751. configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  752. "Maximum size for nonphysical prims", m_nonphysPrimMax.ToString(), true);
  753. configMember.addConfigurationOption("physical_prim_min", ConfigurationOption.ConfigurationTypes.TYPE_FLOAT,
  754. "Minimum size for nonphysical prims", m_physPrimMin.ToString(), true);
  755. configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  756. "Maximum size for physical prims", m_physPrimMax.ToString(), true);
  757. configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  758. "Clamp prims to max size", m_clampPrimSize.ToString(), true);
  759. configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  760. "Max objects this sim will hold", m_objectCapacity.ToString(), true);
  761. configMember.addConfigurationOption("linkset_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  762. "Max prims an object will hold", m_linksetCapacity.ToString(), true);
  763. configMember.addConfigurationOption("agent_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  764. "Max avatars this sim will hold",AgentCapacity.ToString(), true);
  765. configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  766. "Scope ID for this region", ScopeID.ToString(), true);
  767. configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  768. "Free form string describing the type of region", String.Empty, true);
  769. configMember.addConfigurationOption("region_static_maptile", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  770. "UUID of a texture to use as the map for this region", m_maptileStaticUUID.ToString(), true);
  771. }
  772. public void loadConfigurationOptions()
  773. {
  774. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  775. "UUID of Region (Default is recommended, random UUID)",
  776. UUID.Random().ToString(), true);
  777. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  778. "Region Name", "OpenSim Test", false);
  779. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  780. "Grid Location (X Axis)", "1000", false);
  781. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  782. "Grid Location (Y Axis)", "1000", false);
  783. configMember.addConfigurationOption("sim_size_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  784. "Size of region in X dimension", Constants.RegionSize.ToString(), false);
  785. configMember.addConfigurationOption("sim_size_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  786. "Size of region in Y dimension", Constants.RegionSize.ToString(), false);
  787. configMember.addConfigurationOption("sim_size_z", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  788. "Size of region in Z dimension", Constants.RegionHeight.ToString(), false);
  789. //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  790. configMember.addConfigurationOption("internal_ip_address",
  791. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  792. "Internal IP Address for incoming UDP client connections", "0.0.0.0",
  793. false);
  794. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  795. "Internal IP Port for incoming UDP client connections",
  796. ConfigSettings.DefaultRegionHttpPort.ToString(), false);
  797. configMember.addConfigurationOption("external_host_name",
  798. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  799. "External Host Name", "127.0.0.1", false);
  800. configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  801. "Last Map UUID", lastMapUUID.ToString(), true);
  802. configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  803. "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
  804. configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  805. "Maximum size for nonphysical prims", "0", true);
  806. configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  807. "Maximum size for physical prims", "0", true);
  808. configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  809. "Clamp prims to max size", "false", true);
  810. configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  811. "Max objects this sim will hold", "15000", true);
  812. configMember.addConfigurationOption("agent_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  813. "Max avatars this sim will hold", "100", true);
  814. configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  815. "Scope ID for this region", UUID.Zero.ToString(), true);
  816. configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  817. "Region Type", String.Empty, true);
  818. configMember.addConfigurationOption("region_static_maptile", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  819. "UUID of a texture to use as the map for this region", String.Empty, true);
  820. }
  821. public bool handleIncomingConfiguration(string configuration_key, object configuration_result)
  822. {
  823. switch (configuration_key)
  824. {
  825. case "sim_UUID":
  826. RegionID = (UUID) configuration_result;
  827. originRegionID = (UUID) configuration_result;
  828. break;
  829. case "sim_name":
  830. RegionName = (string) configuration_result;
  831. break;
  832. case "sim_location_x":
  833. RegionLocX = (uint) configuration_result;
  834. break;
  835. case "sim_location_y":
  836. RegionLocY = (uint) configuration_result;
  837. break;
  838. case "sim_size_x":
  839. RegionSizeX = (uint) configuration_result;
  840. break;
  841. case "sim_size_y":
  842. RegionSizeY = (uint) configuration_result;
  843. break;
  844. case "sim_size_z":
  845. RegionSizeZ = (uint) configuration_result;
  846. break;
  847. case "datastore":
  848. DataStore = (string) configuration_result;
  849. break;
  850. case "internal_ip_address":
  851. IPAddress address = (IPAddress) configuration_result;
  852. m_internalEndPoint = new IPEndPoint(address, 0);
  853. break;
  854. case "internal_ip_port":
  855. m_internalEndPoint.Port = (int) configuration_result;
  856. break;
  857. case "external_host_name":
  858. if ((string) configuration_result != "SYSTEMIP")
  859. {
  860. m_externalHostName = (string) configuration_result;
  861. }
  862. else
  863. {
  864. m_externalHostName = Util.GetLocalHost().ToString();
  865. }
  866. break;
  867. case "lastmap_uuid":
  868. lastMapUUID = (UUID)configuration_result;
  869. break;
  870. case "lastmap_refresh":
  871. lastMapRefresh = (string)configuration_result;
  872. break;
  873. case "nonphysical_prim_max":
  874. m_nonphysPrimMax = (int)configuration_result;
  875. break;
  876. case "physical_prim_max":
  877. m_physPrimMax = (int)configuration_result;
  878. break;
  879. case "clamp_prim_size":
  880. m_clampPrimSize = (bool)configuration_result;
  881. break;
  882. case "object_capacity":
  883. m_objectCapacity = (int)configuration_result;
  884. break;
  885. case "linkset_capacity":
  886. m_linksetCapacity = (int)configuration_result;
  887. break;
  888. case "agent_capacity":
  889. AgentCapacity = (int)configuration_result;
  890. break;
  891. case "scope_id":
  892. ScopeID = (UUID)configuration_result;
  893. break;
  894. case "region_type":
  895. m_regionType = (string)configuration_result;
  896. break;
  897. case "region_static_maptile":
  898. m_maptileStaticUUID = (UUID)configuration_result;
  899. break;
  900. }
  901. return true;
  902. }
  903. public void SaveLastMapUUID(UUID mapUUID)
  904. {
  905. lastMapUUID = mapUUID;
  906. lastMapRefresh = Util.UnixTimeSinceEpoch().ToString();
  907. }
  908. public OSDMap PackRegionInfoData()
  909. {
  910. OSDMap args = new OSDMap();
  911. args["region_id"] = OSD.FromUUID(RegionID);
  912. if (!string.IsNullOrEmpty(RegionName))
  913. args["region_name"] = OSD.FromString(RegionName);
  914. args["external_host_name"] = OSD.FromString(ExternalHostName);
  915. args["http_port"] = OSD.FromString(HttpPort.ToString());
  916. args["server_uri"] = OSD.FromString(ServerURI);
  917. args["region_xloc"] = OSD.FromString(RegionLocX.ToString());
  918. args["region_yloc"] = OSD.FromString(RegionLocY.ToString());
  919. args["region_size_x"] = OSD.FromString(RegionSizeX.ToString());
  920. args["region_size_y"] = OSD.FromString(RegionSizeY.ToString());
  921. args["region_size_z"] = OSD.FromString(RegionSizeZ.ToString());
  922. args["internal_ep_address"] = OSD.FromString(InternalEndPoint.Address.ToString());
  923. args["internal_ep_port"] = OSD.FromString(InternalEndPoint.Port.ToString());
  924. if (!string.IsNullOrEmpty(RemotingAddress))
  925. args["remoting_address"] = OSD.FromString(RemotingAddress);
  926. args["remoting_port"] = OSD.FromString(RemotingPort.ToString());
  927. if (!string.IsNullOrEmpty(proxyUrl))
  928. args["proxy_url"] = OSD.FromString(proxyUrl);
  929. if (RegionType != String.Empty)
  930. args["region_type"] = OSD.FromString(RegionType);
  931. return args;
  932. }
  933. public void UnpackRegionInfoData(OSDMap args)
  934. {
  935. if (args["region_id"] != null)
  936. RegionID = args["region_id"].AsUUID();
  937. if (args["region_name"] != null)
  938. RegionName = args["region_name"].AsString();
  939. if (args["external_host_name"] != null)
  940. ExternalHostName = args["external_host_name"].AsString();
  941. if (args["http_port"] != null)
  942. UInt32.TryParse(args["http_port"].AsString(), out m_httpPort);
  943. if (args["server_uri"] != null)
  944. ServerURI = args["server_uri"].AsString();
  945. if (args["region_xloc"] != null)
  946. {
  947. uint locx;
  948. UInt32.TryParse(args["region_xloc"].AsString(), out locx);
  949. RegionLocX = locx;
  950. }
  951. if (args["region_yloc"] != null)
  952. {
  953. uint locy;
  954. UInt32.TryParse(args["region_yloc"].AsString(), out locy);
  955. RegionLocY = locy;
  956. }
  957. OSD osdtmp;
  958. if (args.TryGetValue("region_size_x", out osdtmp))
  959. RegionSizeX = (uint)osdtmp.AsInteger();
  960. if (args.TryGetValue("region_size_y", out osdtmp))
  961. RegionSizeY = (uint)osdtmp.AsInteger();
  962. if (args.TryGetValue("region_size_z", out osdtmp))
  963. RegionSizeZ = (uint)osdtmp.AsInteger();
  964. IPAddress ip_addr = null;
  965. if (args["internal_ep_address"] != null)
  966. {
  967. IPAddress.TryParse(args["internal_ep_address"].AsString(), out ip_addr);
  968. }
  969. int port = 0;
  970. if (args["internal_ep_port"] != null)
  971. {
  972. Int32.TryParse(args["internal_ep_port"].AsString(), out port);
  973. }
  974. InternalEndPoint = new IPEndPoint(ip_addr, port);
  975. if (args["remoting_address"] != null)
  976. RemotingAddress = args["remoting_address"].AsString();
  977. if (args["remoting_port"] != null)
  978. UInt32.TryParse(args["remoting_port"].AsString(), out m_remotingPort);
  979. if (args["proxy_url"] != null)
  980. proxyUrl = args["proxy_url"].AsString();
  981. if (args["region_type"] != null)
  982. m_regionType = args["region_type"].AsString();
  983. }
  984. public static RegionInfo Create(UUID regionID, string regionName, uint regX, uint regY, string externalHostName, uint httpPort, uint simPort, uint remotingPort, string serverURI)
  985. {
  986. RegionInfo regionInfo;
  987. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(externalHostName), (int)simPort);
  988. regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, externalHostName);
  989. regionInfo.RemotingPort = remotingPort;
  990. regionInfo.RemotingAddress = externalHostName;
  991. regionInfo.HttpPort = httpPort;
  992. regionInfo.RegionID = regionID;
  993. regionInfo.RegionName = regionName;
  994. regionInfo.ServerURI = serverURI;
  995. return regionInfo;
  996. }
  997. public int getInternalEndPointPort()
  998. {
  999. return m_internalEndPoint.Port;
  1000. }
  1001. public Dictionary<string, object> ToKeyValuePairs()
  1002. {
  1003. Dictionary<string, object> kvp = new Dictionary<string, object>();
  1004. kvp["uuid"] = RegionID.ToString();
  1005. kvp["locX"] = RegionLocX.ToString();
  1006. kvp["locY"] = RegionLocY.ToString();
  1007. kvp["external_ip_address"] = ExternalEndPoint.Address.ToString();
  1008. kvp["external_port"] = ExternalEndPoint.Port.ToString();
  1009. kvp["external_host_name"] = ExternalHostName;
  1010. kvp["http_port"] = HttpPort.ToString();
  1011. kvp["internal_ip_address"] = InternalEndPoint.Address.ToString();
  1012. kvp["internal_port"] = InternalEndPoint.Port.ToString();
  1013. // TODO: Remove in next major version
  1014. kvp["alternate_ports"] = "False";
  1015. kvp["server_uri"] = ServerURI;
  1016. return kvp;
  1017. }
  1018. }
  1019. }