RegionInfo.cs 53 KB

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