RegionInfo.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  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. public uint RegionLocX
  359. {
  360. get { return m_regionLocX.Value; }
  361. set { m_regionLocX = value; }
  362. }
  363. public uint RegionLocY
  364. {
  365. get { return m_regionLocY.Value; }
  366. set { m_regionLocY = value; }
  367. }
  368. public ulong RegionHandle
  369. {
  370. get { return Util.UIntsToLong((RegionLocX * (uint) Constants.RegionSize), (RegionLocY * (uint) Constants.RegionSize)); }
  371. }
  372. public void SetEndPoint(string ipaddr, int port)
  373. {
  374. IPAddress tmpIP = IPAddress.Parse(ipaddr);
  375. IPEndPoint tmpEPE = new IPEndPoint(tmpIP, port);
  376. m_internalEndPoint = tmpEPE;
  377. }
  378. public string GetOtherSetting(string key)
  379. {
  380. string val;
  381. string keylower = key.ToLower();
  382. if (m_otherSettings.TryGetValue(keylower, out val))
  383. return val;
  384. m_log.DebugFormat("[RegionInfo] Could not locate value for parameter {0}", key);
  385. return null;
  386. }
  387. public void SetOtherSetting(string key, string value)
  388. {
  389. string keylower = key.ToLower();
  390. m_otherSettings[keylower] = value;
  391. }
  392. private void ReadNiniConfig(IConfigSource source, string name)
  393. {
  394. // bool creatingNew = false;
  395. if (source.Configs.Count == 0)
  396. {
  397. MainConsole.Instance.Output("=====================================\n");
  398. MainConsole.Instance.Output("We are now going to ask a couple of questions about your region.\n");
  399. MainConsole.Instance.Output("You can press 'enter' without typing anything to use the default\n");
  400. MainConsole.Instance.Output("the default is displayed between [ ] brackets.\n");
  401. MainConsole.Instance.Output("=====================================\n");
  402. if (name == String.Empty)
  403. name = MainConsole.Instance.CmdPrompt("New region name", name);
  404. if (name == String.Empty)
  405. throw new Exception("Cannot interactively create region with no name");
  406. source.AddConfig(name);
  407. // creatingNew = true;
  408. }
  409. if (name == String.Empty)
  410. name = source.Configs[0].Name;
  411. if (source.Configs[name] == null)
  412. {
  413. source.AddConfig(name);
  414. }
  415. RegionName = name;
  416. IConfig config = source.Configs[name];
  417. // Track all of the keys in this config and remove as they are processed
  418. // The remaining keys will be added to generic key-value storage for
  419. // whoever might need it
  420. HashSet<String> allKeys = new HashSet<String>();
  421. foreach (string s in config.GetKeys())
  422. {
  423. allKeys.Add(s);
  424. }
  425. // RegionUUID
  426. //
  427. allKeys.Remove("RegionUUID");
  428. string regionUUID = config.GetString("RegionUUID", string.Empty);
  429. if (regionUUID == String.Empty)
  430. {
  431. UUID newID = UUID.Random();
  432. regionUUID = MainConsole.Instance.CmdPrompt("RegionUUID", newID.ToString());
  433. config.Set("RegionUUID", regionUUID);
  434. }
  435. RegionID = new UUID(regionUUID);
  436. originRegionID = RegionID; // What IS this?! (Needed for RegionCombinerModule?)
  437. // Location
  438. //
  439. allKeys.Remove("Location");
  440. string location = config.GetString("Location", String.Empty);
  441. if (location == String.Empty)
  442. {
  443. location = MainConsole.Instance.CmdPrompt("Region Location", "1000,1000");
  444. config.Set("Location", location);
  445. }
  446. string[] locationElements = location.Split(new char[] {','});
  447. m_regionLocX = Convert.ToUInt32(locationElements[0]);
  448. m_regionLocY = Convert.ToUInt32(locationElements[1]);
  449. // InternalAddress
  450. //
  451. IPAddress address;
  452. allKeys.Remove("InternalAddress");
  453. if (config.Contains("InternalAddress"))
  454. {
  455. address = IPAddress.Parse(config.GetString("InternalAddress", String.Empty));
  456. }
  457. else
  458. {
  459. address = IPAddress.Parse(MainConsole.Instance.CmdPrompt("Internal IP address", "0.0.0.0"));
  460. config.Set("InternalAddress", address.ToString());
  461. }
  462. // InternalPort
  463. //
  464. int port;
  465. allKeys.Remove("InternalPort");
  466. if (config.Contains("InternalPort"))
  467. {
  468. port = config.GetInt("InternalPort", 9000);
  469. }
  470. else
  471. {
  472. port = Convert.ToInt32(MainConsole.Instance.CmdPrompt("Internal port", "9000"));
  473. config.Set("InternalPort", port);
  474. }
  475. m_internalEndPoint = new IPEndPoint(address, port);
  476. // AllowAlternatePorts
  477. //
  478. allKeys.Remove("AllowAlternatePorts");
  479. if (config.Contains("AllowAlternatePorts"))
  480. {
  481. m_allow_alternate_ports = config.GetBoolean("AllowAlternatePorts", true);
  482. }
  483. else
  484. {
  485. m_allow_alternate_ports = Convert.ToBoolean(MainConsole.Instance.CmdPrompt("Allow alternate ports", "False"));
  486. config.Set("AllowAlternatePorts", m_allow_alternate_ports.ToString());
  487. }
  488. // ExternalHostName
  489. //
  490. allKeys.Remove("ExternalHostName");
  491. string externalName;
  492. if (config.Contains("ExternalHostName"))
  493. {
  494. externalName = config.GetString("ExternalHostName", "SYSTEMIP");
  495. }
  496. else
  497. {
  498. externalName = MainConsole.Instance.CmdPrompt("External host name", "SYSTEMIP");
  499. config.Set("ExternalHostName", externalName);
  500. }
  501. if (externalName == "SYSTEMIP")
  502. {
  503. m_externalHostName = Util.GetLocalHost().ToString();
  504. m_log.InfoFormat(
  505. "[REGIONINFO]: Resolving SYSTEMIP to {0} for external hostname of region {1}",
  506. m_externalHostName, name);
  507. }
  508. else
  509. {
  510. m_externalHostName = externalName;
  511. }
  512. // RegionType
  513. m_regionType = config.GetString("RegionType", String.Empty);
  514. allKeys.Remove("RegionType");
  515. // Prim stuff
  516. //
  517. m_nonphysPrimMax = config.GetInt("NonphysicalPrimMax", 0);
  518. allKeys.Remove("NonphysicalPrimMax");
  519. m_physPrimMax = config.GetInt("PhysicalPrimMax", 0);
  520. allKeys.Remove("PhysicalPrimMax");
  521. m_clampPrimSize = config.GetBoolean("ClampPrimSize", false);
  522. allKeys.Remove("ClampPrimSize");
  523. m_objectCapacity = config.GetInt("MaxPrims", 15000);
  524. allKeys.Remove("MaxPrims");
  525. m_agentCapacity = config.GetInt("MaxAgents", 100);
  526. allKeys.Remove("MaxAgents");
  527. // Multi-tenancy
  528. //
  529. ScopeID = new UUID(config.GetString("ScopeID", UUID.Zero.ToString()));
  530. allKeys.Remove("ScopeID");
  531. foreach (String s in allKeys)
  532. {
  533. SetOtherSetting(s, config.GetString(s));
  534. }
  535. }
  536. private void WriteNiniConfig(IConfigSource source)
  537. {
  538. IConfig config = source.Configs[RegionName];
  539. if (config != null)
  540. source.Configs.Remove(config);
  541. config = source.AddConfig(RegionName);
  542. config.Set("RegionUUID", RegionID.ToString());
  543. string location = String.Format("{0},{1}", m_regionLocX, m_regionLocY);
  544. config.Set("Location", location);
  545. config.Set("InternalAddress", m_internalEndPoint.Address.ToString());
  546. config.Set("InternalPort", m_internalEndPoint.Port);
  547. config.Set("AllowAlternatePorts", m_allow_alternate_ports.ToString());
  548. config.Set("ExternalHostName", m_externalHostName);
  549. if (m_nonphysPrimMax != 0)
  550. config.Set("NonphysicalPrimMax", m_nonphysPrimMax);
  551. if (m_physPrimMax != 0)
  552. config.Set("PhysicalPrimMax", m_physPrimMax);
  553. config.Set("ClampPrimSize", m_clampPrimSize.ToString());
  554. if (m_objectCapacity != 0)
  555. config.Set("MaxPrims", m_objectCapacity);
  556. if (m_agentCapacity != 0)
  557. config.Set("MaxAgents", m_agentCapacity);
  558. if (ScopeID != UUID.Zero)
  559. config.Set("ScopeID", ScopeID.ToString());
  560. if (RegionType != String.Empty)
  561. config.Set("RegionType", RegionType);
  562. }
  563. public bool ignoreIncomingConfiguration(string configuration_key, object configuration_result)
  564. {
  565. return true;
  566. }
  567. public void SaveRegionToFile(string description, string filename)
  568. {
  569. if (filename.ToLower().EndsWith(".ini"))
  570. {
  571. IniConfigSource source = new IniConfigSource();
  572. try
  573. {
  574. source = new IniConfigSource(filename); // Load if it exists
  575. }
  576. catch (Exception)
  577. {
  578. }
  579. WriteNiniConfig(source);
  580. source.Save(filename);
  581. return;
  582. }
  583. else if (filename.ToLower().EndsWith(".xml"))
  584. {
  585. configMember = new ConfigurationMember(filename, description, loadConfigurationOptionsFromMe,
  586. ignoreIncomingConfiguration, false);
  587. configMember.performConfigurationRetrieve();
  588. RegionFile = filename;
  589. }
  590. else
  591. throw new Exception("Invalid file type for region persistence.");
  592. }
  593. public void loadConfigurationOptionsFromMe()
  594. {
  595. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID_NULL_FREE,
  596. "UUID of Region (Default is recommended, random UUID)",
  597. RegionID.ToString(), true);
  598. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  599. "Region Name", RegionName, true);
  600. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  601. "Grid Location (X Axis)", m_regionLocX.ToString(), true);
  602. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  603. "Grid Location (Y Axis)", m_regionLocY.ToString(), true);
  604. //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  605. configMember.addConfigurationOption("internal_ip_address",
  606. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  607. "Internal IP Address for incoming UDP client connections",
  608. m_internalEndPoint.Address.ToString(),
  609. true);
  610. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  611. "Internal IP Port for incoming UDP client connections",
  612. m_internalEndPoint.Port.ToString(), true);
  613. configMember.addConfigurationOption("allow_alternate_ports",
  614. ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  615. "Allow sim to find alternate UDP ports when ports are in use?",
  616. m_allow_alternate_ports.ToString(), true);
  617. configMember.addConfigurationOption("external_host_name",
  618. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  619. "External Host Name", m_externalHostName, true);
  620. configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  621. "Last Map UUID", lastMapUUID.ToString(), true);
  622. configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  623. "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
  624. configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  625. "Maximum size for nonphysical prims", m_nonphysPrimMax.ToString(), true);
  626. configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  627. "Maximum size for physical prims", m_physPrimMax.ToString(), true);
  628. configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  629. "Clamp prims to max size", m_clampPrimSize.ToString(), true);
  630. configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  631. "Max objects this sim will hold", m_objectCapacity.ToString(), true);
  632. configMember.addConfigurationOption("agent_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  633. "Max avatars this sim will hold", m_agentCapacity.ToString(), true);
  634. configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  635. "Scope ID for this region", ScopeID.ToString(), true);
  636. configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  637. "Free form string describing the type of region", String.Empty, true);
  638. }
  639. public void loadConfigurationOptions()
  640. {
  641. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  642. "UUID of Region (Default is recommended, random UUID)",
  643. UUID.Random().ToString(), true);
  644. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  645. "Region Name", "OpenSim Test", false);
  646. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  647. "Grid Location (X Axis)", "1000", false);
  648. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  649. "Grid Location (Y Axis)", "1000", false);
  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", "0.0.0.0",
  654. false);
  655. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  656. "Internal IP Port for incoming UDP client connections",
  657. ConfigSettings.DefaultRegionHttpPort.ToString(), false);
  658. configMember.addConfigurationOption("allow_alternate_ports", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  659. "Allow sim to find alternate UDP ports when ports are in use?",
  660. "false", true);
  661. configMember.addConfigurationOption("external_host_name",
  662. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  663. "External Host Name", "127.0.0.1", false);
  664. configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  665. "Last Map UUID", lastMapUUID.ToString(), true);
  666. configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  667. "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
  668. configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  669. "Maximum size for nonphysical prims", "0", true);
  670. configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  671. "Maximum size for physical prims", "0", true);
  672. configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  673. "Clamp prims to max size", "false", true);
  674. configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  675. "Max objects this sim will hold", "15000", true);
  676. configMember.addConfigurationOption("agent_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  677. "Max avatars this sim will hold", "100", true);
  678. configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  679. "Scope ID for this region", UUID.Zero.ToString(), true);
  680. configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  681. "Region Type", String.Empty, true);
  682. }
  683. public bool handleIncomingConfiguration(string configuration_key, object configuration_result)
  684. {
  685. switch (configuration_key)
  686. {
  687. case "sim_UUID":
  688. RegionID = (UUID) configuration_result;
  689. originRegionID = (UUID) configuration_result;
  690. break;
  691. case "sim_name":
  692. RegionName = (string) configuration_result;
  693. break;
  694. case "sim_location_x":
  695. m_regionLocX = (uint) configuration_result;
  696. break;
  697. case "sim_location_y":
  698. m_regionLocY = (uint) configuration_result;
  699. break;
  700. case "internal_ip_address":
  701. IPAddress address = (IPAddress) configuration_result;
  702. m_internalEndPoint = new IPEndPoint(address, 0);
  703. break;
  704. case "internal_ip_port":
  705. m_internalEndPoint.Port = (int) configuration_result;
  706. break;
  707. case "allow_alternate_ports":
  708. m_allow_alternate_ports = (bool) configuration_result;
  709. break;
  710. case "external_host_name":
  711. if ((string) configuration_result != "SYSTEMIP")
  712. {
  713. m_externalHostName = (string) configuration_result;
  714. }
  715. else
  716. {
  717. m_externalHostName = Util.GetLocalHost().ToString();
  718. }
  719. break;
  720. case "lastmap_uuid":
  721. lastMapUUID = (UUID)configuration_result;
  722. break;
  723. case "lastmap_refresh":
  724. lastMapRefresh = (string)configuration_result;
  725. break;
  726. case "nonphysical_prim_max":
  727. m_nonphysPrimMax = (int)configuration_result;
  728. break;
  729. case "physical_prim_max":
  730. m_physPrimMax = (int)configuration_result;
  731. break;
  732. case "clamp_prim_size":
  733. m_clampPrimSize = (bool)configuration_result;
  734. break;
  735. case "object_capacity":
  736. m_objectCapacity = (int)configuration_result;
  737. break;
  738. case "agent_capacity":
  739. m_agentCapacity = (int)configuration_result;
  740. break;
  741. case "scope_id":
  742. ScopeID = (UUID)configuration_result;
  743. break;
  744. case "region_type":
  745. m_regionType = (string)configuration_result;
  746. break;
  747. }
  748. return true;
  749. }
  750. public void SaveLastMapUUID(UUID mapUUID)
  751. {
  752. lastMapUUID = mapUUID;
  753. lastMapRefresh = Util.UnixTimeSinceEpoch().ToString();
  754. if (configMember == null)
  755. return;
  756. configMember.forceSetConfigurationOption("lastmap_uuid", mapUUID.ToString());
  757. configMember.forceSetConfigurationOption("lastmap_refresh", lastMapRefresh);
  758. }
  759. public OSDMap PackRegionInfoData()
  760. {
  761. OSDMap args = new OSDMap();
  762. args["region_id"] = OSD.FromUUID(RegionID);
  763. if ((RegionName != null) && !RegionName.Equals(""))
  764. args["region_name"] = OSD.FromString(RegionName);
  765. args["external_host_name"] = OSD.FromString(ExternalHostName);
  766. args["http_port"] = OSD.FromString(HttpPort.ToString());
  767. args["server_uri"] = OSD.FromString(ServerURI);
  768. args["region_xloc"] = OSD.FromString(RegionLocX.ToString());
  769. args["region_yloc"] = OSD.FromString(RegionLocY.ToString());
  770. args["internal_ep_address"] = OSD.FromString(InternalEndPoint.Address.ToString());
  771. args["internal_ep_port"] = OSD.FromString(InternalEndPoint.Port.ToString());
  772. if ((RemotingAddress != null) && !RemotingAddress.Equals(""))
  773. args["remoting_address"] = OSD.FromString(RemotingAddress);
  774. args["remoting_port"] = OSD.FromString(RemotingPort.ToString());
  775. args["allow_alt_ports"] = OSD.FromBoolean(m_allow_alternate_ports);
  776. if ((proxyUrl != null) && !proxyUrl.Equals(""))
  777. args["proxy_url"] = OSD.FromString(proxyUrl);
  778. if (RegionType != String.Empty)
  779. args["region_type"] = OSD.FromString(RegionType);
  780. return args;
  781. }
  782. public void UnpackRegionInfoData(OSDMap args)
  783. {
  784. if (args["region_id"] != null)
  785. RegionID = args["region_id"].AsUUID();
  786. if (args["region_name"] != null)
  787. RegionName = args["region_name"].AsString();
  788. if (args["external_host_name"] != null)
  789. ExternalHostName = args["external_host_name"].AsString();
  790. if (args["http_port"] != null)
  791. UInt32.TryParse(args["http_port"].AsString(), out m_httpPort);
  792. if (args["server_uri"] != null)
  793. ServerURI = args["server_uri"].AsString();
  794. if (args["region_xloc"] != null)
  795. {
  796. uint locx;
  797. UInt32.TryParse(args["region_xloc"].AsString(), out locx);
  798. RegionLocX = locx;
  799. }
  800. if (args["region_yloc"] != null)
  801. {
  802. uint locy;
  803. UInt32.TryParse(args["region_yloc"].AsString(), out locy);
  804. RegionLocY = locy;
  805. }
  806. IPAddress ip_addr = null;
  807. if (args["internal_ep_address"] != null)
  808. {
  809. IPAddress.TryParse(args["internal_ep_address"].AsString(), out ip_addr);
  810. }
  811. int port = 0;
  812. if (args["internal_ep_port"] != null)
  813. {
  814. Int32.TryParse(args["internal_ep_port"].AsString(), out port);
  815. }
  816. InternalEndPoint = new IPEndPoint(ip_addr, port);
  817. if (args["remoting_address"] != null)
  818. RemotingAddress = args["remoting_address"].AsString();
  819. if (args["remoting_port"] != null)
  820. UInt32.TryParse(args["remoting_port"].AsString(), out m_remotingPort);
  821. if (args["allow_alt_ports"] != null)
  822. m_allow_alternate_ports = args["allow_alt_ports"].AsBoolean();
  823. if (args["proxy_url"] != null)
  824. proxyUrl = args["proxy_url"].AsString();
  825. if (args["region_type"] != null)
  826. m_regionType = args["region_type"].AsString();
  827. }
  828. public static RegionInfo Create(UUID regionID, string regionName, uint regX, uint regY, string externalHostName, uint httpPort, uint simPort, uint remotingPort, string serverURI)
  829. {
  830. RegionInfo regionInfo;
  831. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(externalHostName), (int)simPort);
  832. regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, externalHostName);
  833. regionInfo.RemotingPort = remotingPort;
  834. regionInfo.RemotingAddress = externalHostName;
  835. regionInfo.HttpPort = httpPort;
  836. regionInfo.RegionID = regionID;
  837. regionInfo.RegionName = regionName;
  838. regionInfo.ServerURI = serverURI;
  839. return regionInfo;
  840. }
  841. public Dictionary<string, object> ToKeyValuePairs()
  842. {
  843. Dictionary<string, object> kvp = new Dictionary<string, object>();
  844. kvp["uuid"] = RegionID.ToString();
  845. kvp["locX"] = RegionLocX.ToString();
  846. kvp["locY"] = RegionLocY.ToString();
  847. kvp["external_ip_address"] = ExternalEndPoint.Address.ToString();
  848. kvp["external_port"] = ExternalEndPoint.Port.ToString();
  849. kvp["external_host_name"] = ExternalHostName;
  850. kvp["http_port"] = HttpPort.ToString();
  851. kvp["internal_ip_address"] = InternalEndPoint.Address.ToString();
  852. kvp["internal_port"] = InternalEndPoint.Port.ToString();
  853. kvp["alternate_ports"] = m_allow_alternate_ports.ToString();
  854. kvp["server_uri"] = ServerURI;
  855. return kvp;
  856. }
  857. }
  858. }