1
0

RegionInfo.cs 37 KB

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