RegionInfo.cs 44 KB

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