RegionInfo.cs 46 KB

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