RegionInfo.cs 42 KB

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