RegionInfo.cs 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  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 RegionLightShareData : ICloneable
  42. {
  43. public bool valid = false;
  44. public UUID regionID = UUID.Zero;
  45. public Vector3 waterColor = new Vector3(4.0f,38.0f,64.0f);
  46. public float waterFogDensityExponent = 4.0f;
  47. public float underwaterFogModifier = 0.25f;
  48. public Vector3 reflectionWaveletScale = new Vector3(2.0f,2.0f,2.0f);
  49. public float fresnelScale = 0.40f;
  50. public float fresnelOffset = 0.50f;
  51. public float refractScaleAbove = 0.03f;
  52. public float refractScaleBelow = 0.20f;
  53. public float blurMultiplier = 0.040f;
  54. public Vector2 bigWaveDirection = new Vector2(1.05f,-0.42f);
  55. public Vector2 littleWaveDirection = new Vector2(1.11f,-1.16f);
  56. public UUID normalMapTexture = new UUID("822ded49-9a6c-f61c-cb89-6df54f42cdf4");
  57. public Vector4 horizon = new Vector4(0.25f, 0.25f, 0.32f, 0.32f);
  58. public float hazeHorizon = 0.19f;
  59. public Vector4 blueDensity = new Vector4(0.12f, 0.22f, 0.38f, 0.38f);
  60. public float hazeDensity = 0.70f;
  61. public float densityMultiplier = 0.18f;
  62. public float distanceMultiplier = 0.8f;
  63. public UInt16 maxAltitude = 1605;
  64. public Vector4 sunMoonColor = new Vector4(0.24f, 0.26f, 0.30f, 0.30f);
  65. public float sunMoonPosition = 0.317f;
  66. public Vector4 ambient = new Vector4(0.35f,0.35f,0.35f,0.35f);
  67. public float eastAngle = 0.0f;
  68. public float sunGlowFocus = 0.10f;
  69. public float sunGlowSize = 1.75f;
  70. public float sceneGamma = 1.0f;
  71. public float starBrightness = 0.0f;
  72. public Vector4 cloudColor = new Vector4(0.41f, 0.41f, 0.41f, 0.41f);
  73. public Vector3 cloudXYDensity = new Vector3(1.00f, 0.53f, 1.00f);
  74. public float cloudCoverage = 0.27f;
  75. public float cloudScale = 0.42f;
  76. public Vector3 cloudDetailXYDensity = new Vector3(1.00f, 0.53f, 0.12f);
  77. public float cloudScrollX = 0.20f;
  78. public bool cloudScrollXLock = false;
  79. public float cloudScrollY = 0.01f;
  80. public bool cloudScrollYLock = false;
  81. public bool drawClassicClouds = true;
  82. public delegate void SaveDelegate(RegionLightShareData wl);
  83. public event SaveDelegate OnSave;
  84. public void Save()
  85. {
  86. if (OnSave != null)
  87. OnSave(this);
  88. }
  89. public object Clone()
  90. {
  91. return this.MemberwiseClone(); // call clone method
  92. }
  93. }
  94. public class RegionInfo
  95. {
  96. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  97. private static readonly string LogHeader = "[REGION INFO]";
  98. public string RegionFile = String.Empty;
  99. public bool isSandbox = false;
  100. public bool Persistent = true;
  101. private EstateSettings m_estateSettings;
  102. private RegionSettings m_regionSettings;
  103. // private IConfigSource m_configSource = null;
  104. public UUID originRegionID = UUID.Zero;
  105. public string proxyUrl = "";
  106. public int ProxyOffset = 0;
  107. public string regionSecret = UUID.Random().ToString();
  108. public string osSecret;
  109. public UUID lastMapUUID = UUID.Zero;
  110. public string lastMapRefresh = "0";
  111. private float m_nonphysPrimMin = 0;
  112. private int m_nonphysPrimMax = 0;
  113. private float m_physPrimMin = 0;
  114. private int m_physPrimMax = 0;
  115. private bool m_clampPrimSize = false;
  116. private int m_objectCapacity = 0;
  117. private int m_maxPrimsPerUser = -1;
  118. private int m_linksetCapacity = 0;
  119. private int m_agentCapacity = 0;
  120. private string m_regionType = String.Empty;
  121. private RegionLightShareData m_windlight = new RegionLightShareData();
  122. protected uint m_httpPort;
  123. protected string m_serverURI;
  124. protected string m_regionName = String.Empty;
  125. protected bool Allow_Alternate_Ports;
  126. public bool m_allow_alternate_ports;
  127. protected string m_externalHostName;
  128. protected IPEndPoint m_internalEndPoint;
  129. protected uint m_remotingPort;
  130. public UUID RegionID = UUID.Zero;
  131. public string RemotingAddress;
  132. public UUID ScopeID = UUID.Zero;
  133. private UUID m_maptileStaticUUID = UUID.Zero;
  134. public uint WorldLocX = 0;
  135. public uint WorldLocY = 0;
  136. public uint WorldLocZ = 0;
  137. /// <summary>
  138. /// X dimension of the region.
  139. /// </summary>
  140. /// <remarks>
  141. /// If this is a varregion then the default size set here will be replaced when we load the region config.
  142. /// </remarks>
  143. public uint RegionSizeX = Constants.RegionSize;
  144. /// <summary>
  145. /// X dimension of the region.
  146. /// </summary>
  147. /// <remarks>
  148. /// If this is a varregion then the default size set here will be replaced when we load the region config.
  149. /// </remarks>
  150. public uint RegionSizeY = Constants.RegionSize;
  151. /// <summary>
  152. /// Z dimension of the region.
  153. /// </summary>
  154. /// <remarks>
  155. /// XXX: Unknown if this accounts for regions with negative Z.
  156. /// </remarks>
  157. public uint RegionSizeZ = Constants.RegionHeight;
  158. private Dictionary<String, String> m_extraSettings = new Dictionary<string, string>();
  159. // Apparently, we're applying the same estatesettings regardless of whether it's local or remote.
  160. // MT: Yes. Estates can't span trust boundaries. Therefore, it can be
  161. // assumed that all instances belonging to one estate are able to
  162. // access the same database server. Since estate settings are lodaed
  163. // from there, that should be sufficient for full remote administration
  164. // File based loading
  165. //
  166. public RegionInfo(string description, string filename, bool skipConsoleConfig, IConfigSource configSource) : this(description, filename, skipConsoleConfig, configSource, String.Empty)
  167. {
  168. }
  169. public RegionInfo(string description, string filename, bool skipConsoleConfig, IConfigSource configSource, string configName)
  170. {
  171. // m_configSource = configSource;
  172. if (filename.ToLower().EndsWith(".ini"))
  173. {
  174. if (!File.Exists(filename)) // New region config request
  175. {
  176. IniConfigSource newFile = new IniConfigSource();
  177. ReadNiniConfig(newFile, configName);
  178. newFile.Save(filename);
  179. RegionFile = filename;
  180. return;
  181. }
  182. IniConfigSource source = new IniConfigSource(filename);
  183. bool saveFile = false;
  184. if (source.Configs[configName] == null)
  185. saveFile = true;
  186. ReadNiniConfig(source, configName);
  187. if (configName != String.Empty && saveFile)
  188. source.Save(filename);
  189. RegionFile = filename;
  190. return;
  191. }
  192. try
  193. {
  194. // This will throw if it's not legal Nini XML format
  195. //
  196. IConfigSource xmlsource = new XmlConfigSource(filename);
  197. ReadNiniConfig(xmlsource, configName);
  198. RegionFile = filename;
  199. return;
  200. }
  201. catch (Exception)
  202. {
  203. }
  204. }
  205. // The web loader uses this
  206. //
  207. public RegionInfo(string description, XmlNode xmlNode, bool skipConsoleConfig, IConfigSource configSource)
  208. {
  209. XmlElement elem = (XmlElement)xmlNode;
  210. string name = elem.GetAttribute("Name");
  211. string xmlstr = "<Nini>" + xmlNode.OuterXml + "</Nini>";
  212. XmlConfigSource source = new XmlConfigSource(XmlReader.Create(new StringReader(xmlstr)));
  213. ReadNiniConfig(source, name);
  214. m_serverURI = string.Empty;
  215. }
  216. public RegionInfo(uint legacyRegionLocX, uint legacyRegionLocY, IPEndPoint internalEndPoint, string externalUri)
  217. {
  218. RegionLocX = legacyRegionLocX;
  219. RegionLocY = legacyRegionLocY;
  220. RegionSizeX = Constants.RegionSize;
  221. RegionSizeY = Constants.RegionSize;
  222. m_internalEndPoint = internalEndPoint;
  223. m_externalHostName = externalUri;
  224. m_serverURI = string.Empty;
  225. }
  226. public RegionInfo()
  227. {
  228. m_serverURI = string.Empty;
  229. }
  230. public EstateSettings EstateSettings
  231. {
  232. get
  233. {
  234. if (m_estateSettings == null)
  235. {
  236. m_estateSettings = new EstateSettings();
  237. }
  238. return m_estateSettings;
  239. }
  240. set { m_estateSettings = value; }
  241. }
  242. public RegionSettings RegionSettings
  243. {
  244. get
  245. {
  246. if (m_regionSettings == null)
  247. {
  248. m_regionSettings = new RegionSettings();
  249. }
  250. return m_regionSettings;
  251. }
  252. set { m_regionSettings = value; }
  253. }
  254. public RegionLightShareData WindlightSettings
  255. {
  256. get
  257. {
  258. if (m_windlight == null)
  259. {
  260. m_windlight = new RegionLightShareData();
  261. }
  262. return m_windlight;
  263. }
  264. set { m_windlight = value; }
  265. }
  266. public float NonphysPrimMin
  267. {
  268. get { return m_nonphysPrimMin; }
  269. }
  270. public int NonphysPrimMax
  271. {
  272. get { return m_nonphysPrimMax; }
  273. }
  274. public float PhysPrimMin
  275. {
  276. get { return m_physPrimMin; }
  277. }
  278. public int PhysPrimMax
  279. {
  280. get { return m_physPrimMax; }
  281. }
  282. public bool ClampPrimSize
  283. {
  284. get { return m_clampPrimSize; }
  285. }
  286. public int ObjectCapacity
  287. {
  288. get { return m_objectCapacity; }
  289. }
  290. public int MaxPrimsPerUser
  291. {
  292. get { return m_maxPrimsPerUser; }
  293. }
  294. public int LinksetCapacity
  295. {
  296. get { return m_linksetCapacity; }
  297. }
  298. public int AgentCapacity
  299. {
  300. get { return m_agentCapacity; }
  301. }
  302. public byte AccessLevel
  303. {
  304. get { return (byte)Util.ConvertMaturityToAccessLevel((uint)RegionSettings.Maturity); }
  305. }
  306. public string RegionType
  307. {
  308. get { return m_regionType; }
  309. }
  310. public UUID MaptileStaticUUID
  311. {
  312. get { return m_maptileStaticUUID; }
  313. }
  314. public string MaptileStaticFile { get; private set; }
  315. /// <summary>
  316. /// The port by which http communication occurs with the region (most noticeably, CAPS communication)
  317. /// </summary>
  318. public uint HttpPort
  319. {
  320. get { return m_httpPort; }
  321. set { m_httpPort = value; }
  322. }
  323. /// <summary>
  324. /// A well-formed URI for the host region server (namely "http://" + ExternalHostName)
  325. /// </summary>
  326. public string ServerURI
  327. {
  328. get {
  329. if ( m_serverURI != string.Empty ) {
  330. return m_serverURI;
  331. } else {
  332. return "http://" + m_externalHostName + ":" + m_httpPort + "/";
  333. }
  334. }
  335. set {
  336. if ( value.EndsWith("/") ) {
  337. m_serverURI = value;
  338. } else {
  339. m_serverURI = value + '/';
  340. }
  341. }
  342. }
  343. public string RegionName
  344. {
  345. get { return m_regionName; }
  346. set { m_regionName = value; }
  347. }
  348. public uint RemotingPort
  349. {
  350. get { return m_remotingPort; }
  351. set { m_remotingPort = value; }
  352. }
  353. /// <value>
  354. /// This accessor can throw all the exceptions that Dns.GetHostAddresses can throw.
  355. ///
  356. /// XXX Isn't this really doing too much to be a simple getter, rather than an explict method?
  357. /// </value>
  358. public IPEndPoint ExternalEndPoint
  359. {
  360. get
  361. {
  362. // Old one defaults to IPv6
  363. //return new IPEndPoint(Dns.GetHostAddresses(m_externalHostName)[0], m_internalEndPoint.Port);
  364. IPAddress ia = null;
  365. // If it is already an IP, don't resolve it - just return directly
  366. if (IPAddress.TryParse(m_externalHostName, out ia))
  367. return new IPEndPoint(ia, m_internalEndPoint.Port);
  368. // Reset for next check
  369. ia = null;
  370. try
  371. {
  372. foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
  373. {
  374. if (ia == null)
  375. ia = Adr;
  376. if (Adr.AddressFamily == AddressFamily.InterNetwork)
  377. {
  378. ia = Adr;
  379. break;
  380. }
  381. }
  382. }
  383. catch (SocketException e)
  384. {
  385. throw new Exception(
  386. "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
  387. e + "' attached to this exception", e);
  388. }
  389. return new IPEndPoint(ia, m_internalEndPoint.Port);
  390. }
  391. set { m_externalHostName = value.ToString(); }
  392. }
  393. public string ExternalHostName
  394. {
  395. get { return m_externalHostName; }
  396. set { m_externalHostName = value; }
  397. }
  398. public IPEndPoint InternalEndPoint
  399. {
  400. get { return m_internalEndPoint; }
  401. set { m_internalEndPoint = value; }
  402. }
  403. /// <summary>
  404. /// The x co-ordinate of this region in map tiles (e.g. 1000).
  405. /// Coordinate is scaled as world coordinates divided by the legacy region size
  406. /// and is thus is the number of legacy regions.
  407. /// </summary>
  408. public uint RegionLocX
  409. {
  410. get { return WorldLocX / Constants.RegionSize; }
  411. set { WorldLocX = value * Constants.RegionSize; }
  412. }
  413. /// <summary>
  414. /// The y co-ordinate of this region in map tiles (e.g. 1000).
  415. /// Coordinate is scaled as world coordinates divided by the legacy region size
  416. /// and is thus is the number of legacy regions.
  417. /// </summary>
  418. public uint RegionLocY
  419. {
  420. get { return WorldLocY / Constants.RegionSize; }
  421. set { WorldLocY = value * Constants.RegionSize; }
  422. }
  423. public void SetDefaultRegionSize()
  424. {
  425. WorldLocX = 0;
  426. WorldLocY = 0;
  427. WorldLocZ = 0;
  428. RegionSizeX = Constants.RegionSize;
  429. RegionSizeY = Constants.RegionSize;
  430. RegionSizeZ = Constants.RegionHeight;
  431. }
  432. // A unique region handle is created from the region's world coordinates.
  433. // This cannot be changed because some code expects to receive the region handle and then
  434. // compute the region coordinates from it.
  435. public ulong RegionHandle
  436. {
  437. get { return Util.UIntsToLong(WorldLocX, WorldLocY); }
  438. }
  439. public void SetEndPoint(string ipaddr, int port)
  440. {
  441. IPAddress tmpIP = IPAddress.Parse(ipaddr);
  442. IPEndPoint tmpEPE = new IPEndPoint(tmpIP, port);
  443. m_internalEndPoint = tmpEPE;
  444. }
  445. public string GetSetting(string key)
  446. {
  447. string val;
  448. string keylower = key.ToLower();
  449. if (m_extraSettings.TryGetValue(keylower, out val))
  450. return val;
  451. m_log.DebugFormat("[RegionInfo] Could not locate value for parameter {0}", key);
  452. return null;
  453. }
  454. private void SetExtraSetting(string key, string value)
  455. {
  456. string keylower = key.ToLower();
  457. m_extraSettings[keylower] = value;
  458. }
  459. private void ReadNiniConfig(IConfigSource source, string name)
  460. {
  461. // bool creatingNew = false;
  462. if (source.Configs.Count == 0)
  463. {
  464. MainConsole.Instance.Output("=====================================\n");
  465. MainConsole.Instance.Output("We are now going to ask a couple of questions about your region.\n");
  466. MainConsole.Instance.Output("You can press 'enter' without typing anything to use the default\n");
  467. MainConsole.Instance.Output("the default is displayed between [ ] brackets.\n");
  468. MainConsole.Instance.Output("=====================================\n");
  469. if (name == String.Empty)
  470. {
  471. while (name.Trim() == string.Empty)
  472. {
  473. name = MainConsole.Instance.CmdPrompt("New region name", name);
  474. if (name.Trim() == string.Empty)
  475. {
  476. MainConsole.Instance.Output("Cannot interactively create region with no name");
  477. }
  478. }
  479. }
  480. source.AddConfig(name);
  481. // creatingNew = true;
  482. }
  483. if (name == String.Empty)
  484. name = source.Configs[0].Name;
  485. if (source.Configs[name] == null)
  486. {
  487. source.AddConfig(name);
  488. }
  489. RegionName = name;
  490. IConfig config = source.Configs[name];
  491. // Track all of the keys in this config and remove as they are processed
  492. // The remaining keys will be added to generic key-value storage for
  493. // whoever might need it
  494. HashSet<String> allKeys = new HashSet<String>();
  495. foreach (string s in config.GetKeys())
  496. {
  497. allKeys.Add(s);
  498. }
  499. // RegionUUID
  500. //
  501. allKeys.Remove("RegionUUID");
  502. string regionUUID = config.GetString("RegionUUID", string.Empty);
  503. if (!UUID.TryParse(regionUUID.Trim(), out RegionID))
  504. {
  505. UUID newID = UUID.Random();
  506. while (RegionID == UUID.Zero)
  507. {
  508. regionUUID = MainConsole.Instance.CmdPrompt("RegionUUID", newID.ToString());
  509. if (!UUID.TryParse(regionUUID.Trim(), out RegionID))
  510. {
  511. MainConsole.Instance.Output("RegionUUID must be a valid UUID");
  512. }
  513. }
  514. config.Set("RegionUUID", regionUUID);
  515. }
  516. originRegionID = RegionID; // What IS this?! (Needed for RegionCombinerModule?)
  517. // Location
  518. //
  519. allKeys.Remove("Location");
  520. string location = config.GetString("Location", String.Empty);
  521. if (location == String.Empty)
  522. {
  523. location = MainConsole.Instance.CmdPrompt("Region Location", "1000,1000");
  524. config.Set("Location", location);
  525. }
  526. string[] locationElements = location.Split(new char[] {','});
  527. RegionLocX = Convert.ToUInt32(locationElements[0]);
  528. RegionLocY = Convert.ToUInt32(locationElements[1]);
  529. // Region size
  530. // Default to legacy region size if not specified.
  531. allKeys.Remove("SizeX");
  532. string configSizeX = config.GetString("SizeX", Constants.RegionSize.ToString());
  533. config.Set("SizeX", configSizeX);
  534. RegionSizeX = Convert.ToUInt32(configSizeX);
  535. allKeys.Remove("SizeY");
  536. string configSizeY = config.GetString("SizeY", Constants.RegionSize.ToString());
  537. config.Set("SizeY", configSizeX);
  538. RegionSizeY = Convert.ToUInt32(configSizeY);
  539. allKeys.Remove("SizeZ");
  540. string configSizeZ = config.GetString("SizeZ", Constants.RegionHeight.ToString());
  541. config.Set("SizeZ", configSizeX);
  542. RegionSizeZ = Convert.ToUInt32(configSizeZ);
  543. DoRegionSizeSanityChecks();
  544. // InternalAddress
  545. //
  546. IPAddress address;
  547. allKeys.Remove("InternalAddress");
  548. if (config.Contains("InternalAddress"))
  549. {
  550. address = IPAddress.Parse(config.GetString("InternalAddress", String.Empty));
  551. }
  552. else
  553. {
  554. address = IPAddress.Parse(MainConsole.Instance.CmdPrompt("Internal IP address", "0.0.0.0"));
  555. config.Set("InternalAddress", address.ToString());
  556. }
  557. // InternalPort
  558. //
  559. int port;
  560. allKeys.Remove("InternalPort");
  561. if (config.Contains("InternalPort"))
  562. {
  563. port = config.GetInt("InternalPort", 9000);
  564. }
  565. else
  566. {
  567. port = Convert.ToInt32(MainConsole.Instance.CmdPrompt("Internal port", "9000"));
  568. config.Set("InternalPort", port);
  569. }
  570. m_internalEndPoint = new IPEndPoint(address, port);
  571. // AllowAlternatePorts
  572. //
  573. allKeys.Remove("AllowAlternatePorts");
  574. if (config.Contains("AllowAlternatePorts"))
  575. {
  576. m_allow_alternate_ports = config.GetBoolean("AllowAlternatePorts", true);
  577. }
  578. else
  579. {
  580. m_allow_alternate_ports = Convert.ToBoolean(MainConsole.Instance.CmdPrompt("Allow alternate ports", "False"));
  581. config.Set("AllowAlternatePorts", m_allow_alternate_ports.ToString());
  582. }
  583. // ExternalHostName
  584. //
  585. allKeys.Remove("ExternalHostName");
  586. string externalName;
  587. if (config.Contains("ExternalHostName"))
  588. {
  589. externalName = config.GetString("ExternalHostName", "SYSTEMIP");
  590. }
  591. else
  592. {
  593. externalName = MainConsole.Instance.CmdPrompt("External host name", "SYSTEMIP");
  594. config.Set("ExternalHostName", externalName);
  595. }
  596. if (externalName == "SYSTEMIP")
  597. {
  598. m_externalHostName = Util.GetLocalHost().ToString();
  599. m_log.InfoFormat(
  600. "[REGIONINFO]: Resolving SYSTEMIP to {0} for external hostname of region {1}",
  601. m_externalHostName, name);
  602. }
  603. else
  604. {
  605. m_externalHostName = externalName;
  606. }
  607. // RegionType
  608. m_regionType = config.GetString("RegionType", String.Empty);
  609. allKeys.Remove("RegionType");
  610. #region Prim and map stuff
  611. m_nonphysPrimMin = config.GetFloat("NonPhysicalPrimMin", 0);
  612. allKeys.Remove("NonPhysicalPrimMin");
  613. m_nonphysPrimMax = config.GetInt("NonPhysicalPrimMax", 0);
  614. allKeys.Remove("NonPhysicalPrimMax");
  615. m_physPrimMin = config.GetFloat("PhysicalPrimMin", 0);
  616. allKeys.Remove("PhysicalPrimMin");
  617. m_physPrimMax = config.GetInt("PhysicalPrimMax", 0);
  618. allKeys.Remove("PhysicalPrimMax");
  619. m_clampPrimSize = config.GetBoolean("ClampPrimSize", false);
  620. allKeys.Remove("ClampPrimSize");
  621. m_objectCapacity = config.GetInt("MaxPrims", 15000);
  622. allKeys.Remove("MaxPrims");
  623. m_maxPrimsPerUser = config.GetInt("MaxPrimsPerUser", -1);
  624. allKeys.Remove("MaxPrimsPerUser");
  625. m_linksetCapacity = config.GetInt("LinksetPrims", 0);
  626. allKeys.Remove("LinksetPrims");
  627. allKeys.Remove("MaptileStaticUUID");
  628. string mapTileStaticUUID = config.GetString("MaptileStaticUUID", UUID.Zero.ToString());
  629. if (UUID.TryParse(mapTileStaticUUID.Trim(), out m_maptileStaticUUID))
  630. {
  631. config.Set("MaptileStaticUUID", m_maptileStaticUUID.ToString());
  632. }
  633. MaptileStaticFile = config.GetString("MaptileStaticFile", String.Empty);
  634. allKeys.Remove("MaptileStaticFile");
  635. #endregion
  636. m_agentCapacity = config.GetInt("MaxAgents", 100);
  637. allKeys.Remove("MaxAgents");
  638. // Multi-tenancy
  639. //
  640. ScopeID = new UUID(config.GetString("ScopeID", UUID.Zero.ToString()));
  641. allKeys.Remove("ScopeID");
  642. foreach (String s in allKeys)
  643. {
  644. SetExtraSetting(s, config.GetString(s));
  645. }
  646. }
  647. // Make sure user specified region sizes are sane.
  648. // Must be multiples of legacy region size (256).
  649. private void DoRegionSizeSanityChecks()
  650. {
  651. if (RegionSizeX != Constants.RegionSize || RegionSizeY != Constants.RegionSize)
  652. {
  653. // Doing non-legacy region sizes.
  654. // Enforce region size to be multiples of the legacy region size (256)
  655. uint partial = RegionSizeX % Constants.RegionSize;
  656. if (partial != 0)
  657. {
  658. RegionSizeX -= partial;
  659. if (RegionSizeX == 0)
  660. RegionSizeX = Constants.RegionSize;
  661. m_log.ErrorFormat("{0} Region size must be multiple of {1}. Enforcing {2}.RegionSizeX={3} instead of specified {4}",
  662. LogHeader, Constants.RegionSize, m_regionName, RegionSizeX, RegionSizeX + partial);
  663. }
  664. partial = RegionSizeY % Constants.RegionSize;
  665. if (partial != 0)
  666. {
  667. RegionSizeY -= partial;
  668. if (RegionSizeY == 0)
  669. RegionSizeY = Constants.RegionSize;
  670. m_log.ErrorFormat("{0} Region size must be multiple of {1}. Enforcing {2}.RegionSizeY={3} instead of specified {4}",
  671. LogHeader, Constants.RegionSize, m_regionName, RegionSizeY, RegionSizeY + partial);
  672. }
  673. // Because of things in the viewer, regions MUST be square.
  674. // Remove this check when viewers have been updated.
  675. if (RegionSizeX != RegionSizeY)
  676. {
  677. uint minSize = Math.Min(RegionSizeX, RegionSizeY);
  678. RegionSizeX = minSize;
  679. RegionSizeY = minSize;
  680. m_log.ErrorFormat("{0} Regions must be square until viewers are updated. Forcing region {1} size to <{2},{3}>",
  681. LogHeader, m_regionName, RegionSizeX, RegionSizeY);
  682. }
  683. // There is a practical limit to region size.
  684. if (RegionSizeX > Constants.MaximumRegionSize || RegionSizeY > Constants.MaximumRegionSize)
  685. {
  686. RegionSizeX = Util.Clamp<uint>(RegionSizeX, Constants.RegionSize, Constants.MaximumRegionSize);
  687. RegionSizeY = Util.Clamp<uint>(RegionSizeY, Constants.RegionSize, Constants.MaximumRegionSize);
  688. m_log.ErrorFormat("{0} Region dimensions must be less than {1}. Clamping {2}'s size to <{3},{4}>",
  689. LogHeader, Constants.MaximumRegionSize, m_regionName, RegionSizeX, RegionSizeY);
  690. }
  691. m_log.InfoFormat("{0} Region {1} size set to <{2},{3}>", LogHeader, m_regionName, RegionSizeX, RegionSizeY);
  692. }
  693. }
  694. private void WriteNiniConfig(IConfigSource source)
  695. {
  696. IConfig config = source.Configs[RegionName];
  697. if (config != null)
  698. source.Configs.Remove(config);
  699. config = source.AddConfig(RegionName);
  700. config.Set("RegionUUID", RegionID.ToString());
  701. string location = String.Format("{0},{1}", RegionLocX, RegionLocY);
  702. config.Set("Location", location);
  703. if (RegionSizeX != Constants.RegionSize || RegionSizeY != Constants.RegionSize)
  704. {
  705. config.Set("SizeX", RegionSizeX);
  706. config.Set("SizeY", RegionSizeY);
  707. config.Set("SizeZ", RegionSizeZ);
  708. }
  709. config.Set("InternalAddress", m_internalEndPoint.Address.ToString());
  710. config.Set("InternalPort", m_internalEndPoint.Port);
  711. config.Set("AllowAlternatePorts", m_allow_alternate_ports.ToString());
  712. config.Set("ExternalHostName", m_externalHostName);
  713. if (m_nonphysPrimMin > 0)
  714. config.Set("NonphysicalPrimMax", m_nonphysPrimMin);
  715. if (m_nonphysPrimMax > 0)
  716. config.Set("NonphysicalPrimMax", m_nonphysPrimMax);
  717. if (m_physPrimMin > 0)
  718. config.Set("PhysicalPrimMax", m_physPrimMin);
  719. if (m_physPrimMax > 0)
  720. config.Set("PhysicalPrimMax", m_physPrimMax);
  721. config.Set("ClampPrimSize", m_clampPrimSize.ToString());
  722. if (m_objectCapacity > 0)
  723. config.Set("MaxPrims", m_objectCapacity);
  724. if (m_maxPrimsPerUser > -1)
  725. config.Set("MaxPrimsPerUser", m_maxPrimsPerUser);
  726. if (m_linksetCapacity > 0)
  727. config.Set("LinksetPrims", m_linksetCapacity);
  728. if (m_agentCapacity > 0)
  729. config.Set("MaxAgents", m_agentCapacity);
  730. if (ScopeID != UUID.Zero)
  731. config.Set("ScopeID", ScopeID.ToString());
  732. if (RegionType != String.Empty)
  733. config.Set("RegionType", RegionType);
  734. if (m_maptileStaticUUID != UUID.Zero)
  735. config.Set("MaptileStaticUUID", m_maptileStaticUUID.ToString());
  736. if (MaptileStaticFile != String.Empty)
  737. config.Set("MaptileStaticFile", MaptileStaticFile);
  738. }
  739. public void SaveRegionToFile(string description, string filename)
  740. {
  741. if (filename.ToLower().EndsWith(".ini"))
  742. {
  743. IniConfigSource source = new IniConfigSource();
  744. try
  745. {
  746. source = new IniConfigSource(filename); // Load if it exists
  747. }
  748. catch (Exception)
  749. {
  750. }
  751. WriteNiniConfig(source);
  752. source.Save(filename);
  753. return;
  754. }
  755. else
  756. throw new Exception("Invalid file type for region persistence.");
  757. }
  758. public void SaveLastMapUUID(UUID mapUUID)
  759. {
  760. lastMapUUID = mapUUID;
  761. lastMapRefresh = Util.UnixTimeSinceEpoch().ToString();
  762. }
  763. public OSDMap PackRegionInfoData()
  764. {
  765. OSDMap args = new OSDMap();
  766. args["region_id"] = OSD.FromUUID(RegionID);
  767. if ((RegionName != null) && !RegionName.Equals(""))
  768. args["region_name"] = OSD.FromString(RegionName);
  769. args["external_host_name"] = OSD.FromString(ExternalHostName);
  770. args["http_port"] = OSD.FromString(HttpPort.ToString());
  771. args["server_uri"] = OSD.FromString(ServerURI);
  772. args["region_xloc"] = OSD.FromString(RegionLocX.ToString());
  773. args["region_yloc"] = OSD.FromString(RegionLocY.ToString());
  774. args["region_size_x"] = OSD.FromString(RegionSizeX.ToString());
  775. args["region_size_y"] = OSD.FromString(RegionSizeY.ToString());
  776. args["region_size_z"] = OSD.FromString(RegionSizeZ.ToString());
  777. args["internal_ep_address"] = OSD.FromString(InternalEndPoint.Address.ToString());
  778. args["internal_ep_port"] = OSD.FromString(InternalEndPoint.Port.ToString());
  779. if ((RemotingAddress != null) && !RemotingAddress.Equals(""))
  780. args["remoting_address"] = OSD.FromString(RemotingAddress);
  781. args["remoting_port"] = OSD.FromString(RemotingPort.ToString());
  782. args["allow_alt_ports"] = OSD.FromBoolean(m_allow_alternate_ports);
  783. if ((proxyUrl != null) && !proxyUrl.Equals(""))
  784. args["proxy_url"] = OSD.FromString(proxyUrl);
  785. if (RegionType != String.Empty)
  786. args["region_type"] = OSD.FromString(RegionType);
  787. return args;
  788. }
  789. public void UnpackRegionInfoData(OSDMap args)
  790. {
  791. if (args["region_id"] != null)
  792. RegionID = args["region_id"].AsUUID();
  793. if (args["region_name"] != null)
  794. RegionName = args["region_name"].AsString();
  795. if (args["external_host_name"] != null)
  796. ExternalHostName = args["external_host_name"].AsString();
  797. if (args["http_port"] != null)
  798. UInt32.TryParse(args["http_port"].AsString(), out m_httpPort);
  799. if (args["server_uri"] != null)
  800. ServerURI = args["server_uri"].AsString();
  801. if (args["region_xloc"] != null)
  802. {
  803. uint locx;
  804. UInt32.TryParse(args["region_xloc"].AsString(), out locx);
  805. RegionLocX = locx;
  806. }
  807. if (args["region_yloc"] != null)
  808. {
  809. uint locy;
  810. UInt32.TryParse(args["region_yloc"].AsString(), out locy);
  811. RegionLocY = locy;
  812. }
  813. if (args.ContainsKey("region_size_x"))
  814. RegionSizeX = (uint)args["region_size_x"].AsInteger();
  815. if (args.ContainsKey("region_size_y"))
  816. RegionSizeY = (uint)args["region_size_y"].AsInteger();
  817. if (args.ContainsKey("region_size_z"))
  818. RegionSizeZ = (uint)args["region_size_z"].AsInteger();
  819. IPAddress ip_addr = null;
  820. if (args["internal_ep_address"] != null)
  821. {
  822. IPAddress.TryParse(args["internal_ep_address"].AsString(), out ip_addr);
  823. }
  824. int port = 0;
  825. if (args["internal_ep_port"] != null)
  826. {
  827. Int32.TryParse(args["internal_ep_port"].AsString(), out port);
  828. }
  829. InternalEndPoint = new IPEndPoint(ip_addr, port);
  830. if (args["remoting_address"] != null)
  831. RemotingAddress = args["remoting_address"].AsString();
  832. if (args["remoting_port"] != null)
  833. UInt32.TryParse(args["remoting_port"].AsString(), out m_remotingPort);
  834. if (args["allow_alt_ports"] != null)
  835. m_allow_alternate_ports = args["allow_alt_ports"].AsBoolean();
  836. if (args["proxy_url"] != null)
  837. proxyUrl = args["proxy_url"].AsString();
  838. if (args["region_type"] != null)
  839. m_regionType = args["region_type"].AsString();
  840. }
  841. public static RegionInfo Create(UUID regionID, string regionName, uint regX, uint regY, string externalHostName, uint httpPort, uint simPort, uint remotingPort, string serverURI)
  842. {
  843. RegionInfo regionInfo;
  844. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(externalHostName), (int)simPort);
  845. regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, externalHostName);
  846. regionInfo.RemotingPort = remotingPort;
  847. regionInfo.RemotingAddress = externalHostName;
  848. regionInfo.HttpPort = httpPort;
  849. regionInfo.RegionID = regionID;
  850. regionInfo.RegionName = regionName;
  851. regionInfo.ServerURI = serverURI;
  852. return regionInfo;
  853. }
  854. }
  855. }