RegionInfo.cs 42 KB

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