RegionInfo.cs 20 KB

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