RegionInfo.cs 53 KB

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