RegionInfo.cs 53 KB

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