RegionInfo.cs 53 KB

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