RegionInfo.cs 40 KB

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