RegionInfo.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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 OpenSim 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.Net;
  29. using System.Net.Sockets;
  30. using System.Xml;
  31. using libsecondlife;
  32. using Nini.Config;
  33. namespace OpenSim.Framework
  34. {
  35. [Serializable]
  36. public class SimpleRegionInfo
  37. {
  38. // private static readonly log4net.ILog m_log
  39. // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  40. protected bool Allow_Alternate_Ports;
  41. public bool m_allow_alternate_ports;
  42. protected string m_externalHostName;
  43. /// <value>
  44. /// The port by which http communication occurs with the region (most noticeably, CAPS communication)
  45. /// </value>
  46. protected uint m_httpPort;
  47. protected IPEndPoint m_internalEndPoint;
  48. protected uint? m_regionLocX;
  49. protected uint? m_regionLocY;
  50. protected uint m_remotingPort;
  51. protected string m_serverURI;
  52. public LLUUID RegionID = LLUUID.Zero;
  53. public string RemotingAddress;
  54. public SimpleRegionInfo()
  55. {
  56. }
  57. public SimpleRegionInfo(uint regionLocX, uint regionLocY, IPEndPoint internalEndPoint, string externalUri)
  58. {
  59. m_regionLocX = regionLocX;
  60. m_regionLocY = regionLocY;
  61. m_internalEndPoint = internalEndPoint;
  62. m_externalHostName = externalUri;
  63. }
  64. public SimpleRegionInfo(uint regionLocX, uint regionLocY, string externalUri, uint port)
  65. {
  66. m_regionLocX = regionLocX;
  67. m_regionLocY = regionLocY;
  68. m_externalHostName = externalUri;
  69. m_internalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int) port);
  70. }
  71. public SimpleRegionInfo(RegionInfo ConvertFrom)
  72. {
  73. m_regionLocX = ConvertFrom.RegionLocX;
  74. m_regionLocY = ConvertFrom.RegionLocY;
  75. m_internalEndPoint = ConvertFrom.InternalEndPoint;
  76. m_externalHostName = ConvertFrom.ExternalHostName;
  77. m_remotingPort = ConvertFrom.RemotingPort;
  78. m_httpPort = ConvertFrom.HttpPort;
  79. m_allow_alternate_ports = ConvertFrom.m_allow_alternate_ports;
  80. RemotingAddress = ConvertFrom.RemotingAddress;
  81. RegionID = LLUUID.Zero;
  82. ServerURI = ConvertFrom.ServerURI;
  83. }
  84. public uint RemotingPort
  85. {
  86. get { return m_remotingPort; }
  87. set { m_remotingPort = value; }
  88. }
  89. public uint HttpPort
  90. {
  91. get { return m_httpPort; }
  92. set { m_httpPort = value; }
  93. }
  94. public string ServerURI
  95. {
  96. get { return m_serverURI; }
  97. set { m_serverURI = value; }
  98. }
  99. /// <value>
  100. /// This accessor can throw all the exceptions that Dns.GetHostAddresses can throw.
  101. ///
  102. /// XXX Isn't this really doing too much to be a simple getter, rather than an explict method?
  103. /// </value>
  104. public IPEndPoint ExternalEndPoint
  105. {
  106. get
  107. {
  108. // Old one defaults to IPv6
  109. //return new IPEndPoint(Dns.GetHostAddresses(m_externalHostName)[0], m_internalEndPoint.Port);
  110. IPAddress ia = null;
  111. // If it is already an IP, don't resolve it - just return directly
  112. if (IPAddress.TryParse(m_externalHostName, out ia))
  113. return new IPEndPoint(ia, m_internalEndPoint.Port);
  114. // Reset for next check
  115. ia = null;
  116. foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
  117. {
  118. if (ia == null)
  119. ia = Adr;
  120. if (Adr.AddressFamily == AddressFamily.InterNetwork)
  121. {
  122. ia = Adr;
  123. break;
  124. }
  125. }
  126. return new IPEndPoint(ia, m_internalEndPoint.Port);
  127. }
  128. set { m_externalHostName = value.ToString(); }
  129. }
  130. public string ExternalHostName
  131. {
  132. get { return m_externalHostName; }
  133. set { m_externalHostName = value; }
  134. }
  135. public IPEndPoint InternalEndPoint
  136. {
  137. get { return m_internalEndPoint; }
  138. set { m_internalEndPoint = value; }
  139. }
  140. public uint RegionLocX
  141. {
  142. get { return m_regionLocX.Value; }
  143. set { m_regionLocX = value; }
  144. }
  145. public uint RegionLocY
  146. {
  147. get { return m_regionLocY.Value; }
  148. set { m_regionLocY = value; }
  149. }
  150. public ulong RegionHandle
  151. {
  152. get { return Util.UIntsToLong((RegionLocX * (uint) Constants.RegionSize), (RegionLocY * (uint) Constants.RegionSize)); }
  153. }
  154. public int getInternalEndPointPort()
  155. {
  156. return m_internalEndPoint.Port;
  157. }
  158. }
  159. public class RegionInfo : SimpleRegionInfo
  160. {
  161. // private static readonly log4net.ILog m_log
  162. // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  163. public bool commFailTF = false;
  164. public ConfigurationMember configMember;
  165. public LLUUID CovenantID = LLUUID.Zero;
  166. public string DataStore = String.Empty;
  167. public bool isSandbox = false;
  168. private EstateSettings m_estateSettings;
  169. // public bool m_allow_alternate_ports;
  170. public LLUUID MasterAvatarAssignedUUID = LLUUID.Zero;
  171. public string MasterAvatarFirstName = String.Empty;
  172. public string MasterAvatarLastName = String.Empty;
  173. public string MasterAvatarSandboxPassword = String.Empty;
  174. public LLUUID originRegionID = LLUUID.Zero;
  175. public string proxyUrl = "";
  176. public string RegionName = String.Empty;
  177. public string regionSecret = LLUUID.Random().ToString();
  178. // Apparently, we're applying the same estatesettings regardless of whether it's local or remote.
  179. public RegionInfo(string description, string filename, bool skipConsoleConfig)
  180. {
  181. configMember =
  182. new ConfigurationMember(filename, description, loadConfigurationOptions, handleIncomingConfiguration, !skipConsoleConfig);
  183. configMember.performConfigurationRetrieve();
  184. }
  185. public RegionInfo(string description, XmlNode xmlNode, bool skipConsoleConfig)
  186. {
  187. configMember =
  188. new ConfigurationMember(xmlNode, description, loadConfigurationOptions, handleIncomingConfiguration, !skipConsoleConfig);
  189. configMember.performConfigurationRetrieve();
  190. }
  191. public RegionInfo(uint regionLocX, uint regionLocY, IPEndPoint internalEndPoint, string externalUri) :
  192. base(regionLocX, regionLocY, internalEndPoint, externalUri)
  193. {
  194. }
  195. public RegionInfo()
  196. {
  197. }
  198. public RegionInfo(SerializableRegionInfo ConvertFrom)
  199. {
  200. m_regionLocX = ConvertFrom.RegionLocX;
  201. m_regionLocY = ConvertFrom.RegionLocY;
  202. m_internalEndPoint = ConvertFrom.InternalEndPoint;
  203. m_externalHostName = ConvertFrom.ExternalHostName;
  204. m_remotingPort = ConvertFrom.RemotingPort;
  205. m_allow_alternate_ports = ConvertFrom.m_allow_alternate_ports;
  206. RemotingAddress = ConvertFrom.RemotingAddress;
  207. RegionID = LLUUID.Zero;
  208. proxyUrl = ConvertFrom.ProxyUrl;
  209. originRegionID = ConvertFrom.OriginRegionID;
  210. RegionName = ConvertFrom.RegionName;
  211. ServerURI = ConvertFrom.ServerURI;
  212. }
  213. public RegionInfo(SimpleRegionInfo ConvertFrom)
  214. {
  215. m_regionLocX = ConvertFrom.RegionLocX;
  216. m_regionLocY = ConvertFrom.RegionLocY;
  217. m_internalEndPoint = ConvertFrom.InternalEndPoint;
  218. m_externalHostName = ConvertFrom.ExternalHostName;
  219. m_remotingPort = ConvertFrom.RemotingPort;
  220. m_allow_alternate_ports = ConvertFrom.m_allow_alternate_ports;
  221. RemotingAddress = ConvertFrom.RemotingAddress;
  222. RegionID = LLUUID.Zero;
  223. ServerURI = ConvertFrom.ServerURI;
  224. }
  225. public EstateSettings EstateSettings
  226. {
  227. get
  228. {
  229. if (m_estateSettings == null)
  230. {
  231. m_estateSettings = new EstateSettings();
  232. }
  233. return m_estateSettings;
  234. }
  235. }
  236. public void SetEndPoint(string ipaddr, int port)
  237. {
  238. IPAddress tmpIP = IPAddress.Parse(ipaddr);
  239. IPEndPoint tmpEPE = new IPEndPoint(tmpIP, port);
  240. m_internalEndPoint = tmpEPE;
  241. }
  242. //not in use, should swap to nini though.
  243. public void LoadFromNiniSource(IConfigSource source)
  244. {
  245. LoadFromNiniSource(source, "RegionInfo");
  246. }
  247. //not in use, should swap to nini though.
  248. public void LoadFromNiniSource(IConfigSource source, string sectionName)
  249. {
  250. string errorMessage = String.Empty;
  251. RegionID = new LLUUID(source.Configs[sectionName].GetString("Region_ID", LLUUID.Random().ToString()));
  252. RegionName = source.Configs[sectionName].GetString("sim_name", "OpenSim Test");
  253. m_regionLocX = Convert.ToUInt32(source.Configs[sectionName].GetString("sim_location_x", "1000"));
  254. m_regionLocY = Convert.ToUInt32(source.Configs[sectionName].GetString("sim_location_y", "1000"));
  255. // this.DataStore = source.Configs[sectionName].GetString("datastore", "OpenSim.db");
  256. string ipAddress = source.Configs[sectionName].GetString("internal_ip_address", "0.0.0.0");
  257. IPAddress ipAddressResult;
  258. if (IPAddress.TryParse(ipAddress, out ipAddressResult))
  259. {
  260. m_internalEndPoint = new IPEndPoint(ipAddressResult, 0);
  261. }
  262. else
  263. {
  264. errorMessage = "needs an IP Address (IPAddress)";
  265. }
  266. m_internalEndPoint.Port =
  267. source.Configs[sectionName].GetInt("internal_ip_port", (int) NetworkServersInfo.DefaultHttpListenerPort);
  268. string externalHost = source.Configs[sectionName].GetString("external_host_name", "127.0.0.1");
  269. if (externalHost != "SYSTEMIP")
  270. {
  271. m_externalHostName = externalHost;
  272. }
  273. else
  274. {
  275. m_externalHostName = Util.GetLocalHost().ToString();
  276. }
  277. MasterAvatarFirstName = source.Configs[sectionName].GetString("master_avatar_first", "Test");
  278. MasterAvatarLastName = source.Configs[sectionName].GetString("master_avatar_last", "User");
  279. MasterAvatarSandboxPassword = source.Configs[sectionName].GetString("master_avatar_pass", "test");
  280. if (errorMessage != String.Empty)
  281. {
  282. // a error
  283. }
  284. }
  285. public bool ignoreIncomingConfiguration(string configuration_key, object configuration_result)
  286. {
  287. return true;
  288. }
  289. public void SaveRegionToFile(string description, string filename)
  290. {
  291. configMember = new ConfigurationMember(filename, description, loadConfigurationOptionsFromMe,
  292. ignoreIncomingConfiguration, false);
  293. configMember.performConfigurationRetrieve();
  294. }
  295. public void loadConfigurationOptionsFromMe()
  296. {
  297. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_LLUUID_NULL_FREE,
  298. "UUID of Region (Default is recommended, random UUID)",
  299. RegionID.ToString(), true);
  300. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  301. "Region Name", RegionName, true);
  302. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  303. "Grid Location (X Axis)", m_regionLocX.ToString(), true);
  304. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  305. "Grid Location (Y Axis)", m_regionLocY.ToString(), true);
  306. //configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  307. configMember.addConfigurationOption("internal_ip_address",
  308. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  309. "Internal IP Address for incoming UDP client connections",
  310. m_internalEndPoint.Address.ToString(),
  311. true);
  312. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  313. "Internal IP Port for incoming UDP client connections",
  314. m_internalEndPoint.Port.ToString(), true);
  315. configMember.addConfigurationOption("allow_alternate_ports",
  316. ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  317. "Allow sim to find alternate UDP ports when ports are in use?",
  318. m_allow_alternate_ports.ToString(), true);
  319. configMember.addConfigurationOption("external_host_name",
  320. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  321. "External Host Name", m_externalHostName, true);
  322. configMember.addConfigurationOption("master_avatar_uuid", ConfigurationOption.ConfigurationTypes.TYPE_LLUUID,
  323. "Master Avatar UUID", MasterAvatarAssignedUUID.ToString(), true);
  324. configMember.addConfigurationOption("estate_covanant_uuid",
  325. ConfigurationOption.ConfigurationTypes.TYPE_LLUUID, "Estate Covenant",
  326. CovenantID.ToString(), true);
  327. configMember.addConfigurationOption("master_avatar_first",
  328. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  329. "First Name of Master Avatar", MasterAvatarFirstName, true);
  330. configMember.addConfigurationOption("master_avatar_last",
  331. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  332. "Last Name of Master Avatar", MasterAvatarLastName, true);
  333. configMember.addConfigurationOption("master_avatar_pass", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  334. "(Sandbox Mode Only)Password for Master Avatar account",
  335. MasterAvatarSandboxPassword, true);
  336. }
  337. public void loadConfigurationOptions()
  338. {
  339. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_LLUUID,
  340. "UUID of Region (Default is recommended, random UUID)",
  341. LLUUID.Random().ToString(), true);
  342. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  343. "Region Name", "OpenSim Test", false);
  344. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  345. "Grid Location (X Axis)", "1000", false);
  346. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  347. "Grid Location (Y Axis)", "1000", false);
  348. //configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  349. configMember.addConfigurationOption("internal_ip_address",
  350. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  351. "Internal IP Address for incoming UDP client connections", "0.0.0.0",
  352. false);
  353. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  354. "Internal IP Port for incoming UDP client connections",
  355. NetworkServersInfo.DefaultHttpListenerPort.ToString(), false);
  356. configMember.addConfigurationOption("allow_alternate_ports", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
  357. "Allow sim to find alternate UDP ports when ports are in use?",
  358. "false", true);
  359. configMember.addConfigurationOption("external_host_name",
  360. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  361. "External Host Name", "127.0.0.1", false);
  362. configMember.addConfigurationOption("master_avatar_uuid", ConfigurationOption.ConfigurationTypes.TYPE_LLUUID,
  363. "Master Avatar UUID", LLUUID.Zero.ToString(), true);
  364. configMember.addConfigurationOption("estate_covanant_uuid",
  365. ConfigurationOption.ConfigurationTypes.TYPE_LLUUID, "Estate Covenant",
  366. LLUUID.Zero.ToString(), true);
  367. configMember.addConfigurationOption("master_avatar_first",
  368. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  369. "First Name of Master Avatar", "Test", false,
  370. (ConfigurationOption.ConfigurationOptionShouldBeAsked)
  371. shouldMasterAvatarDetailsBeAsked);
  372. configMember.addConfigurationOption("master_avatar_last",
  373. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  374. "Last Name of Master Avatar", "User", false,
  375. (ConfigurationOption.ConfigurationOptionShouldBeAsked)
  376. shouldMasterAvatarDetailsBeAsked);
  377. configMember.addConfigurationOption("master_avatar_pass", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  378. "(Sandbox Mode Only)Password for Master Avatar account", "test", false,
  379. (ConfigurationOption.ConfigurationOptionShouldBeAsked)
  380. shouldMasterAvatarDetailsBeAsked);
  381. }
  382. public bool shouldMasterAvatarDetailsBeAsked(string configuration_key)
  383. {
  384. if (MasterAvatarAssignedUUID == LLUUID.Zero)
  385. {
  386. return true;
  387. }
  388. return false;
  389. }
  390. public bool handleIncomingConfiguration(string configuration_key, object configuration_result)
  391. {
  392. switch (configuration_key)
  393. {
  394. case "sim_UUID":
  395. RegionID = (LLUUID) configuration_result;
  396. originRegionID = (LLUUID) configuration_result;
  397. break;
  398. case "sim_name":
  399. RegionName = (string) configuration_result;
  400. break;
  401. case "sim_location_x":
  402. m_regionLocX = (uint) configuration_result;
  403. break;
  404. case "sim_location_y":
  405. m_regionLocY = (uint) configuration_result;
  406. break;
  407. case "datastore":
  408. DataStore = (string) configuration_result;
  409. break;
  410. case "internal_ip_address":
  411. IPAddress address = (IPAddress) configuration_result;
  412. m_internalEndPoint = new IPEndPoint(address, 0);
  413. break;
  414. case "internal_ip_port":
  415. m_internalEndPoint.Port = (int) configuration_result;
  416. break;
  417. case "allow_alternate_ports":
  418. m_allow_alternate_ports = (bool) configuration_result;
  419. break;
  420. case "external_host_name":
  421. if ((string) configuration_result != "SYSTEMIP")
  422. {
  423. m_externalHostName = (string) configuration_result;
  424. }
  425. else
  426. {
  427. m_externalHostName = Util.GetLocalHost().ToString();
  428. }
  429. break;
  430. case "master_avatar_uuid":
  431. MasterAvatarAssignedUUID = (LLUUID) configuration_result;
  432. break;
  433. case "estate_covanant_uuid":
  434. CovenantID = (LLUUID) configuration_result;
  435. break;
  436. case "master_avatar_first":
  437. MasterAvatarFirstName = (string) configuration_result;
  438. break;
  439. case "master_avatar_last":
  440. MasterAvatarLastName = (string) configuration_result;
  441. break;
  442. case "master_avatar_pass":
  443. string tempMD5Passwd = (string) configuration_result;
  444. MasterAvatarSandboxPassword = Util.Md5Hash(Util.Md5Hash(tempMD5Passwd) + ":" + String.Empty);
  445. break;
  446. }
  447. return true;
  448. }
  449. public void SaveEstatecovenantUUID(LLUUID notecard)
  450. {
  451. configMember.forceSetConfigurationOption("estate_covanant_uuid", notecard.ToString());
  452. }
  453. }
  454. }