RegionInfo.cs 48 KB

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