RegionInfo.cs 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Net;
  30. using System.Net.Sockets;
  31. using System.Xml;
  32. using System.IO;
  33. using Nini.Config;
  34. using OpenMetaverse;
  35. using OpenMetaverse.StructuredData;
  36. using OpenSim.Framework.Console;
  37. namespace OpenSim.Framework
  38. {
  39. public class RegionLightShareData : ICloneable
  40. {
  41. public UUID regionID = UUID.Zero;
  42. public Vector3 waterColor = new Vector3(4.0f,38.0f,64.0f);
  43. public float waterFogDensityExponent = 4.0f;
  44. public float underwaterFogModifier = 0.25f;
  45. public Vector3 reflectionWaveletScale = new Vector3(2.0f,2.0f,2.0f);
  46. public float fresnelScale = 0.40f;
  47. public float fresnelOffset = 0.50f;
  48. public float refractScaleAbove = 0.03f;
  49. public float refractScaleBelow = 0.20f;
  50. public float blurMultiplier = 0.040f;
  51. public Vector2 bigWaveDirection = new Vector2(1.05f,-0.42f);
  52. public Vector2 littleWaveDirection = new Vector2(1.11f,-1.16f);
  53. public UUID normalMapTexture = new UUID("822ded49-9a6c-f61c-cb89-6df54f42cdf4");
  54. public Vector4 horizon = new Vector4(0.25f, 0.25f, 0.32f, 0.32f);
  55. public float hazeHorizon = 0.19f;
  56. public Vector4 blueDensity = new Vector4(0.12f, 0.22f, 0.38f, 0.38f);
  57. public float hazeDensity = 0.70f;
  58. public float densityMultiplier = 0.18f;
  59. public float distanceMultiplier = 0.8f;
  60. public UInt16 maxAltitude = 1605;
  61. public Vector4 sunMoonColor = new Vector4(0.24f, 0.26f, 0.30f, 0.30f);
  62. public float sunMoonPosition = 0.317f;
  63. public Vector4 ambient = new Vector4(0.35f,0.35f,0.35f,0.35f);
  64. public float eastAngle = 0.0f;
  65. public float sunGlowFocus = 0.10f;
  66. public float sunGlowSize = 1.75f;
  67. public float sceneGamma = 1.0f;
  68. public float starBrightness = 0.0f;
  69. public Vector4 cloudColor = new Vector4(0.41f, 0.41f, 0.41f, 0.41f);
  70. public Vector3 cloudXYDensity = new Vector3(1.00f, 0.53f, 1.00f);
  71. public float cloudCoverage = 0.27f;
  72. public float cloudScale = 0.42f;
  73. public Vector3 cloudDetailXYDensity = new Vector3(1.00f, 0.53f, 0.12f);
  74. public float cloudScrollX = 0.20f;
  75. public bool cloudScrollXLock = false;
  76. public float cloudScrollY = 0.01f;
  77. public bool cloudScrollYLock = false;
  78. public bool drawClassicClouds = true;
  79. public delegate void SaveDelegate(RegionLightShareData wl);
  80. public event SaveDelegate OnSave;
  81. public void Save()
  82. {
  83. if (OnSave != null)
  84. OnSave(this);
  85. }
  86. public object Clone()
  87. {
  88. return this.MemberwiseClone(); // call clone method
  89. }
  90. }
  91. [Serializable]
  92. public class SimpleRegionInfo
  93. {
  94. // private static readonly log4net.ILog m_log
  95. // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  96. /// <summary>
  97. /// The port by which http communication occurs with the region (most noticeably, CAPS communication)
  98. /// </summary>
  99. public uint HttpPort
  100. {
  101. get { return m_httpPort; }
  102. set { m_httpPort = value; }
  103. }
  104. protected uint m_httpPort;
  105. /// <summary>
  106. /// A well-formed URI for the host region server (namely "http://" + ExternalHostName)
  107. /// </summary>
  108. public string ServerURI
  109. {
  110. get { return m_serverURI; }
  111. set { m_serverURI = value; }
  112. }
  113. protected string m_serverURI;
  114. public string RegionName
  115. {
  116. get { return m_regionName; }
  117. set { m_regionName = value; }
  118. }
  119. protected string m_regionName = String.Empty;
  120. protected bool Allow_Alternate_Ports;
  121. public bool m_allow_alternate_ports;
  122. protected string m_externalHostName;
  123. protected IPEndPoint m_internalEndPoint;
  124. protected uint? m_regionLocX;
  125. protected uint? m_regionLocY;
  126. protected uint m_remotingPort;
  127. public UUID RegionID = UUID.Zero;
  128. public string RemotingAddress;
  129. public UUID ScopeID = UUID.Zero;
  130. public SimpleRegionInfo()
  131. {
  132. }
  133. public SimpleRegionInfo(uint regionLocX, uint regionLocY, IPEndPoint internalEndPoint, string externalUri)
  134. {
  135. m_regionLocX = regionLocX;
  136. m_regionLocY = regionLocY;
  137. m_internalEndPoint = internalEndPoint;
  138. m_externalHostName = externalUri;
  139. }
  140. public SimpleRegionInfo(uint regionLocX, uint regionLocY, string externalUri, uint port)
  141. {
  142. m_regionLocX = regionLocX;
  143. m_regionLocY = regionLocY;
  144. m_externalHostName = externalUri;
  145. m_internalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int) port);
  146. }
  147. public SimpleRegionInfo(RegionInfo ConvertFrom)
  148. {
  149. m_regionName = ConvertFrom.RegionName;
  150. m_regionLocX = ConvertFrom.RegionLocX;
  151. m_regionLocY = ConvertFrom.RegionLocY;
  152. m_internalEndPoint = ConvertFrom.InternalEndPoint;
  153. m_externalHostName = ConvertFrom.ExternalHostName;
  154. m_remotingPort = ConvertFrom.RemotingPort;
  155. m_httpPort = ConvertFrom.HttpPort;
  156. m_allow_alternate_ports = ConvertFrom.m_allow_alternate_ports;
  157. RemotingAddress = ConvertFrom.RemotingAddress;
  158. RegionID = UUID.Zero;
  159. ServerURI = ConvertFrom.ServerURI;
  160. }
  161. public uint RemotingPort
  162. {
  163. get { return m_remotingPort; }
  164. set { m_remotingPort = value; }
  165. }
  166. /// <value>
  167. /// This accessor can throw all the exceptions that Dns.GetHostAddresses can throw.
  168. ///
  169. /// XXX Isn't this really doing too much to be a simple getter, rather than an explict method?
  170. /// </value>
  171. public IPEndPoint ExternalEndPoint
  172. {
  173. get
  174. {
  175. // Old one defaults to IPv6
  176. //return new IPEndPoint(Dns.GetHostAddresses(m_externalHostName)[0], m_internalEndPoint.Port);
  177. IPAddress ia = null;
  178. // If it is already an IP, don't resolve it - just return directly
  179. if (IPAddress.TryParse(m_externalHostName, out ia))
  180. return new IPEndPoint(ia, m_internalEndPoint.Port);
  181. // Reset for next check
  182. ia = null;
  183. try
  184. {
  185. foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
  186. {
  187. if (ia == null)
  188. ia = Adr;
  189. if (Adr.AddressFamily == AddressFamily.InterNetwork)
  190. {
  191. ia = Adr;
  192. break;
  193. }
  194. }
  195. }
  196. catch (SocketException e)
  197. {
  198. throw new Exception(
  199. "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
  200. e + "' attached to this exception", e);
  201. }
  202. return new IPEndPoint(ia, m_internalEndPoint.Port);
  203. }
  204. set { m_externalHostName = value.ToString(); }
  205. }
  206. public string ExternalHostName
  207. {
  208. get { return m_externalHostName; }
  209. set { m_externalHostName = value; }
  210. }
  211. public IPEndPoint InternalEndPoint
  212. {
  213. get { return m_internalEndPoint; }
  214. set { m_internalEndPoint = value; }
  215. }
  216. public uint RegionLocX
  217. {
  218. get { return m_regionLocX.Value; }
  219. set { m_regionLocX = value; }
  220. }
  221. public uint RegionLocY
  222. {
  223. get { return m_regionLocY.Value; }
  224. set { m_regionLocY = value; }
  225. }
  226. public ulong RegionHandle
  227. {
  228. get { return Util.UIntsToLong((RegionLocX * (uint) Constants.RegionSize), (RegionLocY * (uint) Constants.RegionSize)); }
  229. }
  230. public int getInternalEndPointPort()
  231. {
  232. return m_internalEndPoint.Port;
  233. }
  234. public Dictionary<string, object> ToKeyValuePairs()
  235. {
  236. Dictionary<string, object> kvp = new Dictionary<string, object>();
  237. kvp["uuid"] = RegionID.ToString();
  238. kvp["locX"] = RegionLocX.ToString();
  239. kvp["locY"] = RegionLocY.ToString();
  240. kvp["external_ip_address"] = ExternalEndPoint.Address.ToString();
  241. kvp["external_port"] = ExternalEndPoint.Port.ToString();
  242. kvp["external_host_name"] = ExternalHostName;
  243. kvp["http_port"] = HttpPort.ToString();
  244. kvp["internal_ip_address"] = InternalEndPoint.Address.ToString();
  245. kvp["internal_port"] = InternalEndPoint.Port.ToString();
  246. kvp["alternate_ports"] = m_allow_alternate_ports.ToString();
  247. kvp["server_uri"] = ServerURI;
  248. return kvp;
  249. }
  250. public SimpleRegionInfo(Dictionary<string, object> kvp)
  251. {
  252. if ((kvp["external_ip_address"] != null) && (kvp["external_port"] != null))
  253. {
  254. int port = 0;
  255. Int32.TryParse((string)kvp["external_port"], out port);
  256. IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)kvp["external_ip_address"]), port);
  257. ExternalEndPoint = ep;
  258. }
  259. else
  260. ExternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
  261. if (kvp["external_host_name"] != null)
  262. ExternalHostName = (string)kvp["external_host_name"];
  263. if (kvp["http_port"] != null)
  264. {
  265. UInt32 port = 0;
  266. UInt32.TryParse((string)kvp["http_port"], out port);
  267. HttpPort = port;
  268. }
  269. if ((kvp["internal_ip_address"] != null) && (kvp["internal_port"] != null))
  270. {
  271. int port = 0;
  272. Int32.TryParse((string)kvp["internal_port"], out port);
  273. IPEndPoint ep = new IPEndPoint(IPAddress.Parse((string)kvp["internal_ip_address"]), port);
  274. InternalEndPoint = ep;
  275. }
  276. else
  277. InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
  278. if (kvp["alternate_ports"] != null)
  279. {
  280. bool alts = false;
  281. Boolean.TryParse((string)kvp["alternate_ports"], out alts);
  282. m_allow_alternate_ports = alts;
  283. }
  284. if (kvp["server_uri"] != null)
  285. ServerURI = (string)kvp["server_uri"];
  286. }
  287. }
  288. public class RegionInfo
  289. {
  290. // private static readonly log4net.ILog m_log
  291. // = log4net.LogManager.GetLogger(System.Reflection.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. m_externalHostName = Util.GetLocalHost().ToString();
  646. else
  647. m_externalHostName = externalName;
  648. m_regionType = config.GetString("RegionType", String.Empty);
  649. // Prim stuff
  650. //
  651. m_nonphysPrimMax = config.GetInt("NonphysicalPrimMax", 256);
  652. m_physPrimMax = config.GetInt("PhysicalPrimMax", 10);
  653. m_clampPrimSize = config.GetBoolean("ClampPrimSize", false);
  654. m_objectCapacity = config.GetInt("MaxPrims", 15000);
  655. // Multi-tenancy
  656. //
  657. ScopeID = new UUID(config.GetString("ScopeID", UUID.Zero.ToString()));
  658. }
  659. private void WriteNiniConfig(IConfigSource source)
  660. {
  661. IConfig config = source.Configs[RegionName];
  662. if (config != null)
  663. source.Configs.Remove(RegionName);
  664. config = source.AddConfig(RegionName);
  665. config.Set("RegionUUID", RegionID.ToString());
  666. string location = String.Format("{0},{1}", m_regionLocX, m_regionLocY);
  667. config.Set("Location", location);
  668. if (DataStore != String.Empty)
  669. config.Set("Datastore", DataStore);
  670. config.Set("InternalAddress", m_internalEndPoint.Address.ToString());
  671. config.Set("InternalPort", m_internalEndPoint.Port);
  672. config.Set("AllowAlternatePorts", m_allow_alternate_ports.ToString());
  673. config.Set("ExternalHostName", m_externalHostName);
  674. if (m_nonphysPrimMax != 0)
  675. config.Set("NonphysicalPrimMax", m_nonphysPrimMax);
  676. if (m_physPrimMax != 0)
  677. config.Set("PhysicalPrimMax", m_physPrimMax);
  678. config.Set("ClampPrimSize", m_clampPrimSize.ToString());
  679. if (m_objectCapacity != 0)
  680. config.Set("MaxPrims", m_objectCapacity);
  681. if (ScopeID != UUID.Zero)
  682. config.Set("ScopeID", ScopeID.ToString());
  683. if (RegionType != String.Empty)
  684. config.Set("RegionType", RegionType);
  685. }
  686. public bool ignoreIncomingConfiguration(string configuration_key, object configuration_result)
  687. {
  688. return true;
  689. }
  690. public void SaveRegionToFile(string description, string filename)
  691. {
  692. if (filename.ToLower().EndsWith(".ini"))
  693. {
  694. IniConfigSource source = new IniConfigSource();
  695. try
  696. {
  697. source = new IniConfigSource(filename); // Load if it exists
  698. }
  699. catch (Exception)
  700. {
  701. }
  702. WriteNiniConfig(source);
  703. source.Save(filename);
  704. return;
  705. }
  706. configMember = new ConfigurationMember(filename, description, loadConfigurationOptionsFromMe,
  707. ignoreIncomingConfiguration, false);
  708. configMember.performConfigurationRetrieve();
  709. RegionFile = filename;
  710. }
  711. public void loadConfigurationOptionsFromMe()
  712. {
  713. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID_NULL_FREE,
  714. "UUID of Region (Default is recommended, random UUID)",
  715. RegionID.ToString(), true);
  716. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  717. "Region Name", RegionName, true);
  718. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  719. "Grid Location (X Axis)", m_regionLocX.ToString(), true);
  720. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  721. "Grid Location (Y Axis)", m_regionLocY.ToString(), true);
  722. //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  723. configMember.addConfigurationOption("internal_ip_address",
  724. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  725. "Internal IP Address for incoming UDP client connections",
  726. m_internalEndPoint.Address.ToString(),
  727. true);
  728. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  729. "Internal IP Port for incoming UDP client connections",
  730. m_internalEndPoint.Port.ToString(), true);
  731. configMember.addConfigurationOption("allow_alternate_ports",
  732. ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  733. "Allow sim to find alternate UDP ports when ports are in use?",
  734. m_allow_alternate_ports.ToString(), true);
  735. configMember.addConfigurationOption("external_host_name",
  736. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  737. "External Host Name", m_externalHostName, true);
  738. configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  739. "Last Map UUID", lastMapUUID.ToString(), true);
  740. configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  741. "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
  742. configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  743. "Maximum size for nonphysical prims", m_nonphysPrimMax.ToString(), true);
  744. configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  745. "Maximum size for physical prims", m_physPrimMax.ToString(), true);
  746. configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  747. "Clamp prims to max size", m_clampPrimSize.ToString(), true);
  748. configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  749. "Max objects this sim will hold", m_objectCapacity.ToString(), true);
  750. configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  751. "Scope ID for this region", ScopeID.ToString(), true);
  752. configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  753. "Free form string describing the type of region", String.Empty, true);
  754. }
  755. public void loadConfigurationOptions()
  756. {
  757. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  758. "UUID of Region (Default is recommended, random UUID)",
  759. UUID.Random().ToString(), true);
  760. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  761. "Region Name", "OpenSim Test", false);
  762. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  763. "Grid Location (X Axis)", "1000", false);
  764. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  765. "Grid Location (Y Axis)", "1000", false);
  766. //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  767. configMember.addConfigurationOption("internal_ip_address",
  768. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  769. "Internal IP Address for incoming UDP client connections", "0.0.0.0",
  770. false);
  771. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  772. "Internal IP Port for incoming UDP client connections",
  773. ConfigSettings.DefaultRegionHttpPort.ToString(), false);
  774. configMember.addConfigurationOption("allow_alternate_ports", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  775. "Allow sim to find alternate UDP ports when ports are in use?",
  776. "false", true);
  777. configMember.addConfigurationOption("external_host_name",
  778. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  779. "External Host Name", "127.0.0.1", false);
  780. configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  781. "Last Map UUID", lastMapUUID.ToString(), true);
  782. configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  783. "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
  784. configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  785. "Maximum size for nonphysical prims", "0", true);
  786. configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  787. "Maximum size for physical prims", "0", true);
  788. configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  789. "Clamp prims to max size", "false", true);
  790. configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  791. "Max objects this sim will hold", "0", true);
  792. configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  793. "Scope ID for this region", UUID.Zero.ToString(), true);
  794. configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  795. "Region Type", String.Empty, true);
  796. }
  797. public bool handleIncomingConfiguration(string configuration_key, object configuration_result)
  798. {
  799. switch (configuration_key)
  800. {
  801. case "sim_UUID":
  802. RegionID = (UUID) configuration_result;
  803. originRegionID = (UUID) configuration_result;
  804. break;
  805. case "sim_name":
  806. RegionName = (string) configuration_result;
  807. break;
  808. case "sim_location_x":
  809. m_regionLocX = (uint) configuration_result;
  810. break;
  811. case "sim_location_y":
  812. m_regionLocY = (uint) configuration_result;
  813. break;
  814. case "datastore":
  815. DataStore = (string) configuration_result;
  816. break;
  817. case "internal_ip_address":
  818. IPAddress address = (IPAddress) configuration_result;
  819. m_internalEndPoint = new IPEndPoint(address, 0);
  820. break;
  821. case "internal_ip_port":
  822. m_internalEndPoint.Port = (int) configuration_result;
  823. break;
  824. case "allow_alternate_ports":
  825. m_allow_alternate_ports = (bool) configuration_result;
  826. break;
  827. case "external_host_name":
  828. if ((string) configuration_result != "SYSTEMIP")
  829. {
  830. m_externalHostName = (string) configuration_result;
  831. }
  832. else
  833. {
  834. m_externalHostName = Util.GetLocalHost().ToString();
  835. }
  836. break;
  837. case "lastmap_uuid":
  838. lastMapUUID = (UUID)configuration_result;
  839. break;
  840. case "lastmap_refresh":
  841. lastMapRefresh = (string)configuration_result;
  842. break;
  843. case "nonphysical_prim_max":
  844. m_nonphysPrimMax = (int)configuration_result;
  845. break;
  846. case "physical_prim_max":
  847. m_physPrimMax = (int)configuration_result;
  848. break;
  849. case "clamp_prim_size":
  850. m_clampPrimSize = (bool)configuration_result;
  851. break;
  852. case "object_capacity":
  853. m_objectCapacity = (int)configuration_result;
  854. break;
  855. case "scope_id":
  856. ScopeID = (UUID)configuration_result;
  857. break;
  858. case "region_type":
  859. m_regionType = (string)configuration_result;
  860. break;
  861. }
  862. return true;
  863. }
  864. public void SaveLastMapUUID(UUID mapUUID)
  865. {
  866. lastMapUUID = mapUUID;
  867. lastMapRefresh = Util.UnixTimeSinceEpoch().ToString();
  868. if (configMember == null)
  869. return;
  870. configMember.forceSetConfigurationOption("lastmap_uuid", mapUUID.ToString());
  871. configMember.forceSetConfigurationOption("lastmap_refresh", lastMapRefresh);
  872. }
  873. public OSDMap PackRegionInfoData()
  874. {
  875. OSDMap args = new OSDMap();
  876. args["region_id"] = OSD.FromUUID(RegionID);
  877. if ((RegionName != null) && !RegionName.Equals(""))
  878. args["region_name"] = OSD.FromString(RegionName);
  879. args["external_host_name"] = OSD.FromString(ExternalHostName);
  880. args["http_port"] = OSD.FromString(HttpPort.ToString());
  881. args["server_uri"] = OSD.FromString(ServerURI);
  882. args["region_xloc"] = OSD.FromString(RegionLocX.ToString());
  883. args["region_yloc"] = OSD.FromString(RegionLocY.ToString());
  884. args["internal_ep_address"] = OSD.FromString(InternalEndPoint.Address.ToString());
  885. args["internal_ep_port"] = OSD.FromString(InternalEndPoint.Port.ToString());
  886. if ((RemotingAddress != null) && !RemotingAddress.Equals(""))
  887. args["remoting_address"] = OSD.FromString(RemotingAddress);
  888. args["remoting_port"] = OSD.FromString(RemotingPort.ToString());
  889. args["allow_alt_ports"] = OSD.FromBoolean(m_allow_alternate_ports);
  890. if ((proxyUrl != null) && !proxyUrl.Equals(""))
  891. args["proxy_url"] = OSD.FromString(proxyUrl);
  892. if (RegionType != String.Empty)
  893. args["region_type"] = OSD.FromString(RegionType);
  894. return args;
  895. }
  896. public void UnpackRegionInfoData(OSDMap args)
  897. {
  898. if (args["region_id"] != null)
  899. RegionID = args["region_id"].AsUUID();
  900. if (args["region_name"] != null)
  901. RegionName = args["region_name"].AsString();
  902. if (args["external_host_name"] != null)
  903. ExternalHostName = args["external_host_name"].AsString();
  904. if (args["http_port"] != null)
  905. UInt32.TryParse(args["http_port"].AsString(), out m_httpPort);
  906. if (args["server_uri"] != null)
  907. ServerURI = args["server_uri"].AsString();
  908. if (args["region_xloc"] != null)
  909. {
  910. uint locx;
  911. UInt32.TryParse(args["region_xloc"].AsString(), out locx);
  912. RegionLocX = locx;
  913. }
  914. if (args["region_yloc"] != null)
  915. {
  916. uint locy;
  917. UInt32.TryParse(args["region_yloc"].AsString(), out locy);
  918. RegionLocY = locy;
  919. }
  920. IPAddress ip_addr = null;
  921. if (args["internal_ep_address"] != null)
  922. {
  923. IPAddress.TryParse(args["internal_ep_address"].AsString(), out ip_addr);
  924. }
  925. int port = 0;
  926. if (args["internal_ep_port"] != null)
  927. {
  928. Int32.TryParse(args["internal_ep_port"].AsString(), out port);
  929. }
  930. InternalEndPoint = new IPEndPoint(ip_addr, port);
  931. if (args["remoting_address"] != null)
  932. RemotingAddress = args["remoting_address"].AsString();
  933. if (args["remoting_port"] != null)
  934. UInt32.TryParse(args["remoting_port"].AsString(), out m_remotingPort);
  935. if (args["allow_alt_ports"] != null)
  936. m_allow_alternate_ports = args["allow_alt_ports"].AsBoolean();
  937. if (args["proxy_url"] != null)
  938. proxyUrl = args["proxy_url"].AsString();
  939. if (args["region_type"] != null)
  940. m_regionType = args["region_type"].AsString();
  941. }
  942. public static RegionInfo Create(UUID regionID, string regionName, uint regX, uint regY, string externalHostName, uint httpPort, uint simPort, uint remotingPort, string serverURI)
  943. {
  944. RegionInfo regionInfo;
  945. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(externalHostName), (int)simPort);
  946. regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, externalHostName);
  947. regionInfo.RemotingPort = remotingPort;
  948. regionInfo.RemotingAddress = externalHostName;
  949. regionInfo.HttpPort = httpPort;
  950. regionInfo.RegionID = regionID;
  951. regionInfo.RegionName = regionName;
  952. regionInfo.ServerURI = serverURI;
  953. return regionInfo;
  954. }
  955. public int getInternalEndPointPort()
  956. {
  957. return m_internalEndPoint.Port;
  958. }
  959. public Dictionary<string, object> ToKeyValuePairs()
  960. {
  961. Dictionary<string, object> kvp = new Dictionary<string, object>();
  962. kvp["uuid"] = RegionID.ToString();
  963. kvp["locX"] = RegionLocX.ToString();
  964. kvp["locY"] = RegionLocY.ToString();
  965. kvp["external_ip_address"] = ExternalEndPoint.Address.ToString();
  966. kvp["external_port"] = ExternalEndPoint.Port.ToString();
  967. kvp["external_host_name"] = ExternalHostName;
  968. kvp["http_port"] = HttpPort.ToString();
  969. kvp["internal_ip_address"] = InternalEndPoint.Address.ToString();
  970. kvp["internal_port"] = InternalEndPoint.Port.ToString();
  971. kvp["alternate_ports"] = m_allow_alternate_ports.ToString();
  972. kvp["server_uri"] = ServerURI;
  973. return kvp;
  974. }
  975. }
  976. }