RegionInfo.cs 54 KB

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