RegionInfo.cs 45 KB

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