RegionInfo.cs 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  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. public class RegionInfo
  95. {
  96. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  97. private static readonly string LogHeader = "[REGION INFO]";
  98. public bool commFailTF = false;
  99. public ConfigurationMember configMember;
  100. public string RegionFile = String.Empty;
  101. public bool isSandbox = false;
  102. public bool Persistent = true;
  103. private EstateSettings m_estateSettings;
  104. private RegionSettings m_regionSettings;
  105. // private IConfigSource m_configSource = null;
  106. public UUID originRegionID = UUID.Zero;
  107. public string proxyUrl = "";
  108. public int ProxyOffset = 0;
  109. public string regionSecret = UUID.Random().ToString();
  110. public string osSecret;
  111. public UUID lastMapUUID = UUID.Zero;
  112. public string lastMapRefresh = "0";
  113. private float m_nonphysPrimMin = 0;
  114. private int m_nonphysPrimMax = 0;
  115. private float m_physPrimMin = 0;
  116. private int m_physPrimMax = 0;
  117. private bool m_clampPrimSize = false;
  118. private int m_objectCapacity = 0;
  119. private int m_linksetCapacity = 0;
  120. private int m_agentCapacity = 0;
  121. private string m_regionType = String.Empty;
  122. private RegionLightShareData m_windlight = new RegionLightShareData();
  123. protected uint m_httpPort;
  124. protected string m_serverURI;
  125. protected string m_regionName = String.Empty;
  126. protected bool Allow_Alternate_Ports;
  127. public bool m_allow_alternate_ports;
  128. protected string m_externalHostName;
  129. protected IPEndPoint m_internalEndPoint;
  130. protected uint m_remotingPort;
  131. public UUID RegionID = UUID.Zero;
  132. public string RemotingAddress;
  133. public UUID ScopeID = UUID.Zero;
  134. private UUID m_maptileStaticUUID = UUID.Zero;
  135. public uint WorldLocX = 0;
  136. public uint WorldLocY = 0;
  137. public uint WorldLocZ = 0;
  138. public uint RegionSizeX = Constants.RegionSize;
  139. public uint RegionSizeY = Constants.RegionSize;
  140. public uint RegionSizeZ = Constants.RegionHeight;
  141. private Dictionary<String, String> m_otherSettings = new Dictionary<string, string>();
  142. // Apparently, we're applying the same estatesettings regardless of whether it's local or remote.
  143. // MT: Yes. Estates can't span trust boundaries. Therefore, it can be
  144. // assumed that all instances belonging to one estate are able to
  145. // access the same database server. Since estate settings are lodaed
  146. // from there, that should be sufficient for full remote administration
  147. // File based loading
  148. //
  149. public RegionInfo(string description, string filename, bool skipConsoleConfig, IConfigSource configSource) : this(description, filename, skipConsoleConfig, configSource, String.Empty)
  150. {
  151. }
  152. public RegionInfo(string description, string filename, bool skipConsoleConfig, IConfigSource configSource, string configName)
  153. {
  154. // m_configSource = configSource;
  155. if (filename.ToLower().EndsWith(".ini"))
  156. {
  157. if (!File.Exists(filename)) // New region config request
  158. {
  159. IniConfigSource newFile = new IniConfigSource();
  160. ReadNiniConfig(newFile, configName);
  161. newFile.Save(filename);
  162. RegionFile = filename;
  163. return;
  164. }
  165. IniConfigSource source = new IniConfigSource(filename);
  166. bool saveFile = false;
  167. if (source.Configs[configName] == null)
  168. saveFile = true;
  169. ReadNiniConfig(source, configName);
  170. if (configName != String.Empty && saveFile)
  171. source.Save(filename);
  172. RegionFile = filename;
  173. return;
  174. }
  175. try
  176. {
  177. // This will throw if it's not legal Nini XML format
  178. // and thereby toss it to the legacy loader
  179. //
  180. IConfigSource xmlsource = new XmlConfigSource(filename);
  181. ReadNiniConfig(xmlsource, configName);
  182. RegionFile = filename;
  183. return;
  184. }
  185. catch (Exception)
  186. {
  187. }
  188. configMember =
  189. new ConfigurationMember(filename, description, loadConfigurationOptions, handleIncomingConfiguration, !skipConsoleConfig);
  190. configMember.performConfigurationRetrieve();
  191. RegionFile = filename;
  192. }
  193. // The web loader uses this
  194. //
  195. public RegionInfo(string description, XmlNode xmlNode, bool skipConsoleConfig, IConfigSource configSource)
  196. {
  197. // m_configSource = configSource;
  198. configMember =
  199. new ConfigurationMember(xmlNode, description, loadConfigurationOptions, handleIncomingConfiguration, !skipConsoleConfig);
  200. configMember.performConfigurationRetrieve();
  201. m_serverURI = string.Empty;
  202. }
  203. public RegionInfo(uint legacyRegionLocX, uint legacyRegionLocY, IPEndPoint internalEndPoint, string externalUri)
  204. {
  205. RegionLocX = legacyRegionLocX;
  206. RegionLocY = legacyRegionLocY;
  207. RegionSizeX = Constants.RegionSize;
  208. RegionSizeY = Constants.RegionSize;
  209. m_internalEndPoint = internalEndPoint;
  210. m_externalHostName = externalUri;
  211. m_serverURI = string.Empty;
  212. }
  213. public RegionInfo()
  214. {
  215. m_serverURI = string.Empty;
  216. }
  217. public EstateSettings EstateSettings
  218. {
  219. get
  220. {
  221. if (m_estateSettings == null)
  222. {
  223. m_estateSettings = new EstateSettings();
  224. }
  225. return m_estateSettings;
  226. }
  227. set { m_estateSettings = value; }
  228. }
  229. public RegionSettings RegionSettings
  230. {
  231. get
  232. {
  233. if (m_regionSettings == null)
  234. {
  235. m_regionSettings = new RegionSettings();
  236. }
  237. return m_regionSettings;
  238. }
  239. set { m_regionSettings = value; }
  240. }
  241. public RegionLightShareData WindlightSettings
  242. {
  243. get
  244. {
  245. if (m_windlight == null)
  246. {
  247. m_windlight = new RegionLightShareData();
  248. }
  249. return m_windlight;
  250. }
  251. set { m_windlight = value; }
  252. }
  253. public float NonphysPrimMin
  254. {
  255. get { return m_nonphysPrimMin; }
  256. }
  257. public int NonphysPrimMax
  258. {
  259. get { return m_nonphysPrimMax; }
  260. }
  261. public float PhysPrimMin
  262. {
  263. get { return m_physPrimMin; }
  264. }
  265. public int PhysPrimMax
  266. {
  267. get { return m_physPrimMax; }
  268. }
  269. public bool ClampPrimSize
  270. {
  271. get { return m_clampPrimSize; }
  272. }
  273. public int ObjectCapacity
  274. {
  275. get { return m_objectCapacity; }
  276. }
  277. public int LinksetCapacity
  278. {
  279. get { return m_linksetCapacity; }
  280. }
  281. public int AgentCapacity
  282. {
  283. get { return m_agentCapacity; }
  284. }
  285. public byte AccessLevel
  286. {
  287. get { return (byte)Util.ConvertMaturityToAccessLevel((uint)RegionSettings.Maturity); }
  288. }
  289. public string RegionType
  290. {
  291. get { return m_regionType; }
  292. }
  293. public UUID MaptileStaticUUID
  294. {
  295. get { return m_maptileStaticUUID; }
  296. }
  297. /// <summary>
  298. /// The port by which http communication occurs with the region (most noticeably, CAPS communication)
  299. /// </summary>
  300. public uint HttpPort
  301. {
  302. get { return m_httpPort; }
  303. set { m_httpPort = value; }
  304. }
  305. /// <summary>
  306. /// A well-formed URI for the host region server (namely "http://" + ExternalHostName)
  307. /// </summary>
  308. public string ServerURI
  309. {
  310. get {
  311. if ( m_serverURI != string.Empty ) {
  312. return m_serverURI;
  313. } else {
  314. return "http://" + m_externalHostName + ":" + m_httpPort + "/";
  315. }
  316. }
  317. set {
  318. if ( value.EndsWith("/") ) {
  319. m_serverURI = value;
  320. } else {
  321. m_serverURI = value + '/';
  322. }
  323. }
  324. }
  325. public string RegionName
  326. {
  327. get { return m_regionName; }
  328. set { m_regionName = value; }
  329. }
  330. public uint RemotingPort
  331. {
  332. get { return m_remotingPort; }
  333. set { m_remotingPort = value; }
  334. }
  335. /// <value>
  336. /// This accessor can throw all the exceptions that Dns.GetHostAddresses can throw.
  337. ///
  338. /// XXX Isn't this really doing too much to be a simple getter, rather than an explict method?
  339. /// </value>
  340. public IPEndPoint ExternalEndPoint
  341. {
  342. get
  343. {
  344. // Old one defaults to IPv6
  345. //return new IPEndPoint(Dns.GetHostAddresses(m_externalHostName)[0], m_internalEndPoint.Port);
  346. IPAddress ia = null;
  347. // If it is already an IP, don't resolve it - just return directly
  348. if (IPAddress.TryParse(m_externalHostName, out ia))
  349. return new IPEndPoint(ia, m_internalEndPoint.Port);
  350. // Reset for next check
  351. ia = null;
  352. try
  353. {
  354. foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
  355. {
  356. if (ia == null)
  357. ia = Adr;
  358. if (Adr.AddressFamily == AddressFamily.InterNetwork)
  359. {
  360. ia = Adr;
  361. break;
  362. }
  363. }
  364. }
  365. catch (SocketException e)
  366. {
  367. throw new Exception(
  368. "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
  369. e + "' attached to this exception", e);
  370. }
  371. return new IPEndPoint(ia, m_internalEndPoint.Port);
  372. }
  373. set { m_externalHostName = value.ToString(); }
  374. }
  375. public string ExternalHostName
  376. {
  377. get { return m_externalHostName; }
  378. set { m_externalHostName = value; }
  379. }
  380. public IPEndPoint InternalEndPoint
  381. {
  382. get { return m_internalEndPoint; }
  383. set { m_internalEndPoint = value; }
  384. }
  385. /// <summary>
  386. /// The x co-ordinate of this region in map tiles (e.g. 1000).
  387. /// Coordinate is scaled as world coordinates divided by the legacy region size
  388. /// and is thus is the number of legacy regions.
  389. /// </summary>
  390. public uint RegionLocX
  391. {
  392. get { return WorldLocX / Constants.RegionSize; }
  393. set { WorldLocX = value * Constants.RegionSize; }
  394. }
  395. /// <summary>
  396. /// The y co-ordinate of this region in map tiles (e.g. 1000).
  397. /// Coordinate is scaled as world coordinates divided by the legacy region size
  398. /// and is thus is the number of legacy regions.
  399. /// </summary>
  400. public uint RegionLocY
  401. {
  402. get { return WorldLocY / Constants.RegionSize; }
  403. set { WorldLocY = value * Constants.RegionSize; }
  404. }
  405. public void SetDefaultRegionSize()
  406. {
  407. WorldLocX = 0;
  408. WorldLocY = 0;
  409. WorldLocZ = 0;
  410. RegionSizeX = Constants.RegionSize;
  411. RegionSizeY = Constants.RegionSize;
  412. RegionSizeZ = Constants.RegionHeight;
  413. }
  414. // A unique region handle is created from the region's world coordinates.
  415. // This cannot be changed because some code expects to receive the region handle and then
  416. // compute the region coordinates from it.
  417. public ulong RegionHandle
  418. {
  419. get { return Util.UIntsToLong(WorldLocX, WorldLocY); }
  420. }
  421. public void SetEndPoint(string ipaddr, int port)
  422. {
  423. IPAddress tmpIP = IPAddress.Parse(ipaddr);
  424. IPEndPoint tmpEPE = new IPEndPoint(tmpIP, port);
  425. m_internalEndPoint = tmpEPE;
  426. }
  427. public string GetOtherSetting(string key)
  428. {
  429. string val;
  430. string keylower = key.ToLower();
  431. if (m_otherSettings.TryGetValue(keylower, out val))
  432. return val;
  433. m_log.DebugFormat("[RegionInfo] Could not locate value for parameter {0}", key);
  434. return null;
  435. }
  436. public void SetOtherSetting(string key, string value)
  437. {
  438. string keylower = key.ToLower();
  439. m_otherSettings[keylower] = value;
  440. }
  441. private void ReadNiniConfig(IConfigSource source, string name)
  442. {
  443. // bool creatingNew = false;
  444. if (source.Configs.Count == 0)
  445. {
  446. MainConsole.Instance.Output("=====================================\n");
  447. MainConsole.Instance.Output("We are now going to ask a couple of questions about your region.\n");
  448. MainConsole.Instance.Output("You can press 'enter' without typing anything to use the default\n");
  449. MainConsole.Instance.Output("the default is displayed between [ ] brackets.\n");
  450. MainConsole.Instance.Output("=====================================\n");
  451. if (name == String.Empty)
  452. {
  453. while (name.Trim() == string.Empty)
  454. {
  455. name = MainConsole.Instance.CmdPrompt("New region name", name);
  456. if (name.Trim() == string.Empty)
  457. {
  458. MainConsole.Instance.Output("Cannot interactively create region with no name");
  459. }
  460. }
  461. }
  462. source.AddConfig(name);
  463. // creatingNew = true;
  464. }
  465. if (name == String.Empty)
  466. name = source.Configs[0].Name;
  467. if (source.Configs[name] == null)
  468. {
  469. source.AddConfig(name);
  470. }
  471. RegionName = name;
  472. IConfig config = source.Configs[name];
  473. // Track all of the keys in this config and remove as they are processed
  474. // The remaining keys will be added to generic key-value storage for
  475. // whoever might need it
  476. HashSet<String> allKeys = new HashSet<String>();
  477. foreach (string s in config.GetKeys())
  478. {
  479. allKeys.Add(s);
  480. }
  481. // RegionUUID
  482. //
  483. allKeys.Remove("RegionUUID");
  484. string regionUUID = config.GetString("RegionUUID", string.Empty);
  485. if (!UUID.TryParse(regionUUID.Trim(), out RegionID))
  486. {
  487. UUID newID = UUID.Random();
  488. while (RegionID == UUID.Zero)
  489. {
  490. regionUUID = MainConsole.Instance.CmdPrompt("RegionUUID", newID.ToString());
  491. if (!UUID.TryParse(regionUUID.Trim(), out RegionID))
  492. {
  493. MainConsole.Instance.Output("RegionUUID must be a valid UUID");
  494. }
  495. }
  496. config.Set("RegionUUID", regionUUID);
  497. }
  498. originRegionID = RegionID; // What IS this?! (Needed for RegionCombinerModule?)
  499. // Location
  500. //
  501. allKeys.Remove("Location");
  502. string location = config.GetString("Location", String.Empty);
  503. if (location == String.Empty)
  504. {
  505. location = MainConsole.Instance.CmdPrompt("Region Location", "1000,1000");
  506. config.Set("Location", location);
  507. }
  508. string[] locationElements = location.Split(new char[] {','});
  509. RegionLocX = Convert.ToUInt32(locationElements[0]);
  510. RegionLocY = Convert.ToUInt32(locationElements[1]);
  511. // Region size
  512. // Default to legacy region size if not specified.
  513. allKeys.Remove("SizeX");
  514. string configSizeX = config.GetString("SizeX", Constants.RegionSize.ToString());
  515. config.Set("SizeX", configSizeX);
  516. RegionSizeX = Convert.ToUInt32(configSizeX);
  517. allKeys.Remove("SizeY");
  518. string configSizeY = config.GetString("SizeY", Constants.RegionSize.ToString());
  519. config.Set("SizeY", configSizeX);
  520. RegionSizeY = Convert.ToUInt32(configSizeY);
  521. allKeys.Remove("SizeZ");
  522. string configSizeZ = config.GetString("SizeZ", Constants.RegionHeight.ToString());
  523. config.Set("SizeZ", configSizeX);
  524. RegionSizeZ = Convert.ToUInt32(configSizeZ);
  525. DoRegionSizeSanityChecks();
  526. // InternalAddress
  527. //
  528. IPAddress address;
  529. allKeys.Remove("InternalAddress");
  530. if (config.Contains("InternalAddress"))
  531. {
  532. address = IPAddress.Parse(config.GetString("InternalAddress", String.Empty));
  533. }
  534. else
  535. {
  536. address = IPAddress.Parse(MainConsole.Instance.CmdPrompt("Internal IP address", "0.0.0.0"));
  537. config.Set("InternalAddress", address.ToString());
  538. }
  539. // InternalPort
  540. //
  541. int port;
  542. allKeys.Remove("InternalPort");
  543. if (config.Contains("InternalPort"))
  544. {
  545. port = config.GetInt("InternalPort", 9000);
  546. }
  547. else
  548. {
  549. port = Convert.ToInt32(MainConsole.Instance.CmdPrompt("Internal port", "9000"));
  550. config.Set("InternalPort", port);
  551. }
  552. m_internalEndPoint = new IPEndPoint(address, port);
  553. // AllowAlternatePorts
  554. //
  555. allKeys.Remove("AllowAlternatePorts");
  556. if (config.Contains("AllowAlternatePorts"))
  557. {
  558. m_allow_alternate_ports = config.GetBoolean("AllowAlternatePorts", true);
  559. }
  560. else
  561. {
  562. m_allow_alternate_ports = Convert.ToBoolean(MainConsole.Instance.CmdPrompt("Allow alternate ports", "False"));
  563. config.Set("AllowAlternatePorts", m_allow_alternate_ports.ToString());
  564. }
  565. // ExternalHostName
  566. //
  567. allKeys.Remove("ExternalHostName");
  568. string externalName;
  569. if (config.Contains("ExternalHostName"))
  570. {
  571. externalName = config.GetString("ExternalHostName", "SYSTEMIP");
  572. }
  573. else
  574. {
  575. externalName = MainConsole.Instance.CmdPrompt("External host name", "SYSTEMIP");
  576. config.Set("ExternalHostName", externalName);
  577. }
  578. if (externalName == "SYSTEMIP")
  579. {
  580. m_externalHostName = Util.GetLocalHost().ToString();
  581. m_log.InfoFormat(
  582. "[REGIONINFO]: Resolving SYSTEMIP to {0} for external hostname of region {1}",
  583. m_externalHostName, name);
  584. }
  585. else
  586. {
  587. m_externalHostName = externalName;
  588. }
  589. // RegionType
  590. m_regionType = config.GetString("RegionType", String.Empty);
  591. allKeys.Remove("RegionType");
  592. #region Prim and map stuff
  593. m_nonphysPrimMin = config.GetFloat("NonPhysicalPrimMin", 0);
  594. allKeys.Remove("NonPhysicalPrimMin");
  595. m_nonphysPrimMax = config.GetInt("NonPhysicalPrimMax", 0);
  596. allKeys.Remove("NonPhysicalPrimMax");
  597. m_physPrimMin = config.GetFloat("PhysicalPrimMin", 0);
  598. allKeys.Remove("PhysicalPrimMin");
  599. m_physPrimMax = config.GetInt("PhysicalPrimMax", 0);
  600. allKeys.Remove("PhysicalPrimMax");
  601. m_clampPrimSize = config.GetBoolean("ClampPrimSize", false);
  602. allKeys.Remove("ClampPrimSize");
  603. m_objectCapacity = config.GetInt("MaxPrims", 15000);
  604. allKeys.Remove("MaxPrims");
  605. m_linksetCapacity = config.GetInt("LinksetPrims", 0);
  606. allKeys.Remove("LinksetPrims");
  607. allKeys.Remove("MaptileStaticUUID");
  608. string mapTileStaticUUID = config.GetString("MaptileStaticUUID", UUID.Zero.ToString());
  609. if (UUID.TryParse(mapTileStaticUUID.Trim(), out m_maptileStaticUUID))
  610. {
  611. config.Set("MaptileStaticUUID", m_maptileStaticUUID.ToString());
  612. }
  613. #endregion
  614. m_agentCapacity = config.GetInt("MaxAgents", 100);
  615. allKeys.Remove("MaxAgents");
  616. // Multi-tenancy
  617. //
  618. ScopeID = new UUID(config.GetString("ScopeID", UUID.Zero.ToString()));
  619. allKeys.Remove("ScopeID");
  620. foreach (String s in allKeys)
  621. {
  622. SetOtherSetting(s, config.GetString(s));
  623. }
  624. }
  625. // Make sure user specified region sizes are sane.
  626. // Must be multiples of legacy region size (256).
  627. private void DoRegionSizeSanityChecks()
  628. {
  629. if (RegionSizeX != Constants.RegionSize || RegionSizeY != Constants.RegionSize)
  630. {
  631. // Doing non-legacy region sizes.
  632. // Enforce region size to be multiples of the legacy region size (256)
  633. uint partial = RegionSizeX % Constants.RegionSize;
  634. if (partial != 0)
  635. {
  636. RegionSizeX -= partial;
  637. if (RegionSizeX == 0)
  638. RegionSizeX = Constants.RegionSize;
  639. m_log.ErrorFormat("{0} Region size must be multiple of {1}. Enforcing {2}.RegionSizeX={3} instead of specified {4}",
  640. LogHeader, Constants.RegionSize, m_regionName, RegionSizeX, RegionSizeX + partial);
  641. }
  642. partial = RegionSizeY % Constants.RegionSize;
  643. if (partial != 0)
  644. {
  645. RegionSizeY -= partial;
  646. if (RegionSizeY == 0)
  647. RegionSizeY = Constants.RegionSize;
  648. m_log.ErrorFormat("{0} Region size must be multiple of {1}. Enforcing {2}.RegionSizeY={3} instead of specified {4}",
  649. LogHeader, Constants.RegionSize, m_regionName, RegionSizeY, RegionSizeY + partial);
  650. }
  651. // Because of things in the viewer, regions MUST be square.
  652. // Remove this check when viewers have been updated.
  653. if (RegionSizeX != RegionSizeY)
  654. {
  655. uint minSize = Math.Min(RegionSizeX, RegionSizeY);
  656. RegionSizeX = minSize;
  657. RegionSizeY = minSize;
  658. m_log.ErrorFormat("{0} Regions must be square until viewers are updated. Forcing region {1} size to <{2},{3}>",
  659. LogHeader, m_regionName, RegionSizeX, RegionSizeY);
  660. }
  661. // There is a practical limit to region size.
  662. if (RegionSizeX > Constants.MaximumRegionSize || RegionSizeY > Constants.MaximumRegionSize)
  663. {
  664. RegionSizeX = Util.Clamp<uint>(RegionSizeX, Constants.RegionSize, Constants.MaximumRegionSize);
  665. RegionSizeY = Util.Clamp<uint>(RegionSizeY, Constants.RegionSize, Constants.MaximumRegionSize);
  666. m_log.ErrorFormat("{0} Region dimensions must be less than {1}. Clamping {2}'s size to <{3},{4}>",
  667. LogHeader, Constants.MaximumRegionSize, m_regionName, RegionSizeX, RegionSizeY);
  668. }
  669. m_log.InfoFormat("{0} Region {1} size set to <{2},{3}>", LogHeader, m_regionName, RegionSizeX, RegionSizeY);
  670. }
  671. }
  672. private void WriteNiniConfig(IConfigSource source)
  673. {
  674. IConfig config = source.Configs[RegionName];
  675. if (config != null)
  676. source.Configs.Remove(config);
  677. config = source.AddConfig(RegionName);
  678. config.Set("RegionUUID", RegionID.ToString());
  679. string location = String.Format("{0},{1}", RegionLocX, RegionLocY);
  680. config.Set("Location", location);
  681. if (RegionSizeX != Constants.RegionSize || RegionSizeY != Constants.RegionSize)
  682. {
  683. config.Set("SizeX", RegionSizeX);
  684. config.Set("SizeY", RegionSizeY);
  685. config.Set("SizeZ", RegionSizeZ);
  686. }
  687. config.Set("InternalAddress", m_internalEndPoint.Address.ToString());
  688. config.Set("InternalPort", m_internalEndPoint.Port);
  689. config.Set("AllowAlternatePorts", m_allow_alternate_ports.ToString());
  690. config.Set("ExternalHostName", m_externalHostName);
  691. if (m_nonphysPrimMin > 0)
  692. config.Set("NonphysicalPrimMax", m_nonphysPrimMin);
  693. if (m_nonphysPrimMax > 0)
  694. config.Set("NonphysicalPrimMax", m_nonphysPrimMax);
  695. if (m_physPrimMin > 0)
  696. config.Set("PhysicalPrimMax", m_physPrimMin);
  697. if (m_physPrimMax > 0)
  698. config.Set("PhysicalPrimMax", m_physPrimMax);
  699. config.Set("ClampPrimSize", m_clampPrimSize.ToString());
  700. if (m_objectCapacity > 0)
  701. config.Set("MaxPrims", m_objectCapacity);
  702. if (m_linksetCapacity > 0)
  703. config.Set("LinksetPrims", m_linksetCapacity);
  704. if (m_agentCapacity > 0)
  705. config.Set("MaxAgents", m_agentCapacity);
  706. if (ScopeID != UUID.Zero)
  707. config.Set("ScopeID", ScopeID.ToString());
  708. if (RegionType != String.Empty)
  709. config.Set("RegionType", RegionType);
  710. if (m_maptileStaticUUID != UUID.Zero)
  711. config.Set("MaptileStaticUUID", m_maptileStaticUUID.ToString());
  712. }
  713. public bool ignoreIncomingConfiguration(string configuration_key, object configuration_result)
  714. {
  715. return true;
  716. }
  717. public void SaveRegionToFile(string description, string filename)
  718. {
  719. if (filename.ToLower().EndsWith(".ini"))
  720. {
  721. IniConfigSource source = new IniConfigSource();
  722. try
  723. {
  724. source = new IniConfigSource(filename); // Load if it exists
  725. }
  726. catch (Exception)
  727. {
  728. }
  729. WriteNiniConfig(source);
  730. source.Save(filename);
  731. return;
  732. }
  733. else if (filename.ToLower().EndsWith(".xml"))
  734. {
  735. configMember = new ConfigurationMember(filename, description, loadConfigurationOptionsFromMe,
  736. ignoreIncomingConfiguration, false);
  737. configMember.performConfigurationRetrieve();
  738. RegionFile = filename;
  739. }
  740. else
  741. throw new Exception("Invalid file type for region persistence.");
  742. }
  743. public void loadConfigurationOptionsFromMe()
  744. {
  745. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID_NULL_FREE,
  746. "UUID of Region (Default is recommended, random UUID)",
  747. RegionID.ToString(), true);
  748. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  749. "Region Name", RegionName, true);
  750. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  751. "Grid Location (X Axis)", RegionLocX.ToString(), true);
  752. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  753. "Grid Location (Y Axis)", RegionLocY.ToString(), true);
  754. configMember.addConfigurationOption("sim_size_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  755. "Size of region in X dimension", RegionSizeX.ToString(), true);
  756. configMember.addConfigurationOption("sim_size_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  757. "Size of region in Y dimension", RegionSizeY.ToString(), true);
  758. configMember.addConfigurationOption("sim_size_z", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  759. "Size of region in Z dimension", RegionSizeZ.ToString(), true);
  760. //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  761. configMember.addConfigurationOption("internal_ip_address",
  762. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  763. "Internal IP Address for incoming UDP client connections",
  764. m_internalEndPoint.Address.ToString(),
  765. true);
  766. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  767. "Internal IP Port for incoming UDP client connections",
  768. m_internalEndPoint.Port.ToString(), true);
  769. configMember.addConfigurationOption("allow_alternate_ports",
  770. ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  771. "Allow sim to find alternate UDP ports when ports are in use?",
  772. m_allow_alternate_ports.ToString(), true);
  773. configMember.addConfigurationOption("external_host_name",
  774. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  775. "External Host Name", m_externalHostName, true);
  776. configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  777. "Last Map UUID", lastMapUUID.ToString(), true);
  778. configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  779. "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
  780. configMember.addConfigurationOption("nonphysical_prim_min", ConfigurationOption.ConfigurationTypes.TYPE_FLOAT,
  781. "Minimum size for nonphysical prims", m_nonphysPrimMin.ToString(), true);
  782. configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  783. "Maximum size for nonphysical prims", m_nonphysPrimMax.ToString(), true);
  784. configMember.addConfigurationOption("physical_prim_min", ConfigurationOption.ConfigurationTypes.TYPE_FLOAT,
  785. "Minimum size for nonphysical prims", m_physPrimMin.ToString(), true);
  786. configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  787. "Maximum size for physical prims", m_physPrimMax.ToString(), true);
  788. configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  789. "Clamp prims to max size", m_clampPrimSize.ToString(), true);
  790. configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  791. "Max objects this sim will hold", m_objectCapacity.ToString(), true);
  792. configMember.addConfigurationOption("linkset_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  793. "Max prims an object will hold", m_linksetCapacity.ToString(), true);
  794. configMember.addConfigurationOption("agent_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  795. "Max avatars this sim will hold", m_agentCapacity.ToString(), true);
  796. configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  797. "Scope ID for this region", ScopeID.ToString(), true);
  798. configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  799. "Free form string describing the type of region", String.Empty, true);
  800. configMember.addConfigurationOption("region_static_maptile", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  801. "UUID of a texture to use as the map for this region", m_maptileStaticUUID.ToString(), true);
  802. }
  803. public void loadConfigurationOptions()
  804. {
  805. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  806. "UUID of Region (Default is recommended, random UUID)",
  807. UUID.Random().ToString(), true);
  808. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  809. "Region Name", "OpenSim Test", false);
  810. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  811. "Grid Location (X Axis)", "1000", false);
  812. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  813. "Grid Location (Y Axis)", "1000", false);
  814. configMember.addConfigurationOption("sim_size_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  815. "Size of region in X dimension", Constants.RegionSize.ToString(), false);
  816. configMember.addConfigurationOption("sim_size_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  817. "Size of region in Y dimension", Constants.RegionSize.ToString(), false);
  818. configMember.addConfigurationOption("sim_size_z", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  819. "Size of region in Z dimension", Constants.RegionHeight.ToString(), false);
  820. //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  821. configMember.addConfigurationOption("internal_ip_address",
  822. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  823. "Internal IP Address for incoming UDP client connections", "0.0.0.0",
  824. false);
  825. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  826. "Internal IP Port for incoming UDP client connections",
  827. ConfigSettings.DefaultRegionHttpPort.ToString(), false);
  828. configMember.addConfigurationOption("allow_alternate_ports", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  829. "Allow sim to find alternate UDP ports when ports are in use?",
  830. "false", true);
  831. configMember.addConfigurationOption("external_host_name",
  832. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  833. "External Host Name", "127.0.0.1", false);
  834. configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  835. "Last Map UUID", lastMapUUID.ToString(), true);
  836. configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  837. "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
  838. configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  839. "Maximum size for nonphysical prims", "0", true);
  840. configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  841. "Maximum size for physical prims", "0", true);
  842. configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  843. "Clamp prims to max size", "false", true);
  844. configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  845. "Max objects this sim will hold", "15000", true);
  846. configMember.addConfigurationOption("agent_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  847. "Max avatars this sim will hold", "100", true);
  848. configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  849. "Scope ID for this region", UUID.Zero.ToString(), true);
  850. configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  851. "Region Type", String.Empty, true);
  852. configMember.addConfigurationOption("region_static_maptile", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  853. "UUID of a texture to use as the map for this region", String.Empty, true);
  854. }
  855. public bool handleIncomingConfiguration(string configuration_key, object configuration_result)
  856. {
  857. switch (configuration_key)
  858. {
  859. case "sim_UUID":
  860. RegionID = (UUID) configuration_result;
  861. originRegionID = (UUID) configuration_result;
  862. break;
  863. case "sim_name":
  864. RegionName = (string) configuration_result;
  865. break;
  866. case "sim_location_x":
  867. RegionLocX = (uint) configuration_result;
  868. break;
  869. case "sim_location_y":
  870. RegionLocY = (uint) configuration_result;
  871. break;
  872. case "sim_size_x":
  873. RegionSizeX = (uint) configuration_result;
  874. break;
  875. case "sim_size_y":
  876. RegionSizeY = (uint) configuration_result;
  877. break;
  878. case "sim_size_z":
  879. RegionSizeZ = (uint) configuration_result;
  880. break;
  881. case "internal_ip_address":
  882. IPAddress address = (IPAddress) configuration_result;
  883. m_internalEndPoint = new IPEndPoint(address, 0);
  884. break;
  885. case "internal_ip_port":
  886. m_internalEndPoint.Port = (int) configuration_result;
  887. break;
  888. case "allow_alternate_ports":
  889. m_allow_alternate_ports = (bool) configuration_result;
  890. break;
  891. case "external_host_name":
  892. if ((string) configuration_result != "SYSTEMIP")
  893. {
  894. m_externalHostName = (string) configuration_result;
  895. }
  896. else
  897. {
  898. m_externalHostName = Util.GetLocalHost().ToString();
  899. }
  900. break;
  901. case "lastmap_uuid":
  902. lastMapUUID = (UUID)configuration_result;
  903. break;
  904. case "lastmap_refresh":
  905. lastMapRefresh = (string)configuration_result;
  906. break;
  907. case "nonphysical_prim_max":
  908. m_nonphysPrimMax = (int)configuration_result;
  909. break;
  910. case "physical_prim_max":
  911. m_physPrimMax = (int)configuration_result;
  912. break;
  913. case "clamp_prim_size":
  914. m_clampPrimSize = (bool)configuration_result;
  915. break;
  916. case "object_capacity":
  917. m_objectCapacity = (int)configuration_result;
  918. break;
  919. case "linkset_capacity":
  920. m_linksetCapacity = (int)configuration_result;
  921. break;
  922. case "agent_capacity":
  923. m_agentCapacity = (int)configuration_result;
  924. break;
  925. case "scope_id":
  926. ScopeID = (UUID)configuration_result;
  927. break;
  928. case "region_type":
  929. m_regionType = (string)configuration_result;
  930. break;
  931. case "region_static_maptile":
  932. m_maptileStaticUUID = (UUID)configuration_result;
  933. break;
  934. }
  935. return true;
  936. }
  937. public void SaveLastMapUUID(UUID mapUUID)
  938. {
  939. lastMapUUID = mapUUID;
  940. lastMapRefresh = Util.UnixTimeSinceEpoch().ToString();
  941. if (configMember == null)
  942. return;
  943. configMember.forceSetConfigurationOption("lastmap_uuid", mapUUID.ToString());
  944. configMember.forceSetConfigurationOption("lastmap_refresh", lastMapRefresh);
  945. }
  946. public OSDMap PackRegionInfoData()
  947. {
  948. OSDMap args = new OSDMap();
  949. args["region_id"] = OSD.FromUUID(RegionID);
  950. if ((RegionName != null) && !RegionName.Equals(""))
  951. args["region_name"] = OSD.FromString(RegionName);
  952. args["external_host_name"] = OSD.FromString(ExternalHostName);
  953. args["http_port"] = OSD.FromString(HttpPort.ToString());
  954. args["server_uri"] = OSD.FromString(ServerURI);
  955. args["region_xloc"] = OSD.FromString(RegionLocX.ToString());
  956. args["region_yloc"] = OSD.FromString(RegionLocY.ToString());
  957. args["region_size_x"] = OSD.FromString(RegionSizeX.ToString());
  958. args["region_size_y"] = OSD.FromString(RegionSizeY.ToString());
  959. args["region_size_z"] = OSD.FromString(RegionSizeZ.ToString());
  960. args["internal_ep_address"] = OSD.FromString(InternalEndPoint.Address.ToString());
  961. args["internal_ep_port"] = OSD.FromString(InternalEndPoint.Port.ToString());
  962. if ((RemotingAddress != null) && !RemotingAddress.Equals(""))
  963. args["remoting_address"] = OSD.FromString(RemotingAddress);
  964. args["remoting_port"] = OSD.FromString(RemotingPort.ToString());
  965. args["allow_alt_ports"] = OSD.FromBoolean(m_allow_alternate_ports);
  966. if ((proxyUrl != null) && !proxyUrl.Equals(""))
  967. args["proxy_url"] = OSD.FromString(proxyUrl);
  968. if (RegionType != String.Empty)
  969. args["region_type"] = OSD.FromString(RegionType);
  970. return args;
  971. }
  972. public void UnpackRegionInfoData(OSDMap args)
  973. {
  974. if (args["region_id"] != null)
  975. RegionID = args["region_id"].AsUUID();
  976. if (args["region_name"] != null)
  977. RegionName = args["region_name"].AsString();
  978. if (args["external_host_name"] != null)
  979. ExternalHostName = args["external_host_name"].AsString();
  980. if (args["http_port"] != null)
  981. UInt32.TryParse(args["http_port"].AsString(), out m_httpPort);
  982. if (args["server_uri"] != null)
  983. ServerURI = args["server_uri"].AsString();
  984. if (args["region_xloc"] != null)
  985. {
  986. uint locx;
  987. UInt32.TryParse(args["region_xloc"].AsString(), out locx);
  988. RegionLocX = locx;
  989. }
  990. if (args["region_yloc"] != null)
  991. {
  992. uint locy;
  993. UInt32.TryParse(args["region_yloc"].AsString(), out locy);
  994. RegionLocY = locy;
  995. }
  996. if (args.ContainsKey("region_size_x"))
  997. RegionSizeX = (uint)args["region_size_x"].AsInteger();
  998. if (args.ContainsKey("region_size_y"))
  999. RegionSizeY = (uint)args["region_size_y"].AsInteger();
  1000. if (args.ContainsKey("region_size_z"))
  1001. RegionSizeZ = (uint)args["region_size_z"].AsInteger();
  1002. IPAddress ip_addr = null;
  1003. if (args["internal_ep_address"] != null)
  1004. {
  1005. IPAddress.TryParse(args["internal_ep_address"].AsString(), out ip_addr);
  1006. }
  1007. int port = 0;
  1008. if (args["internal_ep_port"] != null)
  1009. {
  1010. Int32.TryParse(args["internal_ep_port"].AsString(), out port);
  1011. }
  1012. InternalEndPoint = new IPEndPoint(ip_addr, port);
  1013. if (args["remoting_address"] != null)
  1014. RemotingAddress = args["remoting_address"].AsString();
  1015. if (args["remoting_port"] != null)
  1016. UInt32.TryParse(args["remoting_port"].AsString(), out m_remotingPort);
  1017. if (args["allow_alt_ports"] != null)
  1018. m_allow_alternate_ports = args["allow_alt_ports"].AsBoolean();
  1019. if (args["proxy_url"] != null)
  1020. proxyUrl = args["proxy_url"].AsString();
  1021. if (args["region_type"] != null)
  1022. m_regionType = args["region_type"].AsString();
  1023. }
  1024. public static RegionInfo Create(UUID regionID, string regionName, uint regX, uint regY, string externalHostName, uint httpPort, uint simPort, uint remotingPort, string serverURI)
  1025. {
  1026. RegionInfo regionInfo;
  1027. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(externalHostName), (int)simPort);
  1028. regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, externalHostName);
  1029. regionInfo.RemotingPort = remotingPort;
  1030. regionInfo.RemotingAddress = externalHostName;
  1031. regionInfo.HttpPort = httpPort;
  1032. regionInfo.RegionID = regionID;
  1033. regionInfo.RegionName = regionName;
  1034. regionInfo.ServerURI = serverURI;
  1035. return regionInfo;
  1036. }
  1037. }
  1038. }