RegionInfo.cs 42 KB

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