RegionInfo.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Net;
  30. using System.Net.Sockets;
  31. using System.Reflection;
  32. using System.Xml;
  33. using System.IO;
  34. using log4net;
  35. using Nini.Config;
  36. using OpenMetaverse;
  37. using OpenMetaverse.StructuredData;
  38. //using OpenSim.Framework.Console;
  39. namespace OpenSim.Framework
  40. {
  41. public class RegionLightShareData : ICloneable
  42. {
  43. public bool valid = false;
  44. public UUID regionID = UUID.Zero;
  45. public Vector3 waterColor = new Vector3(4.0f,38.0f,64.0f);
  46. public float waterFogDensityExponent = 4.0f;
  47. public float underwaterFogModifier = 0.25f;
  48. public Vector3 reflectionWaveletScale = new Vector3(2.0f,2.0f,2.0f);
  49. public float fresnelScale = 0.40f;
  50. public float fresnelOffset = 0.50f;
  51. public float refractScaleAbove = 0.03f;
  52. public float refractScaleBelow = 0.20f;
  53. public float blurMultiplier = 0.040f;
  54. public Vector2 bigWaveDirection = new Vector2(1.05f,-0.42f);
  55. public Vector2 littleWaveDirection = new Vector2(1.11f,-1.16f);
  56. public UUID normalMapTexture = new UUID("822ded49-9a6c-f61c-cb89-6df54f42cdf4");
  57. public Vector4 horizon = new Vector4(0.25f, 0.25f, 0.32f, 0.32f);
  58. public float hazeHorizon = 0.19f;
  59. public Vector4 blueDensity = new Vector4(0.12f, 0.22f, 0.38f, 0.38f);
  60. public float hazeDensity = 0.70f;
  61. public float densityMultiplier = 0.18f;
  62. public float distanceMultiplier = 0.8f;
  63. public UInt16 maxAltitude = 1605;
  64. public Vector4 sunMoonColor = new Vector4(0.24f, 0.26f, 0.30f, 0.30f);
  65. public float sunMoonPosition = 0.317f;
  66. public Vector4 ambient = new Vector4(0.35f,0.35f,0.35f,0.35f);
  67. public float eastAngle = 0.0f;
  68. public float sunGlowFocus = 0.10f;
  69. public float sunGlowSize = 1.75f;
  70. public float sceneGamma = 1.0f;
  71. public float starBrightness = 0.0f;
  72. public Vector4 cloudColor = new Vector4(0.41f, 0.41f, 0.41f, 0.41f);
  73. public Vector3 cloudXYDensity = new Vector3(1.00f, 0.53f, 1.00f);
  74. public float cloudCoverage = 0.27f;
  75. public float cloudScale = 0.42f;
  76. public Vector3 cloudDetailXYDensity = new Vector3(1.00f, 0.53f, 0.12f);
  77. public float cloudScrollX = 0.20f;
  78. public bool cloudScrollXLock = false;
  79. public float cloudScrollY = 0.01f;
  80. public bool cloudScrollYLock = false;
  81. public bool drawClassicClouds = true;
  82. public delegate void SaveDelegate(RegionLightShareData wl);
  83. public event SaveDelegate OnSave;
  84. public void Save()
  85. {
  86. if (OnSave != null)
  87. OnSave(this);
  88. }
  89. public object Clone()
  90. {
  91. return this.MemberwiseClone(); // call clone method
  92. }
  93. }
  94. public class RegionInfo
  95. {
  96. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  97. public bool commFailTF = false;
  98. public ConfigurationMember configMember;
  99. public string RegionFile = String.Empty;
  100. public bool isSandbox = false;
  101. public bool Persistent = true;
  102. private EstateSettings m_estateSettings;
  103. private RegionSettings m_regionSettings;
  104. // private IConfigSource m_configSource = null;
  105. public UUID originRegionID = UUID.Zero;
  106. public string proxyUrl = "";
  107. public int ProxyOffset = 0;
  108. public string regionSecret = UUID.Random().ToString();
  109. public string osSecret;
  110. public UUID lastMapUUID = UUID.Zero;
  111. public string lastMapRefresh = "0";
  112. private float m_nonphysPrimMin = 0;
  113. private int m_nonphysPrimMax = 0;
  114. private float m_physPrimMin = 0;
  115. private int m_physPrimMax = 0;
  116. private bool m_clampPrimSize = false;
  117. private int m_objectCapacity = 0;
  118. private int m_linksetCapacity = 0;
  119. private int m_agentCapacity = 0;
  120. private string m_regionType = String.Empty;
  121. private RegionLightShareData m_windlight = new RegionLightShareData();
  122. protected uint m_httpPort;
  123. protected string m_serverURI;
  124. protected string m_regionName = String.Empty;
  125. protected bool Allow_Alternate_Ports;
  126. public bool m_allow_alternate_ports;
  127. protected string m_externalHostName;
  128. protected IPEndPoint m_internalEndPoint;
  129. protected uint? m_regionLocX;
  130. protected uint? m_regionLocY;
  131. protected uint m_remotingPort;
  132. public UUID RegionID = UUID.Zero;
  133. public string RemotingAddress;
  134. public UUID ScopeID = UUID.Zero;
  135. private UUID m_maptileStaticUUID = UUID.Zero;
  136. private Dictionary<String, String> m_otherSettings = new Dictionary<string, string>();
  137. // Apparently, we're applying the same estatesettings regardless of whether it's local or remote.
  138. // MT: Yes. Estates can't span trust boundaries. Therefore, it can be
  139. // assumed that all instances belonging to one estate are able to
  140. // access the same database server. Since estate settings are lodaed
  141. // from there, that should be sufficient for full remote administration
  142. // File based loading
  143. //
  144. public RegionInfo(string description, string filename, bool skipConsoleConfig, IConfigSource configSource) : this(description, filename, skipConsoleConfig, configSource, String.Empty)
  145. {
  146. }
  147. public RegionInfo(string description, string filename, bool skipConsoleConfig, IConfigSource configSource, string configName)
  148. {
  149. // m_configSource = configSource;
  150. if (filename.ToLower().EndsWith(".ini"))
  151. {
  152. if (!File.Exists(filename)) // New region config request
  153. {
  154. IniConfigSource newFile = new IniConfigSource();
  155. ReadNiniConfig(newFile, configName);
  156. newFile.Save(filename);
  157. RegionFile = filename;
  158. return;
  159. }
  160. IniConfigSource source = new IniConfigSource(filename);
  161. bool saveFile = false;
  162. if (source.Configs[configName] == null)
  163. saveFile = true;
  164. ReadNiniConfig(source, configName);
  165. if (configName != String.Empty && saveFile)
  166. source.Save(filename);
  167. RegionFile = filename;
  168. return;
  169. }
  170. try
  171. {
  172. // This will throw if it's not legal Nini XML format
  173. // and thereby toss it to the legacy loader
  174. //
  175. IConfigSource xmlsource = new XmlConfigSource(filename);
  176. ReadNiniConfig(xmlsource, configName);
  177. RegionFile = filename;
  178. return;
  179. }
  180. catch (Exception)
  181. {
  182. }
  183. configMember =
  184. new ConfigurationMember(filename, description, loadConfigurationOptions, handleIncomingConfiguration, !skipConsoleConfig);
  185. configMember.performConfigurationRetrieve();
  186. RegionFile = filename;
  187. }
  188. // The web loader uses this
  189. //
  190. public RegionInfo(string description, XmlNode xmlNode, bool skipConsoleConfig, IConfigSource configSource)
  191. {
  192. // m_configSource = configSource;
  193. configMember =
  194. new ConfigurationMember(xmlNode, description, loadConfigurationOptions, handleIncomingConfiguration, !skipConsoleConfig);
  195. configMember.performConfigurationRetrieve();
  196. m_serverURI = string.Empty;
  197. }
  198. public RegionInfo(uint regionLocX, uint regionLocY, IPEndPoint internalEndPoint, string externalUri)
  199. {
  200. m_regionLocX = regionLocX;
  201. m_regionLocY = regionLocY;
  202. m_internalEndPoint = internalEndPoint;
  203. m_externalHostName = externalUri;
  204. m_serverURI = string.Empty;
  205. }
  206. public RegionInfo()
  207. {
  208. m_serverURI = string.Empty;
  209. }
  210. public EstateSettings EstateSettings
  211. {
  212. get
  213. {
  214. if (m_estateSettings == null)
  215. {
  216. m_estateSettings = new EstateSettings();
  217. }
  218. return m_estateSettings;
  219. }
  220. set { m_estateSettings = value; }
  221. }
  222. public RegionSettings RegionSettings
  223. {
  224. get
  225. {
  226. if (m_regionSettings == null)
  227. {
  228. m_regionSettings = new RegionSettings();
  229. }
  230. return m_regionSettings;
  231. }
  232. set { m_regionSettings = value; }
  233. }
  234. public RegionLightShareData WindlightSettings
  235. {
  236. get
  237. {
  238. if (m_windlight == null)
  239. {
  240. m_windlight = new RegionLightShareData();
  241. }
  242. return m_windlight;
  243. }
  244. set { m_windlight = value; }
  245. }
  246. public float NonphysPrimMin
  247. {
  248. get { return m_nonphysPrimMin; }
  249. }
  250. public int NonphysPrimMax
  251. {
  252. get { return m_nonphysPrimMax; }
  253. }
  254. public float PhysPrimMin
  255. {
  256. get { return m_physPrimMin; }
  257. }
  258. public int PhysPrimMax
  259. {
  260. get { return m_physPrimMax; }
  261. }
  262. public bool ClampPrimSize
  263. {
  264. get { return m_clampPrimSize; }
  265. }
  266. public int ObjectCapacity
  267. {
  268. get { return m_objectCapacity; }
  269. }
  270. public int LinksetCapacity
  271. {
  272. get { return m_linksetCapacity; }
  273. }
  274. public int AgentCapacity
  275. {
  276. get { return m_agentCapacity; }
  277. }
  278. public byte AccessLevel
  279. {
  280. get { return (byte)Util.ConvertMaturityToAccessLevel((uint)RegionSettings.Maturity); }
  281. }
  282. public string RegionType
  283. {
  284. get { return m_regionType; }
  285. }
  286. public UUID MaptileStaticUUID
  287. {
  288. get { return m_maptileStaticUUID; }
  289. }
  290. /// <summary>
  291. /// The port by which http communication occurs with the region (most noticeably, CAPS communication)
  292. /// </summary>
  293. public uint HttpPort
  294. {
  295. get { return m_httpPort; }
  296. set { m_httpPort = value; }
  297. }
  298. /// <summary>
  299. /// A well-formed URI for the host region server (namely "http://" + ExternalHostName)
  300. /// </summary>
  301. public string ServerURI
  302. {
  303. get {
  304. if ( m_serverURI != string.Empty ) {
  305. return m_serverURI;
  306. } else {
  307. return "http://" + m_externalHostName + ":" + m_httpPort + "/";
  308. }
  309. }
  310. set {
  311. if ( value.EndsWith("/") ) {
  312. m_serverURI = value;
  313. } else {
  314. m_serverURI = value + '/';
  315. }
  316. }
  317. }
  318. public string RegionName
  319. {
  320. get { return m_regionName; }
  321. set { m_regionName = value; }
  322. }
  323. public uint RemotingPort
  324. {
  325. get { return m_remotingPort; }
  326. set { m_remotingPort = value; }
  327. }
  328. /// <value>
  329. /// This accessor can throw all the exceptions that Dns.GetHostAddresses can throw.
  330. ///
  331. /// XXX Isn't this really doing too much to be a simple getter, rather than an explict method?
  332. /// </value>
  333. public IPEndPoint ExternalEndPoint
  334. {
  335. get
  336. {
  337. // Old one defaults to IPv6
  338. //return new IPEndPoint(Dns.GetHostAddresses(m_externalHostName)[0], m_internalEndPoint.Port);
  339. IPAddress ia = null;
  340. // If it is already an IP, don't resolve it - just return directly
  341. if (IPAddress.TryParse(m_externalHostName, out ia))
  342. return new IPEndPoint(ia, m_internalEndPoint.Port);
  343. // Reset for next check
  344. ia = null;
  345. try
  346. {
  347. foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
  348. {
  349. if (ia == null)
  350. ia = Adr;
  351. if (Adr.AddressFamily == AddressFamily.InterNetwork)
  352. {
  353. ia = Adr;
  354. break;
  355. }
  356. }
  357. }
  358. catch (SocketException e)
  359. {
  360. throw new Exception(
  361. "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
  362. e + "' attached to this exception", e);
  363. }
  364. return new IPEndPoint(ia, m_internalEndPoint.Port);
  365. }
  366. set { m_externalHostName = value.ToString(); }
  367. }
  368. public string ExternalHostName
  369. {
  370. get { return m_externalHostName; }
  371. set { m_externalHostName = value; }
  372. }
  373. public IPEndPoint InternalEndPoint
  374. {
  375. get { return m_internalEndPoint; }
  376. set { m_internalEndPoint = value; }
  377. }
  378. /// <summary>
  379. /// The x co-ordinate of this region in map tiles (e.g. 1000).
  380. /// </summary>
  381. public uint RegionLocX
  382. {
  383. get { return m_regionLocX.Value; }
  384. set { m_regionLocX = value; }
  385. }
  386. /// <summary>
  387. /// The y co-ordinate of this region in map tiles (e.g. 1000).
  388. /// </summary>
  389. public uint RegionLocY
  390. {
  391. get { return m_regionLocY.Value; }
  392. set { m_regionLocY = value; }
  393. }
  394. public ulong RegionHandle
  395. {
  396. get { return Util.UIntsToLong((RegionLocX * (uint) Constants.RegionSize), (RegionLocY * (uint) Constants.RegionSize)); }
  397. }
  398. public void SetEndPoint(string ipaddr, int port)
  399. {
  400. IPAddress tmpIP = IPAddress.Parse(ipaddr);
  401. IPEndPoint tmpEPE = new IPEndPoint(tmpIP, port);
  402. m_internalEndPoint = tmpEPE;
  403. }
  404. public string GetOtherSetting(string key)
  405. {
  406. string val;
  407. string keylower = key.ToLower();
  408. if (m_otherSettings.TryGetValue(keylower, out val))
  409. return val;
  410. m_log.DebugFormat("[RegionInfo] Could not locate value for parameter {0}", key);
  411. return null;
  412. }
  413. public void SetOtherSetting(string key, string value)
  414. {
  415. string keylower = key.ToLower();
  416. m_otherSettings[keylower] = value;
  417. }
  418. private void ReadNiniConfig(IConfigSource source, string name)
  419. {
  420. // bool creatingNew = false;
  421. if (source.Configs.Count == 0)
  422. {
  423. MainConsole.Instance.Output("=====================================\n");
  424. MainConsole.Instance.Output("We are now going to ask a couple of questions about your region.\n");
  425. MainConsole.Instance.Output("You can press 'enter' without typing anything to use the default\n");
  426. MainConsole.Instance.Output("the default is displayed between [ ] brackets.\n");
  427. MainConsole.Instance.Output("=====================================\n");
  428. if (name == String.Empty)
  429. {
  430. while (name.Trim() == string.Empty)
  431. {
  432. name = MainConsole.Instance.CmdPrompt("New region name", name);
  433. if (name.Trim() == string.Empty)
  434. {
  435. MainConsole.Instance.Output("Cannot interactively create region with no name");
  436. }
  437. }
  438. }
  439. source.AddConfig(name);
  440. // creatingNew = true;
  441. }
  442. if (name == String.Empty)
  443. name = source.Configs[0].Name;
  444. if (source.Configs[name] == null)
  445. {
  446. source.AddConfig(name);
  447. }
  448. RegionName = name;
  449. IConfig config = source.Configs[name];
  450. // Track all of the keys in this config and remove as they are processed
  451. // The remaining keys will be added to generic key-value storage for
  452. // whoever might need it
  453. HashSet<String> allKeys = new HashSet<String>();
  454. foreach (string s in config.GetKeys())
  455. {
  456. allKeys.Add(s);
  457. }
  458. // RegionUUID
  459. //
  460. allKeys.Remove("RegionUUID");
  461. string regionUUID = config.GetString("RegionUUID", string.Empty);
  462. if (!UUID.TryParse(regionUUID.Trim(), out RegionID))
  463. {
  464. UUID newID = UUID.Random();
  465. while (RegionID == UUID.Zero)
  466. {
  467. regionUUID = MainConsole.Instance.CmdPrompt("RegionUUID", newID.ToString());
  468. if (!UUID.TryParse(regionUUID.Trim(), out RegionID))
  469. {
  470. MainConsole.Instance.Output("RegionUUID must be a valid UUID");
  471. }
  472. }
  473. config.Set("RegionUUID", regionUUID);
  474. }
  475. originRegionID = RegionID; // What IS this?! (Needed for RegionCombinerModule?)
  476. // Location
  477. //
  478. allKeys.Remove("Location");
  479. string location = config.GetString("Location", String.Empty);
  480. if (location == String.Empty)
  481. {
  482. location = MainConsole.Instance.CmdPrompt("Region Location", "1000,1000");
  483. config.Set("Location", location);
  484. }
  485. string[] locationElements = location.Split(new char[] {','});
  486. m_regionLocX = Convert.ToUInt32(locationElements[0]);
  487. m_regionLocY = Convert.ToUInt32(locationElements[1]);
  488. // InternalAddress
  489. //
  490. IPAddress address;
  491. allKeys.Remove("InternalAddress");
  492. if (config.Contains("InternalAddress"))
  493. {
  494. address = IPAddress.Parse(config.GetString("InternalAddress", String.Empty));
  495. }
  496. else
  497. {
  498. address = IPAddress.Parse(MainConsole.Instance.CmdPrompt("Internal IP address", "0.0.0.0"));
  499. config.Set("InternalAddress", address.ToString());
  500. }
  501. // InternalPort
  502. //
  503. int port;
  504. allKeys.Remove("InternalPort");
  505. if (config.Contains("InternalPort"))
  506. {
  507. port = config.GetInt("InternalPort", 9000);
  508. }
  509. else
  510. {
  511. port = Convert.ToInt32(MainConsole.Instance.CmdPrompt("Internal port", "9000"));
  512. config.Set("InternalPort", port);
  513. }
  514. m_internalEndPoint = new IPEndPoint(address, port);
  515. // AllowAlternatePorts
  516. //
  517. allKeys.Remove("AllowAlternatePorts");
  518. if (config.Contains("AllowAlternatePorts"))
  519. {
  520. m_allow_alternate_ports = config.GetBoolean("AllowAlternatePorts", true);
  521. }
  522. else
  523. {
  524. m_allow_alternate_ports = Convert.ToBoolean(MainConsole.Instance.CmdPrompt("Allow alternate ports", "False"));
  525. config.Set("AllowAlternatePorts", m_allow_alternate_ports.ToString());
  526. }
  527. // ExternalHostName
  528. //
  529. allKeys.Remove("ExternalHostName");
  530. string externalName;
  531. if (config.Contains("ExternalHostName"))
  532. {
  533. externalName = config.GetString("ExternalHostName", "SYSTEMIP");
  534. }
  535. else
  536. {
  537. externalName = MainConsole.Instance.CmdPrompt("External host name", "SYSTEMIP");
  538. config.Set("ExternalHostName", externalName);
  539. }
  540. if (externalName == "SYSTEMIP")
  541. {
  542. m_externalHostName = Util.GetLocalHost().ToString();
  543. m_log.InfoFormat(
  544. "[REGIONINFO]: Resolving SYSTEMIP to {0} for external hostname of region {1}",
  545. m_externalHostName, name);
  546. }
  547. else
  548. {
  549. m_externalHostName = externalName;
  550. }
  551. // RegionType
  552. m_regionType = config.GetString("RegionType", String.Empty);
  553. allKeys.Remove("RegionType");
  554. #region Prim and map stuff
  555. m_nonphysPrimMin = config.GetFloat("NonPhysicalPrimMin", 0);
  556. allKeys.Remove("NonPhysicalPrimMin");
  557. m_nonphysPrimMax = config.GetInt("NonPhysicalPrimMax", 0);
  558. allKeys.Remove("NonPhysicalPrimMax");
  559. m_physPrimMin = config.GetFloat("PhysicalPrimMin", 0);
  560. allKeys.Remove("PhysicalPrimMin");
  561. m_physPrimMax = config.GetInt("PhysicalPrimMax", 0);
  562. allKeys.Remove("PhysicalPrimMax");
  563. m_clampPrimSize = config.GetBoolean("ClampPrimSize", false);
  564. allKeys.Remove("ClampPrimSize");
  565. m_objectCapacity = config.GetInt("MaxPrims", 15000);
  566. allKeys.Remove("MaxPrims");
  567. m_linksetCapacity = config.GetInt("LinksetPrims", 0);
  568. allKeys.Remove("LinksetPrims");
  569. allKeys.Remove("MaptileStaticUUID");
  570. string mapTileStaticUUID = config.GetString("MaptileStaticUUID", UUID.Zero.ToString());
  571. if (UUID.TryParse(mapTileStaticUUID.Trim(), out m_maptileStaticUUID))
  572. {
  573. config.Set("MaptileStaticUUID", m_maptileStaticUUID.ToString());
  574. }
  575. #endregion
  576. m_agentCapacity = config.GetInt("MaxAgents", 100);
  577. allKeys.Remove("MaxAgents");
  578. // Multi-tenancy
  579. //
  580. ScopeID = new UUID(config.GetString("ScopeID", UUID.Zero.ToString()));
  581. allKeys.Remove("ScopeID");
  582. foreach (String s in allKeys)
  583. {
  584. SetOtherSetting(s, config.GetString(s));
  585. }
  586. }
  587. private void WriteNiniConfig(IConfigSource source)
  588. {
  589. IConfig config = source.Configs[RegionName];
  590. if (config != null)
  591. source.Configs.Remove(config);
  592. config = source.AddConfig(RegionName);
  593. config.Set("RegionUUID", RegionID.ToString());
  594. string location = String.Format("{0},{1}", m_regionLocX, m_regionLocY);
  595. config.Set("Location", location);
  596. config.Set("InternalAddress", m_internalEndPoint.Address.ToString());
  597. config.Set("InternalPort", m_internalEndPoint.Port);
  598. config.Set("AllowAlternatePorts", m_allow_alternate_ports.ToString());
  599. config.Set("ExternalHostName", m_externalHostName);
  600. if (m_nonphysPrimMin > 0)
  601. config.Set("NonphysicalPrimMax", m_nonphysPrimMin);
  602. if (m_nonphysPrimMax > 0)
  603. config.Set("NonphysicalPrimMax", m_nonphysPrimMax);
  604. if (m_physPrimMin > 0)
  605. config.Set("PhysicalPrimMax", m_physPrimMin);
  606. if (m_physPrimMax > 0)
  607. config.Set("PhysicalPrimMax", m_physPrimMax);
  608. config.Set("ClampPrimSize", m_clampPrimSize.ToString());
  609. if (m_objectCapacity > 0)
  610. config.Set("MaxPrims", m_objectCapacity);
  611. if (m_linksetCapacity > 0)
  612. config.Set("LinksetPrims", m_linksetCapacity);
  613. if (m_agentCapacity > 0)
  614. config.Set("MaxAgents", m_agentCapacity);
  615. if (ScopeID != UUID.Zero)
  616. config.Set("ScopeID", ScopeID.ToString());
  617. if (RegionType != String.Empty)
  618. config.Set("RegionType", RegionType);
  619. if (m_maptileStaticUUID != UUID.Zero)
  620. config.Set("MaptileStaticUUID", m_maptileStaticUUID.ToString());
  621. }
  622. public bool ignoreIncomingConfiguration(string configuration_key, object configuration_result)
  623. {
  624. return true;
  625. }
  626. public void SaveRegionToFile(string description, string filename)
  627. {
  628. if (filename.ToLower().EndsWith(".ini"))
  629. {
  630. IniConfigSource source = new IniConfigSource();
  631. try
  632. {
  633. source = new IniConfigSource(filename); // Load if it exists
  634. }
  635. catch (Exception)
  636. {
  637. }
  638. WriteNiniConfig(source);
  639. source.Save(filename);
  640. return;
  641. }
  642. else if (filename.ToLower().EndsWith(".xml"))
  643. {
  644. configMember = new ConfigurationMember(filename, description, loadConfigurationOptionsFromMe,
  645. ignoreIncomingConfiguration, false);
  646. configMember.performConfigurationRetrieve();
  647. RegionFile = filename;
  648. }
  649. else
  650. throw new Exception("Invalid file type for region persistence.");
  651. }
  652. public void loadConfigurationOptionsFromMe()
  653. {
  654. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID_NULL_FREE,
  655. "UUID of Region (Default is recommended, random UUID)",
  656. RegionID.ToString(), true);
  657. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  658. "Region Name", RegionName, true);
  659. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  660. "Grid Location (X Axis)", m_regionLocX.ToString(), true);
  661. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  662. "Grid Location (Y Axis)", m_regionLocY.ToString(), true);
  663. //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  664. configMember.addConfigurationOption("internal_ip_address",
  665. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  666. "Internal IP Address for incoming UDP client connections",
  667. m_internalEndPoint.Address.ToString(),
  668. true);
  669. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  670. "Internal IP Port for incoming UDP client connections",
  671. m_internalEndPoint.Port.ToString(), true);
  672. configMember.addConfigurationOption("allow_alternate_ports",
  673. ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  674. "Allow sim to find alternate UDP ports when ports are in use?",
  675. m_allow_alternate_ports.ToString(), true);
  676. configMember.addConfigurationOption("external_host_name",
  677. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  678. "External Host Name", m_externalHostName, true);
  679. configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  680. "Last Map UUID", lastMapUUID.ToString(), true);
  681. configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  682. "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
  683. configMember.addConfigurationOption("nonphysical_prim_min", ConfigurationOption.ConfigurationTypes.TYPE_FLOAT,
  684. "Minimum size for nonphysical prims", m_nonphysPrimMin.ToString(), true);
  685. configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  686. "Maximum size for nonphysical prims", m_nonphysPrimMax.ToString(), true);
  687. configMember.addConfigurationOption("physical_prim_min", ConfigurationOption.ConfigurationTypes.TYPE_FLOAT,
  688. "Minimum size for nonphysical prims", m_physPrimMin.ToString(), true);
  689. configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  690. "Maximum size for physical prims", m_physPrimMax.ToString(), true);
  691. configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  692. "Clamp prims to max size", m_clampPrimSize.ToString(), true);
  693. configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  694. "Max objects this sim will hold", m_objectCapacity.ToString(), true);
  695. configMember.addConfigurationOption("linkset_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  696. "Max prims an object will hold", m_linksetCapacity.ToString(), true);
  697. configMember.addConfigurationOption("agent_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  698. "Max avatars this sim will hold", m_agentCapacity.ToString(), true);
  699. configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  700. "Scope ID for this region", ScopeID.ToString(), true);
  701. configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  702. "Free form string describing the type of region", String.Empty, true);
  703. configMember.addConfigurationOption("region_static_maptile", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  704. "UUID of a texture to use as the map for this region", m_maptileStaticUUID.ToString(), true);
  705. }
  706. public void loadConfigurationOptions()
  707. {
  708. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  709. "UUID of Region (Default is recommended, random UUID)",
  710. UUID.Random().ToString(), true);
  711. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  712. "Region Name", "OpenSim Test", false);
  713. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  714. "Grid Location (X Axis)", "1000", false);
  715. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  716. "Grid Location (Y Axis)", "1000", false);
  717. //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  718. configMember.addConfigurationOption("internal_ip_address",
  719. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  720. "Internal IP Address for incoming UDP client connections", "0.0.0.0",
  721. false);
  722. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  723. "Internal IP Port for incoming UDP client connections",
  724. ConfigSettings.DefaultRegionHttpPort.ToString(), false);
  725. configMember.addConfigurationOption("allow_alternate_ports", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  726. "Allow sim to find alternate UDP ports when ports are in use?",
  727. "false", true);
  728. configMember.addConfigurationOption("external_host_name",
  729. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  730. "External Host Name", "127.0.0.1", false);
  731. configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  732. "Last Map UUID", lastMapUUID.ToString(), true);
  733. configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  734. "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
  735. configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  736. "Maximum size for nonphysical prims", "0", true);
  737. configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  738. "Maximum size for physical prims", "0", true);
  739. configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  740. "Clamp prims to max size", "false", true);
  741. configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  742. "Max objects this sim will hold", "15000", true);
  743. configMember.addConfigurationOption("agent_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  744. "Max avatars this sim will hold", "100", true);
  745. configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  746. "Scope ID for this region", UUID.Zero.ToString(), true);
  747. configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  748. "Region Type", String.Empty, true);
  749. configMember.addConfigurationOption("region_static_maptile", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  750. "UUID of a texture to use as the map for this region", String.Empty, true);
  751. }
  752. public bool handleIncomingConfiguration(string configuration_key, object configuration_result)
  753. {
  754. switch (configuration_key)
  755. {
  756. case "sim_UUID":
  757. RegionID = (UUID) configuration_result;
  758. originRegionID = (UUID) configuration_result;
  759. break;
  760. case "sim_name":
  761. RegionName = (string) configuration_result;
  762. break;
  763. case "sim_location_x":
  764. m_regionLocX = (uint) configuration_result;
  765. break;
  766. case "sim_location_y":
  767. m_regionLocY = (uint) configuration_result;
  768. break;
  769. case "internal_ip_address":
  770. IPAddress address = (IPAddress) configuration_result;
  771. m_internalEndPoint = new IPEndPoint(address, 0);
  772. break;
  773. case "internal_ip_port":
  774. m_internalEndPoint.Port = (int) configuration_result;
  775. break;
  776. case "allow_alternate_ports":
  777. m_allow_alternate_ports = (bool) configuration_result;
  778. break;
  779. case "external_host_name":
  780. if ((string) configuration_result != "SYSTEMIP")
  781. {
  782. m_externalHostName = (string) configuration_result;
  783. }
  784. else
  785. {
  786. m_externalHostName = Util.GetLocalHost().ToString();
  787. }
  788. break;
  789. case "lastmap_uuid":
  790. lastMapUUID = (UUID)configuration_result;
  791. break;
  792. case "lastmap_refresh":
  793. lastMapRefresh = (string)configuration_result;
  794. break;
  795. case "nonphysical_prim_max":
  796. m_nonphysPrimMax = (int)configuration_result;
  797. break;
  798. case "physical_prim_max":
  799. m_physPrimMax = (int)configuration_result;
  800. break;
  801. case "clamp_prim_size":
  802. m_clampPrimSize = (bool)configuration_result;
  803. break;
  804. case "object_capacity":
  805. m_objectCapacity = (int)configuration_result;
  806. break;
  807. case "linkset_capacity":
  808. m_linksetCapacity = (int)configuration_result;
  809. break;
  810. case "agent_capacity":
  811. m_agentCapacity = (int)configuration_result;
  812. break;
  813. case "scope_id":
  814. ScopeID = (UUID)configuration_result;
  815. break;
  816. case "region_type":
  817. m_regionType = (string)configuration_result;
  818. break;
  819. case "region_static_maptile":
  820. m_maptileStaticUUID = (UUID)configuration_result;
  821. break;
  822. }
  823. return true;
  824. }
  825. public void SaveLastMapUUID(UUID mapUUID)
  826. {
  827. lastMapUUID = mapUUID;
  828. lastMapRefresh = Util.UnixTimeSinceEpoch().ToString();
  829. if (configMember == null)
  830. return;
  831. configMember.forceSetConfigurationOption("lastmap_uuid", mapUUID.ToString());
  832. configMember.forceSetConfigurationOption("lastmap_refresh", lastMapRefresh);
  833. }
  834. public OSDMap PackRegionInfoData()
  835. {
  836. OSDMap args = new OSDMap();
  837. args["region_id"] = OSD.FromUUID(RegionID);
  838. if ((RegionName != null) && !RegionName.Equals(""))
  839. args["region_name"] = OSD.FromString(RegionName);
  840. args["external_host_name"] = OSD.FromString(ExternalHostName);
  841. args["http_port"] = OSD.FromString(HttpPort.ToString());
  842. args["server_uri"] = OSD.FromString(ServerURI);
  843. args["region_xloc"] = OSD.FromString(RegionLocX.ToString());
  844. args["region_yloc"] = OSD.FromString(RegionLocY.ToString());
  845. args["internal_ep_address"] = OSD.FromString(InternalEndPoint.Address.ToString());
  846. args["internal_ep_port"] = OSD.FromString(InternalEndPoint.Port.ToString());
  847. if ((RemotingAddress != null) && !RemotingAddress.Equals(""))
  848. args["remoting_address"] = OSD.FromString(RemotingAddress);
  849. args["remoting_port"] = OSD.FromString(RemotingPort.ToString());
  850. args["allow_alt_ports"] = OSD.FromBoolean(m_allow_alternate_ports);
  851. if ((proxyUrl != null) && !proxyUrl.Equals(""))
  852. args["proxy_url"] = OSD.FromString(proxyUrl);
  853. if (RegionType != String.Empty)
  854. args["region_type"] = OSD.FromString(RegionType);
  855. return args;
  856. }
  857. public void UnpackRegionInfoData(OSDMap args)
  858. {
  859. if (args["region_id"] != null)
  860. RegionID = args["region_id"].AsUUID();
  861. if (args["region_name"] != null)
  862. RegionName = args["region_name"].AsString();
  863. if (args["external_host_name"] != null)
  864. ExternalHostName = args["external_host_name"].AsString();
  865. if (args["http_port"] != null)
  866. UInt32.TryParse(args["http_port"].AsString(), out m_httpPort);
  867. if (args["server_uri"] != null)
  868. ServerURI = args["server_uri"].AsString();
  869. if (args["region_xloc"] != null)
  870. {
  871. uint locx;
  872. UInt32.TryParse(args["region_xloc"].AsString(), out locx);
  873. RegionLocX = locx;
  874. }
  875. if (args["region_yloc"] != null)
  876. {
  877. uint locy;
  878. UInt32.TryParse(args["region_yloc"].AsString(), out locy);
  879. RegionLocY = locy;
  880. }
  881. IPAddress ip_addr = null;
  882. if (args["internal_ep_address"] != null)
  883. {
  884. IPAddress.TryParse(args["internal_ep_address"].AsString(), out ip_addr);
  885. }
  886. int port = 0;
  887. if (args["internal_ep_port"] != null)
  888. {
  889. Int32.TryParse(args["internal_ep_port"].AsString(), out port);
  890. }
  891. InternalEndPoint = new IPEndPoint(ip_addr, port);
  892. if (args["remoting_address"] != null)
  893. RemotingAddress = args["remoting_address"].AsString();
  894. if (args["remoting_port"] != null)
  895. UInt32.TryParse(args["remoting_port"].AsString(), out m_remotingPort);
  896. if (args["allow_alt_ports"] != null)
  897. m_allow_alternate_ports = args["allow_alt_ports"].AsBoolean();
  898. if (args["proxy_url"] != null)
  899. proxyUrl = args["proxy_url"].AsString();
  900. if (args["region_type"] != null)
  901. m_regionType = args["region_type"].AsString();
  902. }
  903. public static RegionInfo Create(UUID regionID, string regionName, uint regX, uint regY, string externalHostName, uint httpPort, uint simPort, uint remotingPort, string serverURI)
  904. {
  905. RegionInfo regionInfo;
  906. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(externalHostName), (int)simPort);
  907. regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, externalHostName);
  908. regionInfo.RemotingPort = remotingPort;
  909. regionInfo.RemotingAddress = externalHostName;
  910. regionInfo.HttpPort = httpPort;
  911. regionInfo.RegionID = regionID;
  912. regionInfo.RegionName = regionName;
  913. regionInfo.ServerURI = serverURI;
  914. return regionInfo;
  915. }
  916. public Dictionary<string, object> ToKeyValuePairs()
  917. {
  918. Dictionary<string, object> kvp = new Dictionary<string, object>();
  919. kvp["uuid"] = RegionID.ToString();
  920. kvp["locX"] = RegionLocX.ToString();
  921. kvp["locY"] = RegionLocY.ToString();
  922. kvp["external_ip_address"] = ExternalEndPoint.Address.ToString();
  923. kvp["external_port"] = ExternalEndPoint.Port.ToString();
  924. kvp["external_host_name"] = ExternalHostName;
  925. kvp["http_port"] = HttpPort.ToString();
  926. kvp["internal_ip_address"] = InternalEndPoint.Address.ToString();
  927. kvp["internal_port"] = InternalEndPoint.Port.ToString();
  928. kvp["alternate_ports"] = m_allow_alternate_ports.ToString();
  929. kvp["server_uri"] = ServerURI;
  930. return kvp;
  931. }
  932. }
  933. }