RegionInfo.cs 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317
  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
  362. {
  363. // Old one defaults to IPv6
  364. //return new IPEndPoint(Dns.GetHostAddresses(m_externalHostName)[0], m_internalEndPoint.Port);
  365. IPAddress ia = null;
  366. // If it is already an IP, don't resolve it - just return directly
  367. if (IPAddress.TryParse(m_externalHostName, out ia))
  368. return new IPEndPoint(ia, m_internalEndPoint.Port);
  369. // Reset for next check
  370. ia = null;
  371. try
  372. {
  373. foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
  374. {
  375. if (ia == null)
  376. ia = Adr;
  377. if (Adr.AddressFamily == AddressFamily.InterNetwork)
  378. {
  379. ia = Adr;
  380. break;
  381. }
  382. }
  383. }
  384. catch (SocketException e)
  385. {
  386. throw new Exception(
  387. "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
  388. e + "' attached to this exception", e);
  389. }
  390. return new IPEndPoint(ia, m_internalEndPoint.Port);
  391. }
  392. set { m_externalHostName = value.ToString(); }
  393. }
  394. public string ExternalHostName
  395. {
  396. get { return m_externalHostName; }
  397. set { m_externalHostName = value; }
  398. }
  399. public IPEndPoint InternalEndPoint
  400. {
  401. get { return m_internalEndPoint; }
  402. set { m_internalEndPoint = value; }
  403. }
  404. /// <summary>
  405. /// The x co-ordinate of this region in map tiles (e.g. 1000).
  406. /// Coordinate is scaled as world coordinates divided by the legacy region size
  407. /// and is thus is the number of legacy regions.
  408. /// </summary>
  409. public uint RegionLocX
  410. {
  411. get { return WorldLocX / Constants.RegionSize; }
  412. set { WorldLocX = value * Constants.RegionSize; }
  413. }
  414. /// <summary>
  415. /// The y co-ordinate of this region in map tiles (e.g. 1000).
  416. /// Coordinate is scaled as world coordinates divided by the legacy region size
  417. /// and is thus is the number of legacy regions.
  418. /// </summary>
  419. public uint RegionLocY
  420. {
  421. get { return WorldLocY / Constants.RegionSize; }
  422. set { WorldLocY = value * Constants.RegionSize; }
  423. }
  424. public void SetDefaultRegionSize()
  425. {
  426. WorldLocX = 0;
  427. WorldLocY = 0;
  428. WorldLocZ = 0;
  429. RegionSizeX = Constants.RegionSize;
  430. RegionSizeY = Constants.RegionSize;
  431. RegionSizeZ = Constants.RegionHeight;
  432. }
  433. // A unique region handle is created from the region's world coordinates.
  434. // This cannot be changed because some code expects to receive the region handle and then
  435. // compute the region coordinates from it.
  436. public ulong RegionHandle
  437. {
  438. get { return Util.UIntsToLong(WorldLocX, WorldLocY); }
  439. }
  440. public void SetEndPoint(string ipaddr, int port)
  441. {
  442. IPAddress tmpIP = IPAddress.Parse(ipaddr);
  443. IPEndPoint tmpEPE = new IPEndPoint(tmpIP, port);
  444. m_internalEndPoint = tmpEPE;
  445. }
  446. public string GetSetting(string key)
  447. {
  448. string val;
  449. string keylower = key.ToLower();
  450. if (m_extraSettings.TryGetValue(keylower, out val))
  451. return val;
  452. m_log.DebugFormat("[RegionInfo] Could not locate value for parameter {0}", key);
  453. return null;
  454. }
  455. public void SetExtraSetting(string key, string value)
  456. {
  457. string keylower = key.ToLower();
  458. m_extraSettings[keylower] = value;
  459. }
  460. private void ReadNiniConfig(IConfigSource source, string name)
  461. {
  462. bool creatingNew = false;
  463. if (source.Configs.Count == 0)
  464. {
  465. MainConsole.Instance.Output("=====================================\n");
  466. MainConsole.Instance.Output("We are now going to ask a couple of questions about your region.\n");
  467. MainConsole.Instance.Output("You can press 'enter' without typing anything to use the default\n");
  468. MainConsole.Instance.Output("the default is displayed between [ ] brackets.\n");
  469. MainConsole.Instance.Output("=====================================\n");
  470. if (name == String.Empty)
  471. {
  472. while (name.Trim() == string.Empty)
  473. {
  474. name = MainConsole.Instance.CmdPrompt("New region name", name);
  475. if (name.Trim() == string.Empty)
  476. {
  477. MainConsole.Instance.Output("Cannot interactively create region with no name");
  478. }
  479. }
  480. }
  481. source.AddConfig(name);
  482. creatingNew = true;
  483. }
  484. if (name == String.Empty)
  485. name = source.Configs[0].Name;
  486. if (source.Configs[name] == null)
  487. {
  488. source.AddConfig(name);
  489. }
  490. RegionName = name;
  491. IConfig config = source.Configs[name];
  492. // Track all of the keys in this config and remove as they are processed
  493. // The remaining keys will be added to generic key-value storage for
  494. // whoever might need it
  495. HashSet<String> allKeys = new HashSet<String>();
  496. foreach (string s in config.GetKeys())
  497. {
  498. allKeys.Add(s);
  499. }
  500. // RegionUUID
  501. //
  502. allKeys.Remove("RegionUUID");
  503. string regionUUID = config.GetString("RegionUUID", string.Empty);
  504. if (!UUID.TryParse(regionUUID.Trim(), out RegionID))
  505. {
  506. UUID newID = UUID.Random();
  507. while (RegionID == UUID.Zero)
  508. {
  509. regionUUID = MainConsole.Instance.CmdPrompt("RegionUUID", newID.ToString());
  510. if (!UUID.TryParse(regionUUID.Trim(), out RegionID))
  511. {
  512. MainConsole.Instance.Output("RegionUUID must be a valid UUID");
  513. }
  514. }
  515. config.Set("RegionUUID", regionUUID);
  516. }
  517. originRegionID = RegionID; // What IS this?! (Needed for RegionCombinerModule?)
  518. // Location
  519. //
  520. allKeys.Remove("Location");
  521. string location = config.GetString("Location", String.Empty);
  522. if (location == String.Empty)
  523. {
  524. location = MainConsole.Instance.CmdPrompt("Region Location", "1000,1000");
  525. config.Set("Location", location);
  526. }
  527. string[] locationElements = location.Split(new char[] {','});
  528. RegionLocX = Convert.ToUInt32(locationElements[0]);
  529. RegionLocY = Convert.ToUInt32(locationElements[1]);
  530. // Region size
  531. // Default to legacy region size if not specified.
  532. allKeys.Remove("SizeX");
  533. string configSizeX = config.GetString("SizeX", Constants.RegionSize.ToString());
  534. config.Set("SizeX", configSizeX);
  535. RegionSizeX = Convert.ToUInt32(configSizeX);
  536. allKeys.Remove("SizeY");
  537. string configSizeY = config.GetString("SizeY", Constants.RegionSize.ToString());
  538. config.Set("SizeY", configSizeX);
  539. RegionSizeY = Convert.ToUInt32(configSizeY);
  540. allKeys.Remove("SizeZ");
  541. string configSizeZ = config.GetString("SizeZ", Constants.RegionHeight.ToString());
  542. config.Set("SizeZ", configSizeX);
  543. RegionSizeZ = Convert.ToUInt32(configSizeZ);
  544. DoRegionSizeSanityChecks();
  545. // InternalAddress
  546. //
  547. IPAddress address;
  548. allKeys.Remove("InternalAddress");
  549. if (config.Contains("InternalAddress"))
  550. {
  551. address = IPAddress.Parse(config.GetString("InternalAddress", String.Empty));
  552. }
  553. else
  554. {
  555. address = IPAddress.Parse(MainConsole.Instance.CmdPrompt("Internal IP address", "0.0.0.0"));
  556. config.Set("InternalAddress", address.ToString());
  557. }
  558. // InternalPort
  559. //
  560. int port;
  561. allKeys.Remove("InternalPort");
  562. if (config.Contains("InternalPort"))
  563. {
  564. port = config.GetInt("InternalPort", 9000);
  565. }
  566. else
  567. {
  568. port = Convert.ToInt32(MainConsole.Instance.CmdPrompt("Internal port", "9000"));
  569. config.Set("InternalPort", port);
  570. }
  571. m_internalEndPoint = new IPEndPoint(address, port);
  572. // ResolveAddress
  573. //
  574. allKeys.Remove("ResolveAddress");
  575. if (config.Contains("ResolveAddress"))
  576. {
  577. m_resolveAddress = config.GetBoolean("ResolveAddress", false);
  578. }
  579. else
  580. {
  581. if (creatingNew)
  582. m_resolveAddress = Convert.ToBoolean(MainConsole.Instance.CmdPrompt("Resolve hostname to IP on start (for running inside Docker)", "False"));
  583. config.Set("ResolveAddress", m_resolveAddress.ToString());
  584. }
  585. // ExternalHostName
  586. //
  587. allKeys.Remove("ExternalHostName");
  588. string externalName;
  589. if (config.Contains("ExternalHostName"))
  590. {
  591. externalName = config.GetString("ExternalHostName", "SYSTEMIP");
  592. }
  593. else
  594. {
  595. externalName = MainConsole.Instance.CmdPrompt("External host name", "SYSTEMIP");
  596. config.Set("ExternalHostName", externalName);
  597. }
  598. if (externalName == "SYSTEMIP")
  599. {
  600. m_externalHostName = Util.GetLocalHost().ToString();
  601. m_log.InfoFormat(
  602. "[REGIONINFO]: Resolving SYSTEMIP to {0} for external hostname of region {1}",
  603. m_externalHostName, name);
  604. }
  605. else if (!m_resolveAddress)
  606. {
  607. m_externalHostName = externalName;
  608. }
  609. else
  610. {
  611. IPAddress[] addrs = Dns.GetHostAddresses(externalName);
  612. if (addrs.Length != 1) // If it is ambiguous or not resolveable, use it literally
  613. m_externalHostName = externalName;
  614. else
  615. m_externalHostName = addrs[0].ToString();
  616. }
  617. // RegionType
  618. m_regionType = config.GetString("RegionType", String.Empty);
  619. allKeys.Remove("RegionType");
  620. // Get Default Landing Location (Defaults to 128,128)
  621. string temp_location = config.GetString("DefaultLanding", "<128, 128, 30>");
  622. Vector3 temp_vector;
  623. if (Vector3.TryParse(temp_location, out temp_vector))
  624. DefaultLandingPoint = temp_vector;
  625. else
  626. m_log.ErrorFormat("[RegionInfo]: Unable to parse DefaultLanding for '{0}'. The value given was '{1}'", RegionName, temp_location);
  627. allKeys.Remove("DefaultLanding");
  628. DoDefaultLandingSanityChecks();
  629. #region Prim and map stuff
  630. m_nonphysPrimMin = config.GetFloat("NonPhysicalPrimMin", 0);
  631. allKeys.Remove("NonPhysicalPrimMin");
  632. m_nonphysPrimMax = config.GetInt("NonPhysicalPrimMax", 0);
  633. allKeys.Remove("NonPhysicalPrimMax");
  634. m_physPrimMin = config.GetFloat("PhysicalPrimMin", 0);
  635. allKeys.Remove("PhysicalPrimMin");
  636. m_physPrimMax = config.GetInt("PhysicalPrimMax", 0);
  637. allKeys.Remove("PhysicalPrimMax");
  638. m_clampPrimSize = config.GetBoolean("ClampPrimSize", false);
  639. allKeys.Remove("ClampPrimSize");
  640. m_objectCapacity = config.GetInt("MaxPrims", m_objectCapacity);
  641. allKeys.Remove("MaxPrims");
  642. m_maxPrimsPerUser = config.GetInt("MaxPrimsPerUser", -1);
  643. allKeys.Remove("MaxPrimsPerUser");
  644. m_linksetCapacity = config.GetInt("LinksetPrims", 0);
  645. allKeys.Remove("LinksetPrims");
  646. allKeys.Remove("MaptileStaticUUID");
  647. string mapTileStaticUUID = config.GetString("MaptileStaticUUID", UUID.Zero.ToString());
  648. if (UUID.TryParse(mapTileStaticUUID.Trim(), out m_maptileStaticUUID))
  649. {
  650. config.Set("MaptileStaticUUID", m_maptileStaticUUID.ToString());
  651. }
  652. MaptileStaticFile = config.GetString("MaptileStaticFile", String.Empty);
  653. allKeys.Remove("MaptileStaticFile");
  654. #endregion
  655. AgentCapacity = config.GetInt("MaxAgents", 100);
  656. allKeys.Remove("MaxAgents");
  657. // Multi-tenancy
  658. //
  659. ScopeID = new UUID(config.GetString("ScopeID", UUID.Zero.ToString()));
  660. allKeys.Remove("ScopeID");
  661. foreach (String s in allKeys)
  662. {
  663. SetExtraSetting(s, config.GetString(s));
  664. }
  665. }
  666. // Make sure DefaultLanding is within region borders with a buffer zone 5 meters from borders
  667. private void DoDefaultLandingSanityChecks()
  668. {
  669. // Sanity Check Default Landing
  670. float buffer_zone = 5f;
  671. bool ValuesCapped = false;
  672. // Minimum Positions
  673. if (DefaultLandingPoint.X < buffer_zone)
  674. {
  675. DefaultLandingPoint.X = buffer_zone;
  676. ValuesCapped = true;
  677. }
  678. if (DefaultLandingPoint.Y < buffer_zone)
  679. {
  680. DefaultLandingPoint.Y = buffer_zone;
  681. ValuesCapped = true;
  682. }
  683. // Maximum Positions
  684. if (DefaultLandingPoint.X > RegionSizeX - buffer_zone)
  685. {
  686. DefaultLandingPoint.X = RegionSizeX - buffer_zone;
  687. ValuesCapped = true;
  688. }
  689. if (DefaultLandingPoint.Y > RegionSizeY - buffer_zone)
  690. {
  691. DefaultLandingPoint.Y = RegionSizeY - buffer_zone;
  692. ValuesCapped = true;
  693. }
  694. // Height
  695. if (DefaultLandingPoint.Z < 0f)
  696. DefaultLandingPoint.Z = 0f;
  697. if (ValuesCapped == true)
  698. m_log.WarnFormat("[RegionInfo]: The default landing location for {0} has been capped to {1}", RegionName, DefaultLandingPoint);
  699. }
  700. // Make sure user specified region sizes are sane.
  701. // Must be multiples of legacy region size (256).
  702. private void DoRegionSizeSanityChecks()
  703. {
  704. if (RegionSizeX != Constants.RegionSize || RegionSizeY != Constants.RegionSize)
  705. {
  706. // Doing non-legacy region sizes.
  707. // Enforce region size to be multiples of the legacy region size (256)
  708. uint partial = RegionSizeX % Constants.RegionSize;
  709. if (partial != 0)
  710. {
  711. RegionSizeX -= partial;
  712. if (RegionSizeX == 0)
  713. RegionSizeX = Constants.RegionSize;
  714. m_log.ErrorFormat("{0} Region size must be multiple of {1}. Enforcing {2}.RegionSizeX={3} instead of specified {4}",
  715. LogHeader, Constants.RegionSize, m_regionName, RegionSizeX, RegionSizeX + partial);
  716. }
  717. partial = RegionSizeY % Constants.RegionSize;
  718. if (partial != 0)
  719. {
  720. RegionSizeY -= partial;
  721. if (RegionSizeY == 0)
  722. RegionSizeY = Constants.RegionSize;
  723. m_log.ErrorFormat("{0} Region size must be multiple of {1}. Enforcing {2}.RegionSizeY={3} instead of specified {4}",
  724. LogHeader, Constants.RegionSize, m_regionName, RegionSizeY, RegionSizeY + partial);
  725. }
  726. // Because of things in the viewer, regions MUST be square.
  727. // Remove this check when viewers have been updated.
  728. if (RegionSizeX != RegionSizeY)
  729. {
  730. uint minSize = Math.Min(RegionSizeX, RegionSizeY);
  731. RegionSizeX = minSize;
  732. RegionSizeY = minSize;
  733. m_log.ErrorFormat("{0} Regions must be square until viewers are updated. Forcing region {1} size to <{2},{3}>",
  734. LogHeader, m_regionName, RegionSizeX, RegionSizeY);
  735. }
  736. // There is a practical limit to region size.
  737. if (RegionSizeX > Constants.MaximumRegionSize || RegionSizeY > Constants.MaximumRegionSize)
  738. {
  739. RegionSizeX = Util.Clamp<uint>(RegionSizeX, Constants.RegionSize, Constants.MaximumRegionSize);
  740. RegionSizeY = Util.Clamp<uint>(RegionSizeY, Constants.RegionSize, Constants.MaximumRegionSize);
  741. m_log.ErrorFormat("{0} Region dimensions must be less than {1}. Clamping {2}'s size to <{3},{4}>",
  742. LogHeader, Constants.MaximumRegionSize, m_regionName, RegionSizeX, RegionSizeY);
  743. }
  744. m_log.InfoFormat("{0} Region {1} size set to <{2},{3}>", LogHeader, m_regionName, RegionSizeX, RegionSizeY);
  745. }
  746. }
  747. private void WriteNiniConfig(IConfigSource source)
  748. {
  749. IConfig config = source.Configs[RegionName];
  750. if (config != null)
  751. source.Configs.Remove(config);
  752. config = source.AddConfig(RegionName);
  753. config.Set("RegionUUID", RegionID.ToString());
  754. string location = String.Format("{0},{1}", RegionLocX, RegionLocY);
  755. config.Set("Location", location);
  756. if (DataStore != String.Empty)
  757. config.Set("Datastore", DataStore);
  758. if (RegionSizeX != Constants.RegionSize || RegionSizeY != Constants.RegionSize)
  759. {
  760. config.Set("SizeX", RegionSizeX);
  761. config.Set("SizeY", RegionSizeY);
  762. // if (RegionSizeZ > 0)
  763. // config.Set("SizeZ", RegionSizeZ);
  764. }
  765. config.Set("InternalAddress", m_internalEndPoint.Address.ToString());
  766. config.Set("InternalPort", m_internalEndPoint.Port);
  767. config.Set("ExternalHostName", m_externalHostName);
  768. if (m_nonphysPrimMin > 0)
  769. config.Set("NonphysicalPrimMax", m_nonphysPrimMin);
  770. if (m_nonphysPrimMax > 0)
  771. config.Set("NonphysicalPrimMax", m_nonphysPrimMax);
  772. if (m_physPrimMin > 0)
  773. config.Set("PhysicalPrimMax", m_physPrimMin);
  774. if (m_physPrimMax > 0)
  775. config.Set("PhysicalPrimMax", m_physPrimMax);
  776. config.Set("ClampPrimSize", m_clampPrimSize.ToString());
  777. if (m_objectCapacity > 0)
  778. config.Set("MaxPrims", m_objectCapacity);
  779. if (m_maxPrimsPerUser > -1)
  780. config.Set("MaxPrimsPerUser", m_maxPrimsPerUser);
  781. if (m_linksetCapacity > 0)
  782. config.Set("LinksetPrims", m_linksetCapacity);
  783. if (AgentCapacity > 0)
  784. config.Set("MaxAgents", AgentCapacity);
  785. if (ScopeID != UUID.Zero)
  786. config.Set("ScopeID", ScopeID.ToString());
  787. if (RegionType != String.Empty)
  788. config.Set("RegionType", RegionType);
  789. if (m_maptileStaticUUID != UUID.Zero)
  790. config.Set("MaptileStaticUUID", m_maptileStaticUUID.ToString());
  791. if (MaptileStaticFile != null && MaptileStaticFile != String.Empty)
  792. config.Set("MaptileStaticFile", MaptileStaticFile);
  793. }
  794. public void SaveRegionToFile(string description, string filename)
  795. {
  796. if (filename.ToLower().EndsWith(".ini"))
  797. {
  798. IniConfigSource source = new IniConfigSource();
  799. try
  800. {
  801. source = new IniConfigSource(filename); // Load if it exists
  802. }
  803. catch (Exception)
  804. {
  805. }
  806. WriteNiniConfig(source);
  807. source.Save(filename);
  808. return;
  809. }
  810. else
  811. throw new Exception("Invalid file type for region persistence.");
  812. }
  813. public void loadConfigurationOptionsFromMe()
  814. {
  815. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID_NULL_FREE,
  816. "UUID of Region (Default is recommended, random UUID)",
  817. RegionID.ToString(), true);
  818. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  819. "Region Name", RegionName, true);
  820. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  821. "Grid Location (X Axis)", RegionLocX.ToString(), true);
  822. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  823. "Grid Location (Y Axis)", RegionLocY.ToString(), true);
  824. configMember.addConfigurationOption("sim_size_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  825. "Size of region in X dimension", RegionSizeX.ToString(), true);
  826. configMember.addConfigurationOption("sim_size_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  827. "Size of region in Y dimension", RegionSizeY.ToString(), true);
  828. configMember.addConfigurationOption("sim_size_z", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  829. "Size of region in Z dimension", RegionSizeZ.ToString(), true);
  830. //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  831. configMember.addConfigurationOption("internal_ip_address",
  832. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  833. "Internal IP Address for incoming UDP client connections",
  834. m_internalEndPoint.Address.ToString(),
  835. true);
  836. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  837. "Internal IP Port for incoming UDP client connections",
  838. m_internalEndPoint.Port.ToString(), true);
  839. configMember.addConfigurationOption("external_host_name",
  840. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  841. "External Host Name", m_externalHostName, true);
  842. configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  843. "Last Map UUID", lastMapUUID.ToString(), true);
  844. configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  845. "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
  846. configMember.addConfigurationOption("nonphysical_prim_min", ConfigurationOption.ConfigurationTypes.TYPE_FLOAT,
  847. "Minimum size for nonphysical prims", m_nonphysPrimMin.ToString(), true);
  848. configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  849. "Maximum size for nonphysical prims", m_nonphysPrimMax.ToString(), true);
  850. configMember.addConfigurationOption("physical_prim_min", ConfigurationOption.ConfigurationTypes.TYPE_FLOAT,
  851. "Minimum size for nonphysical prims", m_physPrimMin.ToString(), true);
  852. configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  853. "Maximum size for physical prims", m_physPrimMax.ToString(), true);
  854. configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  855. "Clamp prims to max size", m_clampPrimSize.ToString(), true);
  856. configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  857. "Max objects this sim will hold", m_objectCapacity.ToString(), true);
  858. configMember.addConfigurationOption("linkset_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  859. "Max prims an object will hold", m_linksetCapacity.ToString(), true);
  860. configMember.addConfigurationOption("agent_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  861. "Max avatars this sim will hold",AgentCapacity.ToString(), true);
  862. configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  863. "Scope ID for this region", ScopeID.ToString(), true);
  864. configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  865. "Free form string describing the type of region", String.Empty, true);
  866. configMember.addConfigurationOption("region_static_maptile", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  867. "UUID of a texture to use as the map for this region", m_maptileStaticUUID.ToString(), true);
  868. }
  869. public void loadConfigurationOptions()
  870. {
  871. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  872. "UUID of Region (Default is recommended, random UUID)",
  873. UUID.Random().ToString(), true);
  874. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  875. "Region Name", "OpenSim Test", false);
  876. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  877. "Grid Location (X Axis)", "1000", false);
  878. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  879. "Grid Location (Y Axis)", "1000", false);
  880. configMember.addConfigurationOption("sim_size_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  881. "Size of region in X dimension", Constants.RegionSize.ToString(), false);
  882. configMember.addConfigurationOption("sim_size_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  883. "Size of region in Y dimension", Constants.RegionSize.ToString(), false);
  884. configMember.addConfigurationOption("sim_size_z", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  885. "Size of region in Z dimension", Constants.RegionHeight.ToString(), false);
  886. //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  887. configMember.addConfigurationOption("internal_ip_address",
  888. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  889. "Internal IP Address for incoming UDP client connections", "0.0.0.0",
  890. false);
  891. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  892. "Internal IP Port for incoming UDP client connections",
  893. ConfigSettings.DefaultRegionHttpPort.ToString(), false);
  894. configMember.addConfigurationOption("external_host_name",
  895. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  896. "External Host Name", "127.0.0.1", false);
  897. configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  898. "Last Map UUID", lastMapUUID.ToString(), true);
  899. configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  900. "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
  901. configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  902. "Maximum size for nonphysical prims", "0", true);
  903. configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  904. "Maximum size for physical prims", "0", true);
  905. configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  906. "Clamp prims to max size", "false", true);
  907. configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  908. "Max objects this sim will hold", "15000", true);
  909. configMember.addConfigurationOption("agent_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  910. "Max avatars this sim will hold", "100", true);
  911. configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  912. "Scope ID for this region", UUID.Zero.ToString(), true);
  913. configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  914. "Region Type", String.Empty, true);
  915. configMember.addConfigurationOption("region_static_maptile", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  916. "UUID of a texture to use as the map for this region", String.Empty, true);
  917. }
  918. public bool handleIncomingConfiguration(string configuration_key, object configuration_result)
  919. {
  920. switch (configuration_key)
  921. {
  922. case "sim_UUID":
  923. RegionID = (UUID) configuration_result;
  924. originRegionID = (UUID) configuration_result;
  925. break;
  926. case "sim_name":
  927. RegionName = (string) configuration_result;
  928. break;
  929. case "sim_location_x":
  930. RegionLocX = (uint) configuration_result;
  931. break;
  932. case "sim_location_y":
  933. RegionLocY = (uint) configuration_result;
  934. break;
  935. case "sim_size_x":
  936. RegionSizeX = (uint) configuration_result;
  937. break;
  938. case "sim_size_y":
  939. RegionSizeY = (uint) configuration_result;
  940. break;
  941. case "sim_size_z":
  942. RegionSizeZ = (uint) configuration_result;
  943. break;
  944. case "datastore":
  945. DataStore = (string) configuration_result;
  946. break;
  947. case "internal_ip_address":
  948. IPAddress address = (IPAddress) configuration_result;
  949. m_internalEndPoint = new IPEndPoint(address, 0);
  950. break;
  951. case "internal_ip_port":
  952. m_internalEndPoint.Port = (int) configuration_result;
  953. break;
  954. case "external_host_name":
  955. if ((string) configuration_result != "SYSTEMIP")
  956. {
  957. m_externalHostName = (string) configuration_result;
  958. }
  959. else
  960. {
  961. m_externalHostName = Util.GetLocalHost().ToString();
  962. }
  963. break;
  964. case "lastmap_uuid":
  965. lastMapUUID = (UUID)configuration_result;
  966. break;
  967. case "lastmap_refresh":
  968. lastMapRefresh = (string)configuration_result;
  969. break;
  970. case "nonphysical_prim_max":
  971. m_nonphysPrimMax = (int)configuration_result;
  972. break;
  973. case "physical_prim_max":
  974. m_physPrimMax = (int)configuration_result;
  975. break;
  976. case "clamp_prim_size":
  977. m_clampPrimSize = (bool)configuration_result;
  978. break;
  979. case "object_capacity":
  980. m_objectCapacity = (int)configuration_result;
  981. break;
  982. case "linkset_capacity":
  983. m_linksetCapacity = (int)configuration_result;
  984. break;
  985. case "agent_capacity":
  986. AgentCapacity = (int)configuration_result;
  987. break;
  988. case "scope_id":
  989. ScopeID = (UUID)configuration_result;
  990. break;
  991. case "region_type":
  992. m_regionType = (string)configuration_result;
  993. break;
  994. case "region_static_maptile":
  995. m_maptileStaticUUID = (UUID)configuration_result;
  996. break;
  997. }
  998. return true;
  999. }
  1000. public void SaveLastMapUUID(UUID mapUUID)
  1001. {
  1002. lastMapUUID = mapUUID;
  1003. lastMapRefresh = Util.UnixTimeSinceEpoch().ToString();
  1004. }
  1005. public OSDMap PackRegionInfoData()
  1006. {
  1007. OSDMap args = new OSDMap();
  1008. args["region_id"] = OSD.FromUUID(RegionID);
  1009. if ((RegionName != null) && !RegionName.Equals(""))
  1010. args["region_name"] = OSD.FromString(RegionName);
  1011. args["external_host_name"] = OSD.FromString(ExternalHostName);
  1012. args["http_port"] = OSD.FromString(HttpPort.ToString());
  1013. args["server_uri"] = OSD.FromString(ServerURI);
  1014. args["region_xloc"] = OSD.FromString(RegionLocX.ToString());
  1015. args["region_yloc"] = OSD.FromString(RegionLocY.ToString());
  1016. args["region_size_x"] = OSD.FromString(RegionSizeX.ToString());
  1017. args["region_size_y"] = OSD.FromString(RegionSizeY.ToString());
  1018. args["region_size_z"] = OSD.FromString(RegionSizeZ.ToString());
  1019. args["internal_ep_address"] = OSD.FromString(InternalEndPoint.Address.ToString());
  1020. args["internal_ep_port"] = OSD.FromString(InternalEndPoint.Port.ToString());
  1021. if ((RemotingAddress != null) && !RemotingAddress.Equals(""))
  1022. args["remoting_address"] = OSD.FromString(RemotingAddress);
  1023. args["remoting_port"] = OSD.FromString(RemotingPort.ToString());
  1024. if ((proxyUrl != null) && !proxyUrl.Equals(""))
  1025. args["proxy_url"] = OSD.FromString(proxyUrl);
  1026. if (RegionType != String.Empty)
  1027. args["region_type"] = OSD.FromString(RegionType);
  1028. return args;
  1029. }
  1030. public void UnpackRegionInfoData(OSDMap args)
  1031. {
  1032. if (args["region_id"] != null)
  1033. RegionID = args["region_id"].AsUUID();
  1034. if (args["region_name"] != null)
  1035. RegionName = args["region_name"].AsString();
  1036. if (args["external_host_name"] != null)
  1037. ExternalHostName = args["external_host_name"].AsString();
  1038. if (args["http_port"] != null)
  1039. UInt32.TryParse(args["http_port"].AsString(), out m_httpPort);
  1040. if (args["server_uri"] != null)
  1041. ServerURI = args["server_uri"].AsString();
  1042. if (args["region_xloc"] != null)
  1043. {
  1044. uint locx;
  1045. UInt32.TryParse(args["region_xloc"].AsString(), out locx);
  1046. RegionLocX = locx;
  1047. }
  1048. if (args["region_yloc"] != null)
  1049. {
  1050. uint locy;
  1051. UInt32.TryParse(args["region_yloc"].AsString(), out locy);
  1052. RegionLocY = locy;
  1053. }
  1054. if (args.ContainsKey("region_size_x"))
  1055. RegionSizeX = (uint)args["region_size_x"].AsInteger();
  1056. if (args.ContainsKey("region_size_y"))
  1057. RegionSizeY = (uint)args["region_size_y"].AsInteger();
  1058. if (args.ContainsKey("region_size_z"))
  1059. RegionSizeZ = (uint)args["region_size_z"].AsInteger();
  1060. IPAddress ip_addr = null;
  1061. if (args["internal_ep_address"] != null)
  1062. {
  1063. IPAddress.TryParse(args["internal_ep_address"].AsString(), out ip_addr);
  1064. }
  1065. int port = 0;
  1066. if (args["internal_ep_port"] != null)
  1067. {
  1068. Int32.TryParse(args["internal_ep_port"].AsString(), out port);
  1069. }
  1070. InternalEndPoint = new IPEndPoint(ip_addr, port);
  1071. if (args["remoting_address"] != null)
  1072. RemotingAddress = args["remoting_address"].AsString();
  1073. if (args["remoting_port"] != null)
  1074. UInt32.TryParse(args["remoting_port"].AsString(), out m_remotingPort);
  1075. if (args["proxy_url"] != null)
  1076. proxyUrl = args["proxy_url"].AsString();
  1077. if (args["region_type"] != null)
  1078. m_regionType = args["region_type"].AsString();
  1079. }
  1080. public static RegionInfo Create(UUID regionID, string regionName, uint regX, uint regY, string externalHostName, uint httpPort, uint simPort, uint remotingPort, string serverURI)
  1081. {
  1082. RegionInfo regionInfo;
  1083. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(externalHostName), (int)simPort);
  1084. regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, externalHostName);
  1085. regionInfo.RemotingPort = remotingPort;
  1086. regionInfo.RemotingAddress = externalHostName;
  1087. regionInfo.HttpPort = httpPort;
  1088. regionInfo.RegionID = regionID;
  1089. regionInfo.RegionName = regionName;
  1090. regionInfo.ServerURI = serverURI;
  1091. return regionInfo;
  1092. }
  1093. public int getInternalEndPointPort()
  1094. {
  1095. return m_internalEndPoint.Port;
  1096. }
  1097. public Dictionary<string, object> ToKeyValuePairs()
  1098. {
  1099. Dictionary<string, object> kvp = new Dictionary<string, object>();
  1100. kvp["uuid"] = RegionID.ToString();
  1101. kvp["locX"] = RegionLocX.ToString();
  1102. kvp["locY"] = RegionLocY.ToString();
  1103. kvp["external_ip_address"] = ExternalEndPoint.Address.ToString();
  1104. kvp["external_port"] = ExternalEndPoint.Port.ToString();
  1105. kvp["external_host_name"] = ExternalHostName;
  1106. kvp["http_port"] = HttpPort.ToString();
  1107. kvp["internal_ip_address"] = InternalEndPoint.Address.ToString();
  1108. kvp["internal_port"] = InternalEndPoint.Port.ToString();
  1109. // TODO: Remove in next major version
  1110. kvp["alternate_ports"] = "False";
  1111. kvp["server_uri"] = ServerURI;
  1112. return kvp;
  1113. }
  1114. }
  1115. }