RegionInfo.cs 42 KB

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