RegionInfo.cs 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  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. public bool commFailTF = false;
  98. public ConfigurationMember configMember;
  99. public string RegionFile = String.Empty;
  100. public bool isSandbox = false;
  101. public bool Persistent = true;
  102. private EstateSettings m_estateSettings;
  103. private RegionSettings m_regionSettings;
  104. // private IConfigSource m_configSource = null;
  105. public UUID originRegionID = UUID.Zero;
  106. public string proxyUrl = "";
  107. public int ProxyOffset = 0;
  108. public string regionSecret = UUID.Random().ToString();
  109. public string osSecret;
  110. public UUID lastMapUUID = UUID.Zero;
  111. public string lastMapRefresh = "0";
  112. private int m_nonphysPrimMax = 0;
  113. private int m_physPrimMax = 0;
  114. private bool m_clampPrimSize = false;
  115. private int m_objectCapacity = 0;
  116. private int m_agentCapacity = 0;
  117. private string m_regionType = String.Empty;
  118. private RegionLightShareData m_windlight = new RegionLightShareData();
  119. protected uint m_httpPort;
  120. protected string m_serverURI;
  121. protected string m_regionName = String.Empty;
  122. protected bool Allow_Alternate_Ports;
  123. public bool m_allow_alternate_ports;
  124. protected string m_externalHostName;
  125. protected IPEndPoint m_internalEndPoint;
  126. protected uint? m_regionLocX;
  127. protected uint? m_regionLocY;
  128. protected uint m_remotingPort;
  129. public UUID RegionID = UUID.Zero;
  130. public string RemotingAddress;
  131. public UUID ScopeID = UUID.Zero;
  132. //DSG SYNC
  133. //IP:port for the symmetric sync listener this actor is configured to connect to
  134. private string m_syncServerAddr = String.Empty;
  135. private int m_syncServerPort;
  136. //IP:port for the avatar sync server this actor is configured to connect to
  137. private string m_avatarSyncServerAddr = String.Empty;
  138. private int m_avatarSyncServerPort;
  139. //IP:port for the physics sync server this actor is configured to connect to
  140. private string m_physicsSyncServerAddr = String.Empty;
  141. private int m_physicsSyncServerPort;
  142. private uint m_quarkLocX;
  143. private uint m_quarkLocY;
  144. //end of DSG SYNC
  145. // Apparently, we're applying the same estatesettings regardless of whether it's local or remote.
  146. // MT: Yes. Estates can't span trust boundaries. Therefore, it can be
  147. // assumed that all instances belonging to one estate are able to
  148. // access the same database server. Since estate settings are lodaed
  149. // from there, that should be sufficient for full remote administration
  150. // File based loading
  151. //
  152. public RegionInfo(string description, string filename, bool skipConsoleConfig, IConfigSource configSource) : this(description, filename, skipConsoleConfig, configSource, String.Empty)
  153. {
  154. }
  155. public RegionInfo(string description, string filename, bool skipConsoleConfig, IConfigSource configSource, string configName)
  156. {
  157. // m_configSource = configSource;
  158. if (filename.ToLower().EndsWith(".ini"))
  159. {
  160. if (!File.Exists(filename)) // New region config request
  161. {
  162. IniConfigSource newFile = new IniConfigSource();
  163. ReadNiniConfig(newFile, configName);
  164. newFile.Save(filename);
  165. RegionFile = filename;
  166. return;
  167. }
  168. IniConfigSource source = new IniConfigSource(filename);
  169. bool saveFile = false;
  170. if (source.Configs[configName] == null)
  171. saveFile = true;
  172. ReadNiniConfig(source, configName);
  173. if (configName != String.Empty && saveFile)
  174. source.Save(filename);
  175. RegionFile = filename;
  176. return;
  177. }
  178. try
  179. {
  180. // This will throw if it's not legal Nini XML format
  181. // and thereby toss it to the legacy loader
  182. //
  183. IConfigSource xmlsource = new XmlConfigSource(filename);
  184. ReadNiniConfig(xmlsource, configName);
  185. RegionFile = filename;
  186. return;
  187. }
  188. catch (Exception)
  189. {
  190. }
  191. configMember =
  192. new ConfigurationMember(filename, description, loadConfigurationOptions, handleIncomingConfiguration, !skipConsoleConfig);
  193. configMember.performConfigurationRetrieve();
  194. RegionFile = filename;
  195. }
  196. // The web loader uses this
  197. //
  198. public RegionInfo(string description, XmlNode xmlNode, bool skipConsoleConfig, IConfigSource configSource)
  199. {
  200. // m_configSource = configSource;
  201. configMember =
  202. new ConfigurationMember(xmlNode, description, loadConfigurationOptions, handleIncomingConfiguration, !skipConsoleConfig);
  203. configMember.performConfigurationRetrieve();
  204. m_serverURI = string.Empty;
  205. }
  206. public RegionInfo(uint regionLocX, uint regionLocY, IPEndPoint internalEndPoint, string externalUri)
  207. {
  208. m_regionLocX = regionLocX;
  209. m_regionLocY = regionLocY;
  210. m_internalEndPoint = internalEndPoint;
  211. m_externalHostName = externalUri;
  212. m_serverURI = string.Empty;
  213. }
  214. public RegionInfo()
  215. {
  216. m_serverURI = string.Empty;
  217. }
  218. public EstateSettings EstateSettings
  219. {
  220. get
  221. {
  222. if (m_estateSettings == null)
  223. {
  224. m_estateSettings = new EstateSettings();
  225. }
  226. return m_estateSettings;
  227. }
  228. set { m_estateSettings = value; }
  229. }
  230. public RegionSettings RegionSettings
  231. {
  232. get
  233. {
  234. if (m_regionSettings == null)
  235. {
  236. m_regionSettings = new RegionSettings();
  237. }
  238. return m_regionSettings;
  239. }
  240. set { m_regionSettings = value; }
  241. }
  242. public RegionLightShareData WindlightSettings
  243. {
  244. get
  245. {
  246. if (m_windlight == null)
  247. {
  248. m_windlight = new RegionLightShareData();
  249. }
  250. return m_windlight;
  251. }
  252. set { m_windlight = value; }
  253. }
  254. public int NonphysPrimMax
  255. {
  256. get { return m_nonphysPrimMax; }
  257. }
  258. public int PhysPrimMax
  259. {
  260. get { return m_physPrimMax; }
  261. }
  262. public bool ClampPrimSize
  263. {
  264. get { return m_clampPrimSize; }
  265. }
  266. public int ObjectCapacity
  267. {
  268. get { return m_objectCapacity; }
  269. }
  270. public int AgentCapacity
  271. {
  272. get { return m_agentCapacity; }
  273. }
  274. public byte AccessLevel
  275. {
  276. get { return (byte)Util.ConvertMaturityToAccessLevel((uint)RegionSettings.Maturity); }
  277. }
  278. public string RegionType
  279. {
  280. get { return m_regionType; }
  281. }
  282. /// <summary>
  283. /// The port by which http communication occurs with the region (most noticeably, CAPS communication)
  284. /// </summary>
  285. public uint HttpPort
  286. {
  287. get { return m_httpPort; }
  288. set { m_httpPort = value; }
  289. }
  290. /// <summary>
  291. /// A well-formed URI for the host region server (namely "http://" + ExternalHostName)
  292. /// </summary>
  293. public string ServerURI
  294. {
  295. get {
  296. if ( m_serverURI != string.Empty ) {
  297. return m_serverURI;
  298. } else {
  299. return "http://" + m_externalHostName + ":" + m_httpPort + "/";
  300. }
  301. }
  302. set {
  303. if ( value.EndsWith("/") ) {
  304. m_serverURI = value;
  305. } else {
  306. m_serverURI = value + '/';
  307. }
  308. }
  309. }
  310. public string RegionName
  311. {
  312. get { return m_regionName; }
  313. set { m_regionName = value; }
  314. }
  315. public uint RemotingPort
  316. {
  317. get { return m_remotingPort; }
  318. set { m_remotingPort = value; }
  319. }
  320. /// <value>
  321. /// This accessor can throw all the exceptions that Dns.GetHostAddresses can throw.
  322. ///
  323. /// XXX Isn't this really doing too much to be a simple getter, rather than an explict method?
  324. /// </value>
  325. public IPEndPoint ExternalEndPoint
  326. {
  327. get
  328. {
  329. // Old one defaults to IPv6
  330. //return new IPEndPoint(Dns.GetHostAddresses(m_externalHostName)[0], m_internalEndPoint.Port);
  331. IPAddress ia = null;
  332. // If it is already an IP, don't resolve it - just return directly
  333. if (IPAddress.TryParse(m_externalHostName, out ia))
  334. return new IPEndPoint(ia, m_internalEndPoint.Port);
  335. // Reset for next check
  336. ia = null;
  337. try
  338. {
  339. foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
  340. {
  341. if (ia == null)
  342. ia = Adr;
  343. if (Adr.AddressFamily == AddressFamily.InterNetwork)
  344. {
  345. ia = Adr;
  346. break;
  347. }
  348. }
  349. }
  350. catch (SocketException e)
  351. {
  352. throw new Exception(
  353. "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
  354. e + "' attached to this exception", e);
  355. }
  356. return new IPEndPoint(ia, m_internalEndPoint.Port);
  357. }
  358. set { m_externalHostName = value.ToString(); }
  359. }
  360. public string ExternalHostName
  361. {
  362. get { return m_externalHostName; }
  363. set { m_externalHostName = value; }
  364. }
  365. public IPEndPoint InternalEndPoint
  366. {
  367. get { return m_internalEndPoint; }
  368. set { m_internalEndPoint = value; }
  369. }
  370. public uint RegionLocX
  371. {
  372. get { return m_regionLocX.Value; }
  373. set { m_regionLocX = value; }
  374. }
  375. public uint RegionLocY
  376. {
  377. get { return m_regionLocY.Value; }
  378. set { m_regionLocY = value; }
  379. }
  380. public ulong RegionHandle
  381. {
  382. get { return Util.UIntsToLong((RegionLocX * (uint) Constants.RegionSize), (RegionLocY * (uint) Constants.RegionSize)); }
  383. }
  384. //DSG SYNC
  385. public string SyncServerAddress
  386. {
  387. get { return m_syncServerAddr; }
  388. }
  389. public int SyncServerPort
  390. {
  391. get { return m_syncServerPort; }
  392. }
  393. public string AvatarSyncServerAddress
  394. {
  395. get { return m_avatarSyncServerAddr; }
  396. }
  397. public int AvatarSyncServerPort
  398. {
  399. get { return m_avatarSyncServerPort; }
  400. }
  401. public string PhysicsSyncServerAddress
  402. {
  403. get { return m_physicsSyncServerAddr; }
  404. }
  405. public int PhysicsSyncServerPort
  406. {
  407. get { return m_physicsSyncServerPort; }
  408. }
  409. public uint SyncQuarkLocationX
  410. {
  411. get { return m_quarkLocX; }
  412. set { m_quarkLocX = value; }
  413. }
  414. public uint SyncQuarkLocationY
  415. {
  416. get { return m_quarkLocY; }
  417. set { m_quarkLocY = value; }
  418. }
  419. //end of DSG SYNC
  420. public void SetEndPoint(string ipaddr, int port)
  421. {
  422. IPAddress tmpIP = IPAddress.Parse(ipaddr);
  423. IPEndPoint tmpEPE = new IPEndPoint(tmpIP, port);
  424. m_internalEndPoint = tmpEPE;
  425. }
  426. private void ReadNiniConfig(IConfigSource source, string name)
  427. {
  428. // bool creatingNew = false;
  429. if (source.Configs.Count == 0)
  430. {
  431. MainConsole.Instance.Output("=====================================\n");
  432. MainConsole.Instance.Output("We are now going to ask a couple of questions about your region.\n");
  433. MainConsole.Instance.Output("You can press 'enter' without typing anything to use the default\n");
  434. MainConsole.Instance.Output("the default is displayed between [ ] brackets.\n");
  435. MainConsole.Instance.Output("=====================================\n");
  436. if (name == String.Empty)
  437. name = MainConsole.Instance.CmdPrompt("New region name", name);
  438. if (name == String.Empty)
  439. throw new Exception("Cannot interactively create region with no name");
  440. source.AddConfig(name);
  441. // creatingNew = true;
  442. }
  443. if (name == String.Empty)
  444. name = source.Configs[0].Name;
  445. if (source.Configs[name] == null)
  446. {
  447. source.AddConfig(name);
  448. // creatingNew = true;
  449. }
  450. IConfig config = source.Configs[name];
  451. // UUID
  452. //
  453. string regionUUID = config.GetString("RegionUUID", string.Empty);
  454. if (regionUUID == String.Empty)
  455. {
  456. UUID newID = UUID.Random();
  457. regionUUID = MainConsole.Instance.CmdPrompt("Region UUID", newID.ToString());
  458. config.Set("RegionUUID", regionUUID);
  459. }
  460. RegionID = new UUID(regionUUID);
  461. originRegionID = RegionID; // What IS this?!
  462. RegionName = name;
  463. string location = config.GetString("Location", String.Empty);
  464. if (location == String.Empty)
  465. {
  466. location = MainConsole.Instance.CmdPrompt("Region Location", "1000,1000");
  467. config.Set("Location", location);
  468. }
  469. string[] locationElements = location.Split(new char[] {','});
  470. m_regionLocX = Convert.ToUInt32(locationElements[0]);
  471. m_regionLocY = Convert.ToUInt32(locationElements[1]);
  472. // Internal IP
  473. IPAddress address;
  474. if (config.Contains("InternalAddress"))
  475. {
  476. address = IPAddress.Parse(config.GetString("InternalAddress", String.Empty));
  477. }
  478. else
  479. {
  480. address = IPAddress.Parse(MainConsole.Instance.CmdPrompt("Internal IP address", "0.0.0.0"));
  481. config.Set("InternalAddress", address.ToString());
  482. }
  483. int port;
  484. if (config.Contains("InternalPort"))
  485. {
  486. port = config.GetInt("InternalPort", 9000);
  487. }
  488. else
  489. {
  490. port = Convert.ToInt32(MainConsole.Instance.CmdPrompt("Internal port", "9000"));
  491. config.Set("InternalPort", port);
  492. }
  493. m_internalEndPoint = new IPEndPoint(address, port);
  494. if (config.Contains("AllowAlternatePorts"))
  495. {
  496. m_allow_alternate_ports = config.GetBoolean("AllowAlternatePorts", true);
  497. }
  498. else
  499. {
  500. m_allow_alternate_ports = Convert.ToBoolean(MainConsole.Instance.CmdPrompt("Allow alternate ports", "False"));
  501. config.Set("AllowAlternatePorts", m_allow_alternate_ports.ToString());
  502. }
  503. // External IP
  504. //
  505. string externalName;
  506. if (config.Contains("ExternalHostName"))
  507. {
  508. externalName = config.GetString("ExternalHostName", "SYSTEMIP");
  509. }
  510. else
  511. {
  512. externalName = MainConsole.Instance.CmdPrompt("External host name", "SYSTEMIP");
  513. config.Set("ExternalHostName", externalName);
  514. }
  515. if (externalName == "SYSTEMIP")
  516. {
  517. m_externalHostName = Util.GetLocalHost().ToString();
  518. m_log.InfoFormat(
  519. "[REGIONINFO]: Resolving SYSTEMIP to {0} for external hostname of region {1}",
  520. m_externalHostName, name);
  521. }
  522. else
  523. {
  524. m_externalHostName = externalName;
  525. }
  526. m_regionType = config.GetString("RegionType", String.Empty);
  527. // Prim stuff
  528. //
  529. m_nonphysPrimMax = config.GetInt("NonphysicalPrimMax", 256);
  530. m_physPrimMax = config.GetInt("PhysicalPrimMax", 10);
  531. m_clampPrimSize = config.GetBoolean("ClampPrimSize", false);
  532. m_objectCapacity = config.GetInt("MaxPrims", 15000);
  533. m_agentCapacity = config.GetInt("MaxAgents", 100);
  534. // Multi-tenancy
  535. //
  536. ScopeID = new UUID(config.GetString("ScopeID", UUID.Zero.ToString()));
  537. // DSG SYNC
  538. m_syncServerAddr = config.GetString("SyncServerAddress", String.Empty);
  539. m_syncServerPort = config.GetInt("SyncServerPort", -1);
  540. //if either IP or port is not configured, we set IP to empty to raise warning later
  541. if (m_syncServerPort == -1)
  542. m_syncServerAddr = String.Empty;
  543. m_avatarSyncServerAddr = config.GetString("AvatarSyncServerAddress", String.Empty);
  544. m_avatarSyncServerPort = config.GetInt("AvatarSyncServerPort", -1);
  545. if (m_avatarSyncServerPort == -1)
  546. m_avatarSyncServerAddr = String.Empty;
  547. m_physicsSyncServerAddr = config.GetString("PhysicsSyncServerAddress", String.Empty);
  548. m_physicsSyncServerPort = config.GetInt("PhysicsSyncServerPort", -1);
  549. if (m_physicsSyncServerPort == -1)
  550. m_physicsSyncServerAddr = String.Empty;
  551. string quarkLocation = config.GetString("SyncQuarkLocation", "1000,1000");
  552. string[] quarkLocElements = quarkLocation.Split(new char[] { ',' });
  553. m_quarkLocX = Convert.ToUInt32(quarkLocElements[0]);
  554. m_quarkLocY = Convert.ToUInt32(quarkLocElements[1]);
  555. // end of DSG SYNC
  556. }
  557. private void WriteNiniConfig(IConfigSource source)
  558. {
  559. IConfig config = source.Configs[RegionName];
  560. if (config != null)
  561. source.Configs.Remove(config);
  562. config = source.AddConfig(RegionName);
  563. config.Set("RegionUUID", RegionID.ToString());
  564. string location = String.Format("{0},{1}", m_regionLocX, m_regionLocY);
  565. config.Set("Location", location);
  566. config.Set("InternalAddress", m_internalEndPoint.Address.ToString());
  567. config.Set("InternalPort", m_internalEndPoint.Port);
  568. config.Set("AllowAlternatePorts", m_allow_alternate_ports.ToString());
  569. config.Set("ExternalHostName", m_externalHostName);
  570. if (m_nonphysPrimMax != 0)
  571. config.Set("NonphysicalPrimMax", m_nonphysPrimMax);
  572. if (m_physPrimMax != 0)
  573. config.Set("PhysicalPrimMax", m_physPrimMax);
  574. config.Set("ClampPrimSize", m_clampPrimSize.ToString());
  575. if (m_objectCapacity != 0)
  576. config.Set("MaxPrims", m_objectCapacity);
  577. if (m_agentCapacity != 0)
  578. config.Set("MaxAgents", m_agentCapacity);
  579. if (ScopeID != UUID.Zero)
  580. config.Set("ScopeID", ScopeID.ToString());
  581. if (RegionType != String.Empty)
  582. config.Set("RegionType", RegionType);
  583. }
  584. public bool ignoreIncomingConfiguration(string configuration_key, object configuration_result)
  585. {
  586. return true;
  587. }
  588. public void SaveRegionToFile(string description, string filename)
  589. {
  590. if (filename.ToLower().EndsWith(".ini"))
  591. {
  592. IniConfigSource source = new IniConfigSource();
  593. try
  594. {
  595. source = new IniConfigSource(filename); // Load if it exists
  596. }
  597. catch (Exception)
  598. {
  599. }
  600. WriteNiniConfig(source);
  601. source.Save(filename);
  602. return;
  603. }
  604. else if (filename.ToLower().EndsWith(".xml"))
  605. {
  606. configMember = new ConfigurationMember(filename, description, loadConfigurationOptionsFromMe,
  607. ignoreIncomingConfiguration, false);
  608. configMember.performConfigurationRetrieve();
  609. RegionFile = filename;
  610. }
  611. else
  612. throw new Exception("Invalid file type for region persistence.");
  613. }
  614. public void loadConfigurationOptionsFromMe()
  615. {
  616. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID_NULL_FREE,
  617. "UUID of Region (Default is recommended, random UUID)",
  618. RegionID.ToString(), true);
  619. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  620. "Region Name", RegionName, true);
  621. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  622. "Grid Location (X Axis)", m_regionLocX.ToString(), true);
  623. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  624. "Grid Location (Y Axis)", m_regionLocY.ToString(), true);
  625. //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  626. configMember.addConfigurationOption("internal_ip_address",
  627. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  628. "Internal IP Address for incoming UDP client connections",
  629. m_internalEndPoint.Address.ToString(),
  630. true);
  631. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  632. "Internal IP Port for incoming UDP client connections",
  633. m_internalEndPoint.Port.ToString(), true);
  634. configMember.addConfigurationOption("allow_alternate_ports",
  635. ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  636. "Allow sim to find alternate UDP ports when ports are in use?",
  637. m_allow_alternate_ports.ToString(), true);
  638. configMember.addConfigurationOption("external_host_name",
  639. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  640. "External Host Name", m_externalHostName, true);
  641. configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  642. "Last Map UUID", lastMapUUID.ToString(), true);
  643. configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  644. "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
  645. configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  646. "Maximum size for nonphysical prims", m_nonphysPrimMax.ToString(), true);
  647. configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  648. "Maximum size for physical prims", m_physPrimMax.ToString(), true);
  649. configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  650. "Clamp prims to max size", m_clampPrimSize.ToString(), true);
  651. configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  652. "Max objects this sim will hold", m_objectCapacity.ToString(), true);
  653. configMember.addConfigurationOption("agent_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  654. "Max avatars this sim will hold", m_agentCapacity.ToString(), true);
  655. configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  656. "Scope ID for this region", ScopeID.ToString(), true);
  657. configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  658. "Free form string describing the type of region", String.Empty, true);
  659. }
  660. public void loadConfigurationOptions()
  661. {
  662. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  663. "UUID of Region (Default is recommended, random UUID)",
  664. UUID.Random().ToString(), true);
  665. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  666. "Region Name", "OpenSim Test", false);
  667. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  668. "Grid Location (X Axis)", "1000", false);
  669. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  670. "Grid Location (Y Axis)", "1000", false);
  671. //m_configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  672. configMember.addConfigurationOption("internal_ip_address",
  673. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  674. "Internal IP Address for incoming UDP client connections", "0.0.0.0",
  675. false);
  676. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  677. "Internal IP Port for incoming UDP client connections",
  678. ConfigSettings.DefaultRegionHttpPort.ToString(), false);
  679. configMember.addConfigurationOption("allow_alternate_ports", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  680. "Allow sim to find alternate UDP ports when ports are in use?",
  681. "false", true);
  682. configMember.addConfigurationOption("external_host_name",
  683. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  684. "External Host Name", "127.0.0.1", false);
  685. configMember.addConfigurationOption("lastmap_uuid", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  686. "Last Map UUID", lastMapUUID.ToString(), true);
  687. configMember.addConfigurationOption("lastmap_refresh", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  688. "Last Map Refresh", Util.UnixTimeSinceEpoch().ToString(), true);
  689. configMember.addConfigurationOption("nonphysical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  690. "Maximum size for nonphysical prims", "0", true);
  691. configMember.addConfigurationOption("physical_prim_max", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  692. "Maximum size for physical prims", "0", true);
  693. configMember.addConfigurationOption("clamp_prim_size", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  694. "Clamp prims to max size", "false", true);
  695. configMember.addConfigurationOption("object_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  696. "Max objects this sim will hold", "15000", true);
  697. configMember.addConfigurationOption("agent_capacity", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  698. "Max avatars this sim will hold", "100", true);
  699. configMember.addConfigurationOption("scope_id", ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  700. "Scope ID for this region", UUID.Zero.ToString(), true);
  701. configMember.addConfigurationOption("region_type", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  702. "Region Type", String.Empty, true);
  703. }
  704. public bool handleIncomingConfiguration(string configuration_key, object configuration_result)
  705. {
  706. switch (configuration_key)
  707. {
  708. case "sim_UUID":
  709. RegionID = (UUID) configuration_result;
  710. originRegionID = (UUID) configuration_result;
  711. break;
  712. case "sim_name":
  713. RegionName = (string) configuration_result;
  714. break;
  715. case "sim_location_x":
  716. m_regionLocX = (uint) configuration_result;
  717. break;
  718. case "sim_location_y":
  719. m_regionLocY = (uint) configuration_result;
  720. break;
  721. case "internal_ip_address":
  722. IPAddress address = (IPAddress) configuration_result;
  723. m_internalEndPoint = new IPEndPoint(address, 0);
  724. break;
  725. case "internal_ip_port":
  726. m_internalEndPoint.Port = (int) configuration_result;
  727. break;
  728. case "allow_alternate_ports":
  729. m_allow_alternate_ports = (bool) configuration_result;
  730. break;
  731. case "external_host_name":
  732. if ((string) configuration_result != "SYSTEMIP")
  733. {
  734. m_externalHostName = (string) configuration_result;
  735. }
  736. else
  737. {
  738. m_externalHostName = Util.GetLocalHost().ToString();
  739. }
  740. break;
  741. case "lastmap_uuid":
  742. lastMapUUID = (UUID)configuration_result;
  743. break;
  744. case "lastmap_refresh":
  745. lastMapRefresh = (string)configuration_result;
  746. break;
  747. case "nonphysical_prim_max":
  748. m_nonphysPrimMax = (int)configuration_result;
  749. break;
  750. case "physical_prim_max":
  751. m_physPrimMax = (int)configuration_result;
  752. break;
  753. case "clamp_prim_size":
  754. m_clampPrimSize = (bool)configuration_result;
  755. break;
  756. case "object_capacity":
  757. m_objectCapacity = (int)configuration_result;
  758. break;
  759. case "agent_capacity":
  760. m_agentCapacity = (int)configuration_result;
  761. break;
  762. case "scope_id":
  763. ScopeID = (UUID)configuration_result;
  764. break;
  765. case "region_type":
  766. m_regionType = (string)configuration_result;
  767. break;
  768. }
  769. return true;
  770. }
  771. public void SaveLastMapUUID(UUID mapUUID)
  772. {
  773. lastMapUUID = mapUUID;
  774. lastMapRefresh = Util.UnixTimeSinceEpoch().ToString();
  775. if (configMember == null)
  776. return;
  777. configMember.forceSetConfigurationOption("lastmap_uuid", mapUUID.ToString());
  778. configMember.forceSetConfigurationOption("lastmap_refresh", lastMapRefresh);
  779. }
  780. public OSDMap PackRegionInfoData()
  781. {
  782. OSDMap args = new OSDMap();
  783. args["region_id"] = OSD.FromUUID(RegionID);
  784. if ((RegionName != null) && !RegionName.Equals(""))
  785. args["region_name"] = OSD.FromString(RegionName);
  786. args["external_host_name"] = OSD.FromString(ExternalHostName);
  787. args["http_port"] = OSD.FromString(HttpPort.ToString());
  788. args["server_uri"] = OSD.FromString(ServerURI);
  789. args["region_xloc"] = OSD.FromString(RegionLocX.ToString());
  790. args["region_yloc"] = OSD.FromString(RegionLocY.ToString());
  791. args["internal_ep_address"] = OSD.FromString(InternalEndPoint.Address.ToString());
  792. args["internal_ep_port"] = OSD.FromString(InternalEndPoint.Port.ToString());
  793. if ((RemotingAddress != null) && !RemotingAddress.Equals(""))
  794. args["remoting_address"] = OSD.FromString(RemotingAddress);
  795. args["remoting_port"] = OSD.FromString(RemotingPort.ToString());
  796. args["allow_alt_ports"] = OSD.FromBoolean(m_allow_alternate_ports);
  797. if ((proxyUrl != null) && !proxyUrl.Equals(""))
  798. args["proxy_url"] = OSD.FromString(proxyUrl);
  799. if (RegionType != String.Empty)
  800. args["region_type"] = OSD.FromString(RegionType);
  801. return args;
  802. }
  803. public void UnpackRegionInfoData(OSDMap args)
  804. {
  805. if (args["region_id"] != null)
  806. RegionID = args["region_id"].AsUUID();
  807. if (args["region_name"] != null)
  808. RegionName = args["region_name"].AsString();
  809. if (args["external_host_name"] != null)
  810. ExternalHostName = args["external_host_name"].AsString();
  811. if (args["http_port"] != null)
  812. UInt32.TryParse(args["http_port"].AsString(), out m_httpPort);
  813. if (args["server_uri"] != null)
  814. ServerURI = args["server_uri"].AsString();
  815. if (args["region_xloc"] != null)
  816. {
  817. uint locx;
  818. UInt32.TryParse(args["region_xloc"].AsString(), out locx);
  819. RegionLocX = locx;
  820. }
  821. if (args["region_yloc"] != null)
  822. {
  823. uint locy;
  824. UInt32.TryParse(args["region_yloc"].AsString(), out locy);
  825. RegionLocY = locy;
  826. }
  827. IPAddress ip_addr = null;
  828. if (args["internal_ep_address"] != null)
  829. {
  830. IPAddress.TryParse(args["internal_ep_address"].AsString(), out ip_addr);
  831. }
  832. int port = 0;
  833. if (args["internal_ep_port"] != null)
  834. {
  835. Int32.TryParse(args["internal_ep_port"].AsString(), out port);
  836. }
  837. InternalEndPoint = new IPEndPoint(ip_addr, port);
  838. if (args["remoting_address"] != null)
  839. RemotingAddress = args["remoting_address"].AsString();
  840. if (args["remoting_port"] != null)
  841. UInt32.TryParse(args["remoting_port"].AsString(), out m_remotingPort);
  842. if (args["allow_alt_ports"] != null)
  843. m_allow_alternate_ports = args["allow_alt_ports"].AsBoolean();
  844. if (args["proxy_url"] != null)
  845. proxyUrl = args["proxy_url"].AsString();
  846. if (args["region_type"] != null)
  847. m_regionType = args["region_type"].AsString();
  848. }
  849. public static RegionInfo Create(UUID regionID, string regionName, uint regX, uint regY, string externalHostName, uint httpPort, uint simPort, uint remotingPort, string serverURI)
  850. {
  851. RegionInfo regionInfo;
  852. IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(externalHostName), (int)simPort);
  853. regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, externalHostName);
  854. regionInfo.RemotingPort = remotingPort;
  855. regionInfo.RemotingAddress = externalHostName;
  856. regionInfo.HttpPort = httpPort;
  857. regionInfo.RegionID = regionID;
  858. regionInfo.RegionName = regionName;
  859. regionInfo.ServerURI = serverURI;
  860. return regionInfo;
  861. }
  862. public Dictionary<string, object> ToKeyValuePairs()
  863. {
  864. Dictionary<string, object> kvp = new Dictionary<string, object>();
  865. kvp["uuid"] = RegionID.ToString();
  866. kvp["locX"] = RegionLocX.ToString();
  867. kvp["locY"] = RegionLocY.ToString();
  868. kvp["external_ip_address"] = ExternalEndPoint.Address.ToString();
  869. kvp["external_port"] = ExternalEndPoint.Port.ToString();
  870. kvp["external_host_name"] = ExternalHostName;
  871. kvp["http_port"] = HttpPort.ToString();
  872. kvp["internal_ip_address"] = InternalEndPoint.Address.ToString();
  873. kvp["internal_port"] = InternalEndPoint.Port.ToString();
  874. kvp["alternate_ports"] = m_allow_alternate_ports.ToString();
  875. kvp["server_uri"] = ServerURI;
  876. return kvp;
  877. }
  878. }
  879. }