RegionInfo.cs 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  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 == String.Empty)
  374. {
  375. while (name.Trim() == string.Empty)
  376. {
  377. name = MainConsole.Instance.Prompt("New region name", name);
  378. if (name.Trim() == string.Empty)
  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 == String.Empty)
  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 == UUID.Zero)
  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 == String.Empty)
  426. {
  427. location = MainConsole.Instance.Prompt("Region Location", "1000,1000");
  428. config.Set("Location", location);
  429. }
  430. string[] locationElements = location.Split(new char[] {','});
  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 == true)
  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 = Util.Clamp<uint>(RegionSizeX, Constants.RegionSize, Constants.MaximumRegionSize);
  643. RegionSizeY = Util.Clamp<uint>(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("NonphysicalPrimMax", m_nonphysPrimMin);
  673. if (m_nonphysPrimMax > 0)
  674. config.Set("NonphysicalPrimMax", m_nonphysPrimMax);
  675. if (m_physPrimMin > 0)
  676. config.Set("PhysicalPrimMax", 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 != UUID.Zero)
  689. config.Set("ScopeID", ScopeID.ToString());
  690. if (RegionType != String.Empty)
  691. config.Set("RegionType", RegionType);
  692. if (m_maptileStaticUUID != UUID.Zero)
  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 ((RegionName != null) && !RegionName.Equals(""))
  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 ((RemotingAddress != null) && !RemotingAddress.Equals(""))
  925. args["remoting_address"] = OSD.FromString(RemotingAddress);
  926. args["remoting_port"] = OSD.FromString(RemotingPort.ToString());
  927. if ((proxyUrl != null) && !proxyUrl.Equals(""))
  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. if (args.ContainsKey("region_size_x"))
  958. RegionSizeX = (uint)args["region_size_x"].AsInteger();
  959. if (args.ContainsKey("region_size_y"))
  960. RegionSizeY = (uint)args["region_size_y"].AsInteger();
  961. if (args.ContainsKey("region_size_z"))
  962. RegionSizeZ = (uint)args["region_size_z"].AsInteger();
  963. IPAddress ip_addr = null;
  964. if (args["internal_ep_address"] != null)
  965. {
  966. IPAddress.TryParse(args["internal_ep_address"].AsString(), out ip_addr);
  967. }
  968. int port = 0;
  969. if (args["internal_ep_port"] != null)
  970. {
  971. Int32.TryParse(args["internal_ep_port"].AsString(), out port);
  972. }
  973. InternalEndPoint = new IPEndPoint(ip_addr, port);
  974. if (args["remoting_address"] != null)
  975. RemotingAddress = args["remoting_address"].AsString();
  976. if (args["remoting_port"] != null)
  977. UInt32.TryParse(args["remoting_port"].AsString(), out m_remotingPort);
  978. if (args["proxy_url"] != null)
  979. proxyUrl = args["proxy_url"].AsString();
  980. if (args["region_type"] != null)
  981. m_regionType = args["region_type"].AsString();
  982. }
  983. public static RegionInfo Create(UUID regionID, string regionName, uint regX, uint regY, string externalHostName, uint httpPort, uint simPort, uint remotingPort, string serverURI)
  984. {
  985. RegionInfo regionInfo;
  986. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(externalHostName), (int)simPort);
  987. regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, externalHostName);
  988. regionInfo.RemotingPort = remotingPort;
  989. regionInfo.RemotingAddress = externalHostName;
  990. regionInfo.HttpPort = httpPort;
  991. regionInfo.RegionID = regionID;
  992. regionInfo.RegionName = regionName;
  993. regionInfo.ServerURI = serverURI;
  994. return regionInfo;
  995. }
  996. public int getInternalEndPointPort()
  997. {
  998. return m_internalEndPoint.Port;
  999. }
  1000. public Dictionary<string, object> ToKeyValuePairs()
  1001. {
  1002. Dictionary<string, object> kvp = new Dictionary<string, object>();
  1003. kvp["uuid"] = RegionID.ToString();
  1004. kvp["locX"] = RegionLocX.ToString();
  1005. kvp["locY"] = RegionLocY.ToString();
  1006. kvp["external_ip_address"] = ExternalEndPoint.Address.ToString();
  1007. kvp["external_port"] = ExternalEndPoint.Port.ToString();
  1008. kvp["external_host_name"] = ExternalHostName;
  1009. kvp["http_port"] = HttpPort.ToString();
  1010. kvp["internal_ip_address"] = InternalEndPoint.Address.ToString();
  1011. kvp["internal_port"] = InternalEndPoint.Port.ToString();
  1012. // TODO: Remove in next major version
  1013. kvp["alternate_ports"] = "False";
  1014. kvp["server_uri"] = ServerURI;
  1015. return kvp;
  1016. }
  1017. }
  1018. }