RegionInfo.cs 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  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 DataStore = String.Empty;
  311. public string RegionFile = String.Empty;
  312. public bool isSandbox = false;
  313. public bool Persistent = true;
  314. private EstateSettings m_estateSettings;
  315. private RegionSettings m_regionSettings;
  316. // private IConfigSource m_configSource = null;
  317. public UUID originRegionID = UUID.Zero;
  318. public string proxyUrl = "";
  319. public int ProxyOffset = 0;
  320. public string regionSecret = UUID.Random().ToString();
  321. public string osSecret;
  322. public UUID lastMapUUID = UUID.Zero;
  323. public string lastMapRefresh = "0";
  324. private int m_nonphysPrimMax = 0;
  325. private int m_physPrimMax = 0;
  326. private bool m_clampPrimSize = false;
  327. private int m_objectCapacity = 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 byte AccessLevel
  469. {
  470. get { return (byte)Util.ConvertMaturityToAccessLevel((uint)RegionSettings.Maturity); }
  471. }
  472. public string RegionType
  473. {
  474. get { return m_regionType; }
  475. }
  476. /// <summary>
  477. /// The port by which http communication occurs with the region (most noticeably, CAPS communication)
  478. /// </summary>
  479. public uint HttpPort
  480. {
  481. get { return m_httpPort; }
  482. set { m_httpPort = value; }
  483. }
  484. /// <summary>
  485. /// A well-formed URI for the host region server (namely "http://" + ExternalHostName)
  486. /// </summary>
  487. public string ServerURI
  488. {
  489. get {
  490. if ( m_serverURI != string.Empty ) {
  491. return m_serverURI;
  492. } else {
  493. return "http://" + m_externalHostName + ":" + m_httpPort + "/";
  494. }
  495. }
  496. set {
  497. if ( value.EndsWith("/") ) {
  498. m_serverURI = value;
  499. } else {
  500. m_serverURI = value + '/';
  501. }
  502. }
  503. }
  504. public string RegionName
  505. {
  506. get { return m_regionName; }
  507. set { m_regionName = value; }
  508. }
  509. public uint RemotingPort
  510. {
  511. get { return m_remotingPort; }
  512. set { m_remotingPort = value; }
  513. }
  514. /// <value>
  515. /// This accessor can throw all the exceptions that Dns.GetHostAddresses can throw.
  516. ///
  517. /// XXX Isn't this really doing too much to be a simple getter, rather than an explict method?
  518. /// </value>
  519. public IPEndPoint ExternalEndPoint
  520. {
  521. get
  522. {
  523. // Old one defaults to IPv6
  524. //return new IPEndPoint(Dns.GetHostAddresses(m_externalHostName)[0], m_internalEndPoint.Port);
  525. IPAddress ia = null;
  526. // If it is already an IP, don't resolve it - just return directly
  527. if (IPAddress.TryParse(m_externalHostName, out ia))
  528. return new IPEndPoint(ia, m_internalEndPoint.Port);
  529. // Reset for next check
  530. ia = null;
  531. try
  532. {
  533. foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
  534. {
  535. if (ia == null)
  536. ia = Adr;
  537. if (Adr.AddressFamily == AddressFamily.InterNetwork)
  538. {
  539. ia = Adr;
  540. break;
  541. }
  542. }
  543. }
  544. catch (SocketException e)
  545. {
  546. throw new Exception(
  547. "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
  548. e + "' attached to this exception", e);
  549. }
  550. return new IPEndPoint(ia, m_internalEndPoint.Port);
  551. }
  552. set { m_externalHostName = value.ToString(); }
  553. }
  554. public string ExternalHostName
  555. {
  556. get { return m_externalHostName; }
  557. set { m_externalHostName = value; }
  558. }
  559. public IPEndPoint InternalEndPoint
  560. {
  561. get { return m_internalEndPoint; }
  562. set { m_internalEndPoint = value; }
  563. }
  564. public uint RegionLocX
  565. {
  566. get { return m_regionLocX.Value; }
  567. set { m_regionLocX = value; }
  568. }
  569. public uint RegionLocY
  570. {
  571. get { return m_regionLocY.Value; }
  572. set { m_regionLocY = value; }
  573. }
  574. public ulong RegionHandle
  575. {
  576. get { return Util.UIntsToLong((RegionLocX * (uint) Constants.RegionSize), (RegionLocY * (uint) Constants.RegionSize)); }
  577. }
  578. public void SetEndPoint(string ipaddr, int port)
  579. {
  580. IPAddress tmpIP = IPAddress.Parse(ipaddr);
  581. IPEndPoint tmpEPE = new IPEndPoint(tmpIP, port);
  582. m_internalEndPoint = tmpEPE;
  583. }
  584. private void ReadNiniConfig(IConfigSource source, string name)
  585. {
  586. // bool creatingNew = false;
  587. if (source.Configs.Count == 0)
  588. {
  589. MainConsole.Instance.Output("=====================================\n");
  590. MainConsole.Instance.Output("We are now going to ask a couple of questions about your region.\n");
  591. MainConsole.Instance.Output("You can press 'enter' without typing anything to use the default\n");
  592. MainConsole.Instance.Output("the default is displayed between [ ] brackets.\n");
  593. MainConsole.Instance.Output("=====================================\n");
  594. if (name == String.Empty)
  595. name = MainConsole.Instance.CmdPrompt("New region name", name);
  596. if (name == String.Empty)
  597. throw new Exception("Cannot interactively create region with no name");
  598. source.AddConfig(name);
  599. // creatingNew = true;
  600. }
  601. if (name == String.Empty)
  602. name = source.Configs[0].Name;
  603. if (source.Configs[name] == null)
  604. {
  605. source.AddConfig(name);
  606. // creatingNew = true;
  607. }
  608. IConfig config = source.Configs[name];
  609. // UUID
  610. //
  611. string regionUUID = config.GetString("RegionUUID", string.Empty);
  612. if (regionUUID == String.Empty)
  613. {
  614. UUID newID = UUID.Random();
  615. regionUUID = MainConsole.Instance.CmdPrompt("Region UUID", newID.ToString());
  616. config.Set("RegionUUID", regionUUID);
  617. }
  618. RegionID = new UUID(regionUUID);
  619. originRegionID = RegionID; // What IS this?!
  620. RegionName = name;
  621. string location = config.GetString("Location", String.Empty);
  622. if (location == String.Empty)
  623. {
  624. location = MainConsole.Instance.CmdPrompt("Region Location", "1000,1000");
  625. config.Set("Location", location);
  626. }
  627. string[] locationElements = location.Split(new char[] {','});
  628. m_regionLocX = Convert.ToUInt32(locationElements[0]);
  629. m_regionLocY = Convert.ToUInt32(locationElements[1]);
  630. // Datastore (is this implemented? Omitted from example!)
  631. DataStore = config.GetString("Datastore", String.Empty);
  632. // Internal IP
  633. IPAddress address;
  634. if (config.Contains("InternalAddress"))
  635. {
  636. address = IPAddress.Parse(config.GetString("InternalAddress", String.Empty));
  637. }
  638. else
  639. {
  640. address = IPAddress.Parse(MainConsole.Instance.CmdPrompt("Internal IP address", "0.0.0.0"));
  641. config.Set("InternalAddress", address.ToString());
  642. }
  643. int port;
  644. if (config.Contains("InternalPort"))
  645. {
  646. port = config.GetInt("InternalPort", 9000);
  647. }
  648. else
  649. {
  650. port = Convert.ToInt32(MainConsole.Instance.CmdPrompt("Internal port", "9000"));
  651. config.Set("InternalPort", port);
  652. }
  653. m_internalEndPoint = new IPEndPoint(address, port);
  654. if (config.Contains("AllowAlternatePorts"))
  655. {
  656. m_allow_alternate_ports = config.GetBoolean("AllowAlternatePorts", true);
  657. }
  658. else
  659. {
  660. m_allow_alternate_ports = Convert.ToBoolean(MainConsole.Instance.CmdPrompt("Allow alternate ports", "False"));
  661. config.Set("AllowAlternatePorts", m_allow_alternate_ports.ToString());
  662. }
  663. // External IP
  664. //
  665. string externalName;
  666. if (config.Contains("ExternalHostName"))
  667. {
  668. externalName = config.GetString("ExternalHostName", "SYSTEMIP");
  669. }
  670. else
  671. {
  672. externalName = MainConsole.Instance.CmdPrompt("External host name", "SYSTEMIP");
  673. config.Set("ExternalHostName", externalName);
  674. }
  675. if (externalName == "SYSTEMIP")
  676. {
  677. m_externalHostName = Util.GetLocalHost().ToString();
  678. m_log.InfoFormat(
  679. "[REGIONINFO]: Resolving SYSTEMIP to {0} for external hostname of region {1}",
  680. m_externalHostName, name);
  681. }
  682. else
  683. {
  684. m_externalHostName = externalName;
  685. }
  686. m_regionType = config.GetString("RegionType", String.Empty);
  687. // Prim stuff
  688. //
  689. m_nonphysPrimMax = config.GetInt("NonphysicalPrimMax", 256);
  690. m_physPrimMax = config.GetInt("PhysicalPrimMax", 10);
  691. m_clampPrimSize = config.GetBoolean("ClampPrimSize", false);
  692. m_objectCapacity = config.GetInt("MaxPrims", 15000);
  693. // Multi-tenancy
  694. //
  695. ScopeID = new UUID(config.GetString("ScopeID", UUID.Zero.ToString()));
  696. }
  697. private void WriteNiniConfig(IConfigSource source)
  698. {
  699. IConfig config = source.Configs[RegionName];
  700. if (config != null)
  701. source.Configs.Remove(config);
  702. config = source.AddConfig(RegionName);
  703. config.Set("RegionUUID", RegionID.ToString());
  704. string location = String.Format("{0},{1}", m_regionLocX, m_regionLocY);
  705. config.Set("Location", location);
  706. if (DataStore != String.Empty)
  707. config.Set("Datastore", DataStore);
  708. config.Set("InternalAddress", m_internalEndPoint.Address.ToString());
  709. config.Set("InternalPort", m_internalEndPoint.Port);
  710. config.Set("AllowAlternatePorts", m_allow_alternate_ports.ToString());
  711. config.Set("ExternalHostName", m_externalHostName);
  712. if (m_nonphysPrimMax != 0)
  713. config.Set("NonphysicalPrimMax", m_nonphysPrimMax);
  714. if (m_physPrimMax != 0)
  715. config.Set("PhysicalPrimMax", m_physPrimMax);
  716. config.Set("ClampPrimSize", m_clampPrimSize.ToString());
  717. if (m_objectCapacity != 0)
  718. config.Set("MaxPrims", m_objectCapacity);
  719. if (ScopeID != UUID.Zero)
  720. config.Set("ScopeID", ScopeID.ToString());
  721. if (RegionType != String.Empty)
  722. config.Set("RegionType", RegionType);
  723. }
  724. public bool ignoreIncomingConfiguration(string configuration_key, object configuration_result)
  725. {
  726. return true;
  727. }
  728. public void SaveRegionToFile(string description, string filename)
  729. {
  730. if (filename.ToLower().EndsWith(".ini"))
  731. {
  732. IniConfigSource source = new IniConfigSource();
  733. try
  734. {
  735. source = new IniConfigSource(filename); // Load if it exists
  736. }
  737. catch (Exception)
  738. {
  739. }
  740. WriteNiniConfig(source);
  741. source.Save(filename);
  742. return;
  743. }
  744. else if (filename.ToLower().EndsWith(".xml"))
  745. {
  746. configMember = new ConfigurationMember(filename, description, loadConfigurationOptionsFromMe,
  747. ignoreIncomingConfiguration, false);
  748. configMember.performConfigurationRetrieve();
  749. RegionFile = filename;
  750. }
  751. else
  752. throw new Exception("Invalid file type for region persistence.");
  753. }
  754. public void loadConfigurationOptionsFromMe()
  755. {
  756. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID_NULL_FREE,
  757. "UUID of Region (Default is recommended, random UUID)",
  758. RegionID.ToString(), true);
  759. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  760. "Region Name", RegionName, true);
  761. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  762. "Grid Location (X Axis)", m_regionLocX.ToString(), true);
  763. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  764. "Grid Location (Y Axis)", m_regionLocY.ToString(), true);
  765. //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  766. configMember.addConfigurationOption("internal_ip_address",
  767. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  768. "Internal IP Address for incoming UDP client connections",
  769. m_internalEndPoint.Address.ToString(),
  770. true);
  771. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  772. "Internal IP Port for incoming UDP client connections",
  773. m_internalEndPoint.Port.ToString(), true);
  774. configMember.addConfigurationOption("allow_alternate_ports",
  775. ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  776. "Allow sim to find alternate UDP ports when ports are in use?",
  777. m_allow_alternate_ports.ToString(), true);
  778. configMember.addConfigurationOption("external_host_name",
  779. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  780. "External Host Name", m_externalHostName, true);
  781. configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  782. "Last Map UUID", lastMapUUID.ToString(), true);
  783. configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  784. "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
  785. configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  786. "Maximum size for nonphysical prims", m_nonphysPrimMax.ToString(), true);
  787. configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  788. "Maximum size for physical prims", m_physPrimMax.ToString(), true);
  789. configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  790. "Clamp prims to max size", m_clampPrimSize.ToString(), true);
  791. configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  792. "Max objects this sim will hold", m_objectCapacity.ToString(), true);
  793. configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  794. "Scope ID for this region", ScopeID.ToString(), true);
  795. configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  796. "Free form string describing the type of region", String.Empty, true);
  797. }
  798. public void loadConfigurationOptions()
  799. {
  800. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  801. "UUID of Region (Default is recommended, random UUID)",
  802. UUID.Random().ToString(), true);
  803. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  804. "Region Name", "OpenSim Test", false);
  805. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  806. "Grid Location (X Axis)", "1000", false);
  807. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  808. "Grid Location (Y Axis)", "1000", false);
  809. //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  810. configMember.addConfigurationOption("internal_ip_address",
  811. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  812. "Internal IP Address for incoming UDP client connections", "0.0.0.0",
  813. false);
  814. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  815. "Internal IP Port for incoming UDP client connections",
  816. ConfigSettings.DefaultRegionHttpPort.ToString(), false);
  817. configMember.addConfigurationOption("allow_alternate_ports", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  818. "Allow sim to find alternate UDP ports when ports are in use?",
  819. "false", true);
  820. configMember.addConfigurationOption("external_host_name",
  821. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  822. "External Host Name", "127.0.0.1", false);
  823. configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  824. "Last Map UUID", lastMapUUID.ToString(), true);
  825. configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  826. "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
  827. configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  828. "Maximum size for nonphysical prims", "0", true);
  829. configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  830. "Maximum size for physical prims", "0", true);
  831. configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  832. "Clamp prims to max size", "false", true);
  833. configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  834. "Max objects this sim will hold", "0", true);
  835. configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  836. "Scope ID for this region", UUID.Zero.ToString(), true);
  837. configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  838. "Region Type", String.Empty, true);
  839. }
  840. public bool handleIncomingConfiguration(string configuration_key, object configuration_result)
  841. {
  842. switch (configuration_key)
  843. {
  844. case "sim_UUID":
  845. RegionID = (UUID) configuration_result;
  846. originRegionID = (UUID) configuration_result;
  847. break;
  848. case "sim_name":
  849. RegionName = (string) configuration_result;
  850. break;
  851. case "sim_location_x":
  852. m_regionLocX = (uint) configuration_result;
  853. break;
  854. case "sim_location_y":
  855. m_regionLocY = (uint) configuration_result;
  856. break;
  857. case "datastore":
  858. DataStore = (string) configuration_result;
  859. break;
  860. case "internal_ip_address":
  861. IPAddress address = (IPAddress) configuration_result;
  862. m_internalEndPoint = new IPEndPoint(address, 0);
  863. break;
  864. case "internal_ip_port":
  865. m_internalEndPoint.Port = (int) configuration_result;
  866. break;
  867. case "allow_alternate_ports":
  868. m_allow_alternate_ports = (bool) configuration_result;
  869. break;
  870. case "external_host_name":
  871. if ((string) configuration_result != "SYSTEMIP")
  872. {
  873. m_externalHostName = (string) configuration_result;
  874. }
  875. else
  876. {
  877. m_externalHostName = Util.GetLocalHost().ToString();
  878. }
  879. break;
  880. case "lastmap_uuid":
  881. lastMapUUID = (UUID)configuration_result;
  882. break;
  883. case "lastmap_refresh":
  884. lastMapRefresh = (string)configuration_result;
  885. break;
  886. case "nonphysical_prim_max":
  887. m_nonphysPrimMax = (int)configuration_result;
  888. break;
  889. case "physical_prim_max":
  890. m_physPrimMax = (int)configuration_result;
  891. break;
  892. case "clamp_prim_size":
  893. m_clampPrimSize = (bool)configuration_result;
  894. break;
  895. case "object_capacity":
  896. m_objectCapacity = (int)configuration_result;
  897. break;
  898. case "scope_id":
  899. ScopeID = (UUID)configuration_result;
  900. break;
  901. case "region_type":
  902. m_regionType = (string)configuration_result;
  903. break;
  904. }
  905. return true;
  906. }
  907. public void SaveLastMapUUID(UUID mapUUID)
  908. {
  909. lastMapUUID = mapUUID;
  910. lastMapRefresh = Util.UnixTimeSinceEpoch().ToString();
  911. if (configMember == null)
  912. return;
  913. configMember.forceSetConfigurationOption("lastmap_uuid", mapUUID.ToString());
  914. configMember.forceSetConfigurationOption("lastmap_refresh", lastMapRefresh);
  915. }
  916. public OSDMap PackRegionInfoData()
  917. {
  918. OSDMap args = new OSDMap();
  919. args["region_id"] = OSD.FromUUID(RegionID);
  920. if ((RegionName != null) && !RegionName.Equals(""))
  921. args["region_name"] = OSD.FromString(RegionName);
  922. args["external_host_name"] = OSD.FromString(ExternalHostName);
  923. args["http_port"] = OSD.FromString(HttpPort.ToString());
  924. args["server_uri"] = OSD.FromString(ServerURI);
  925. args["region_xloc"] = OSD.FromString(RegionLocX.ToString());
  926. args["region_yloc"] = OSD.FromString(RegionLocY.ToString());
  927. args["internal_ep_address"] = OSD.FromString(InternalEndPoint.Address.ToString());
  928. args["internal_ep_port"] = OSD.FromString(InternalEndPoint.Port.ToString());
  929. if ((RemotingAddress != null) && !RemotingAddress.Equals(""))
  930. args["remoting_address"] = OSD.FromString(RemotingAddress);
  931. args["remoting_port"] = OSD.FromString(RemotingPort.ToString());
  932. args["allow_alt_ports"] = OSD.FromBoolean(m_allow_alternate_ports);
  933. if ((proxyUrl != null) && !proxyUrl.Equals(""))
  934. args["proxy_url"] = OSD.FromString(proxyUrl);
  935. if (RegionType != String.Empty)
  936. args["region_type"] = OSD.FromString(RegionType);
  937. return args;
  938. }
  939. public void UnpackRegionInfoData(OSDMap args)
  940. {
  941. if (args["region_id"] != null)
  942. RegionID = args["region_id"].AsUUID();
  943. if (args["region_name"] != null)
  944. RegionName = args["region_name"].AsString();
  945. if (args["external_host_name"] != null)
  946. ExternalHostName = args["external_host_name"].AsString();
  947. if (args["http_port"] != null)
  948. UInt32.TryParse(args["http_port"].AsString(), out m_httpPort);
  949. if (args["server_uri"] != null)
  950. ServerURI = args["server_uri"].AsString();
  951. if (args["region_xloc"] != null)
  952. {
  953. uint locx;
  954. UInt32.TryParse(args["region_xloc"].AsString(), out locx);
  955. RegionLocX = locx;
  956. }
  957. if (args["region_yloc"] != null)
  958. {
  959. uint locy;
  960. UInt32.TryParse(args["region_yloc"].AsString(), out locy);
  961. RegionLocY = locy;
  962. }
  963. IPAddress ip_addr = null;
  964. if (args["internal_ep_address"] != null)
  965. {
  966. IPAddress.TryParse(args["internal_ep_address"].AsString(), out ip_addr);
  967. }
  968. int port = 0;
  969. if (args["internal_ep_port"] != null)
  970. {
  971. Int32.TryParse(args["internal_ep_port"].AsString(), out port);
  972. }
  973. InternalEndPoint = new IPEndPoint(ip_addr, port);
  974. if (args["remoting_address"] != null)
  975. RemotingAddress = args["remoting_address"].AsString();
  976. if (args["remoting_port"] != null)
  977. UInt32.TryParse(args["remoting_port"].AsString(), out m_remotingPort);
  978. if (args["allow_alt_ports"] != null)
  979. m_allow_alternate_ports = args["allow_alt_ports"].AsBoolean();
  980. if (args["proxy_url"] != null)
  981. proxyUrl = args["proxy_url"].AsString();
  982. if (args["region_type"] != null)
  983. m_regionType = args["region_type"].AsString();
  984. }
  985. public static RegionInfo Create(UUID regionID, string regionName, uint regX, uint regY, string externalHostName, uint httpPort, uint simPort, uint remotingPort, string serverURI)
  986. {
  987. RegionInfo regionInfo;
  988. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(externalHostName), (int)simPort);
  989. regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, externalHostName);
  990. regionInfo.RemotingPort = remotingPort;
  991. regionInfo.RemotingAddress = externalHostName;
  992. regionInfo.HttpPort = httpPort;
  993. regionInfo.RegionID = regionID;
  994. regionInfo.RegionName = regionName;
  995. regionInfo.ServerURI = serverURI;
  996. return regionInfo;
  997. }
  998. public int getInternalEndPointPort()
  999. {
  1000. return m_internalEndPoint.Port;
  1001. }
  1002. public Dictionary<string, object> ToKeyValuePairs()
  1003. {
  1004. Dictionary<string, object> kvp = new Dictionary<string, object>();
  1005. kvp["uuid"] = RegionID.ToString();
  1006. kvp["locX"] = RegionLocX.ToString();
  1007. kvp["locY"] = RegionLocY.ToString();
  1008. kvp["external_ip_address"] = ExternalEndPoint.Address.ToString();
  1009. kvp["external_port"] = ExternalEndPoint.Port.ToString();
  1010. kvp["external_host_name"] = ExternalHostName;
  1011. kvp["http_port"] = HttpPort.ToString();
  1012. kvp["internal_ip_address"] = InternalEndPoint.Address.ToString();
  1013. kvp["internal_port"] = InternalEndPoint.Port.ToString();
  1014. kvp["alternate_ports"] = m_allow_alternate_ports.ToString();
  1015. kvp["server_uri"] = ServerURI;
  1016. return kvp;
  1017. }
  1018. }
  1019. }