RegionInfo.cs 46 KB

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