RegionInfo.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. */
  28. using System;
  29. using System.Net;
  30. using System.Net.Sockets;
  31. using System.Xml;
  32. using libsecondlife;
  33. using Nini.Config;
  34. namespace OpenSim.Framework
  35. {
  36. [Serializable]
  37. public class SimpleRegionInfo
  38. {
  39. public SimpleRegionInfo()
  40. {
  41. }
  42. public SimpleRegionInfo(uint regionLocX, uint regionLocY, IPEndPoint internalEndPoint, string externalUri)
  43. {
  44. m_regionLocX = regionLocX;
  45. m_regionLocY = regionLocY;
  46. m_internalEndPoint = internalEndPoint;
  47. m_externalHostName = externalUri;
  48. }
  49. public SimpleRegionInfo(uint regionLocX, uint regionLocY, string externalUri, uint port)
  50. {
  51. m_regionLocX = regionLocX;
  52. m_regionLocY = regionLocY;
  53. m_externalHostName = externalUri;
  54. m_internalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int) port);
  55. }
  56. public SimpleRegionInfo(RegionInfo ConvertFrom)
  57. {
  58. m_regionLocX = ConvertFrom.RegionLocX;
  59. m_regionLocY = ConvertFrom.RegionLocY;
  60. m_internalEndPoint = ConvertFrom.InternalEndPoint;
  61. m_externalHostName = ConvertFrom.ExternalHostName;
  62. m_remotingPort = ConvertFrom.RemotingPort;
  63. RemotingAddress = ConvertFrom.RemotingAddress;
  64. RegionID = LLUUID.Zero;
  65. }
  66. public LLUUID RegionID = LLUUID.Zero;
  67. public uint m_remotingPort;
  68. public uint RemotingPort
  69. {
  70. get { return m_remotingPort; }
  71. set { m_remotingPort = value; }
  72. }
  73. public string RemotingAddress;
  74. public IPEndPoint ExternalEndPoint
  75. {
  76. get
  77. {
  78. // Old one defaults to IPv6
  79. //return new IPEndPoint( Dns.GetHostAddresses( m_externalHostName )[0], m_internalEndPoint.Port );
  80. IPAddress ia = null;
  81. // If it is already an IP, don't resolve it - just return directly
  82. if (IPAddress.TryParse(m_externalHostName, out ia))
  83. return new IPEndPoint(ia, m_internalEndPoint.Port);
  84. // Reset for next check
  85. ia = null;
  86. // New method favors IPv4
  87. foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
  88. {
  89. if (ia == null)
  90. ia = Adr;
  91. if (Adr.AddressFamily == AddressFamily.InterNetwork)
  92. {
  93. ia = Adr;
  94. break;
  95. }
  96. }
  97. return new IPEndPoint(ia, m_internalEndPoint.Port);
  98. }
  99. set { m_externalHostName = value.ToString(); }
  100. }
  101. protected string m_externalHostName;
  102. public string ExternalHostName
  103. {
  104. get { return m_externalHostName; }
  105. set { m_externalHostName = value; }
  106. }
  107. protected IPEndPoint m_internalEndPoint;
  108. public IPEndPoint InternalEndPoint
  109. {
  110. get { return m_internalEndPoint; }
  111. set { m_internalEndPoint = value; }
  112. }
  113. protected uint? m_regionLocX;
  114. public uint RegionLocX
  115. {
  116. get { return m_regionLocX.Value; }
  117. set { m_regionLocX = value; }
  118. }
  119. protected uint? m_regionLocY;
  120. public uint RegionLocY
  121. {
  122. get { return m_regionLocY.Value; }
  123. set { m_regionLocY = value; }
  124. }
  125. public ulong RegionHandle
  126. {
  127. get { return Util.UIntsToLong((RegionLocX*256), (RegionLocY*256)); }
  128. }
  129. }
  130. public class RegionInfo : SimpleRegionInfo
  131. {
  132. public string RegionName = "";
  133. public string DataStore = "";
  134. public bool isSandbox = false;
  135. public bool commFailTF = false;
  136. public LLUUID MasterAvatarAssignedUUID = LLUUID.Zero;
  137. public LLUUID CovenantID = LLUUID.Zero;
  138. public string MasterAvatarFirstName = "";
  139. public string MasterAvatarLastName = "";
  140. public string MasterAvatarSandboxPassword = "";
  141. public LLUUID SkyboxFront = null;
  142. public LLUUID SkyboxBack = null;
  143. public LLUUID SkyboxLeft = null;
  144. public LLUUID SkyboxRight = null;
  145. public LLUUID SkyboxTop = null;
  146. public LLUUID SkyboxBottom = null;
  147. // Apparently, we're applying the same estatesettings regardless of whether it's local or remote.
  148. private static EstateSettings m_estateSettings;
  149. public EstateSettings EstateSettings
  150. {
  151. get
  152. {
  153. if (m_estateSettings == null)
  154. {
  155. m_estateSettings = new EstateSettings();
  156. }
  157. return m_estateSettings;
  158. }
  159. }
  160. public ConfigurationMember configMember;
  161. public RegionInfo(string description, string filename, bool skipConsoleConfig)
  162. {
  163. configMember =
  164. new ConfigurationMember(filename, description, loadConfigurationOptions, handleIncomingConfiguration,!skipConsoleConfig);
  165. configMember.performConfigurationRetrieve();
  166. }
  167. public RegionInfo(string description, XmlNode xmlNode, bool skipConsoleConfig)
  168. {
  169. configMember =
  170. new ConfigurationMember(xmlNode, description, loadConfigurationOptions, handleIncomingConfiguration, !skipConsoleConfig);
  171. configMember.performConfigurationRetrieve();
  172. }
  173. public RegionInfo(uint regionLocX, uint regionLocY, IPEndPoint internalEndPoint, string externalUri) :
  174. base(regionLocX, regionLocY, internalEndPoint, externalUri)
  175. {
  176. }
  177. public RegionInfo()
  178. {
  179. }
  180. public RegionInfo(SearializableRegionInfo ConvertFrom)
  181. {
  182. m_regionLocX = ConvertFrom.RegionLocX;
  183. m_regionLocY = ConvertFrom.RegionLocY;
  184. m_internalEndPoint = ConvertFrom.InternalEndPoint;
  185. m_externalHostName = ConvertFrom.ExternalHostName;
  186. m_remotingPort = ConvertFrom.RemotingPort;
  187. RemotingAddress = ConvertFrom.RemotingAddress;
  188. RegionID = LLUUID.Zero;
  189. }
  190. public RegionInfo(SimpleRegionInfo ConvertFrom)
  191. {
  192. m_regionLocX = ConvertFrom.RegionLocX;
  193. m_regionLocY = ConvertFrom.RegionLocY;
  194. m_internalEndPoint = ConvertFrom.InternalEndPoint;
  195. m_externalHostName = ConvertFrom.ExternalHostName;
  196. m_remotingPort = ConvertFrom.RemotingPort;
  197. RemotingAddress = ConvertFrom.RemotingAddress;
  198. RegionID = LLUUID.Zero;
  199. }
  200. //not in use, should swap to nini though.
  201. public void LoadFromNiniSource(IConfigSource source)
  202. {
  203. LoadFromNiniSource(source, "RegionInfo");
  204. }
  205. //not in use, should swap to nini though.
  206. public void LoadFromNiniSource(IConfigSource source, string sectionName)
  207. {
  208. string errorMessage = "";
  209. RegionID = new LLUUID(source.Configs[sectionName].GetString("Region_ID", LLUUID.Random().ToString()));
  210. RegionName = source.Configs[sectionName].GetString("sim_name", "OpenSim Test");
  211. m_regionLocX = Convert.ToUInt32(source.Configs[sectionName].GetString("sim_location_x", "1000"));
  212. m_regionLocY = Convert.ToUInt32(source.Configs[sectionName].GetString("sim_location_y", "1000"));
  213. // this.DataStore = source.Configs[sectionName].GetString("datastore", "OpenSim.db");
  214. string ipAddress = source.Configs[sectionName].GetString("internal_ip_address", "0.0.0.0");
  215. IPAddress ipAddressResult;
  216. if (IPAddress.TryParse(ipAddress, out ipAddressResult))
  217. {
  218. m_internalEndPoint = new IPEndPoint(ipAddressResult, 0);
  219. }
  220. else
  221. {
  222. errorMessage = "needs an IP Address (IPAddress)";
  223. }
  224. m_internalEndPoint.Port =
  225. source.Configs[sectionName].GetInt("internal_ip_port", (int) NetworkServersInfo.DefaultHttpListenerPort);
  226. string externalHost = source.Configs[sectionName].GetString("external_host_name", "127.0.0.1");
  227. if (externalHost != "SYSTEMIP")
  228. {
  229. m_externalHostName = externalHost;
  230. }
  231. else
  232. {
  233. m_externalHostName = Util.GetLocalHost().ToString();
  234. }
  235. MasterAvatarFirstName = source.Configs[sectionName].GetString("master_avatar_first", "Test");
  236. MasterAvatarLastName = source.Configs[sectionName].GetString("master_avatar_last", "User");
  237. MasterAvatarSandboxPassword = source.Configs[sectionName].GetString("master_avatar_pass", "test");
  238. if (errorMessage != "")
  239. {
  240. // a error
  241. }
  242. }
  243. public void loadConfigurationOptions()
  244. {
  245. configMember.addConfigurationOption("sim_UUID", ConfigurationOption.ConfigurationTypes.TYPE_LLUUID,
  246. "UUID of Region (Default is recommended, random UUID)",
  247. LLUUID.Random().ToString(), true);
  248. configMember.addConfigurationOption("sim_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  249. "Region Name", "OpenSim Test", false);
  250. configMember.addConfigurationOption("sim_location_x", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  251. "Grid Location (X Axis)", "1000", false);
  252. configMember.addConfigurationOption("sim_location_y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  253. "Grid Location (Y Axis)", "1000", false);
  254. //configMember.addConfigurationOption("datastore", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "Filename for local storage", "OpenSim.db", false);
  255. configMember.addConfigurationOption("internal_ip_address",
  256. ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS,
  257. "Internal IP Address for incoming UDP client connections", "0.0.0.0",
  258. false);
  259. configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  260. "Internal IP Port for incoming UDP client connections",
  261. NetworkServersInfo.DefaultHttpListenerPort.ToString(), false);
  262. configMember.addConfigurationOption("external_host_name",
  263. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  264. "External Host Name", "127.0.0.1", false);
  265. configMember.addConfigurationOption("master_avatar_uuid", ConfigurationOption.ConfigurationTypes.TYPE_LLUUID,
  266. "Master Avatar UUID", LLUUID.Zero.ToString(), true);
  267. configMember.addConfigurationOption("estate_covanant_uuid",
  268. ConfigurationOption.ConfigurationTypes.TYPE_LLUUID, "Estate Covenant",
  269. LLUUID.Zero.ToString(), true);
  270. configMember.addConfigurationOption("master_avatar_first",
  271. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  272. "First Name of Master Avatar", "Test", false,
  273. (ConfigurationOption.ConfigurationOptionShouldBeAsked)
  274. shouldMasterAvatarDetailsBeAsked);
  275. configMember.addConfigurationOption("master_avatar_last",
  276. ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
  277. "Last Name of Master Avatar", "User", false,
  278. (ConfigurationOption.ConfigurationOptionShouldBeAsked)
  279. shouldMasterAvatarDetailsBeAsked);
  280. configMember.addConfigurationOption("master_avatar_pass", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  281. "(Sandbox Mode Only)Password for Master Avatar account", "test", false,
  282. (ConfigurationOption.ConfigurationOptionShouldBeAsked)
  283. shouldMasterAvatarDetailsBeAsked);
  284. }
  285. public bool shouldMasterAvatarDetailsBeAsked(string configuration_key)
  286. {
  287. if (MasterAvatarAssignedUUID.Equals(null) || MasterAvatarAssignedUUID.ToString() == LLUUID.Zero.ToString())
  288. {
  289. return true;
  290. }
  291. return false;
  292. }
  293. public bool handleIncomingConfiguration(string configuration_key, object configuration_result)
  294. {
  295. switch (configuration_key)
  296. {
  297. case "sim_UUID":
  298. RegionID = (LLUUID) configuration_result;
  299. break;
  300. case "sim_name":
  301. RegionName = (string) configuration_result;
  302. break;
  303. case "sim_location_x":
  304. m_regionLocX = (uint) configuration_result;
  305. break;
  306. case "sim_location_y":
  307. m_regionLocY = (uint) configuration_result;
  308. break;
  309. case "datastore":
  310. DataStore = (string) configuration_result;
  311. break;
  312. case "internal_ip_address":
  313. IPAddress address = (IPAddress) configuration_result;
  314. m_internalEndPoint = new IPEndPoint(address, 0);
  315. break;
  316. case "internal_ip_port":
  317. m_internalEndPoint.Port = (int) configuration_result;
  318. break;
  319. case "external_host_name":
  320. if ((string) configuration_result != "SYSTEMIP")
  321. {
  322. m_externalHostName = (string) configuration_result;
  323. }
  324. else
  325. {
  326. m_externalHostName = Util.GetLocalHost().ToString();
  327. }
  328. break;
  329. case "master_avatar_uuid":
  330. MasterAvatarAssignedUUID = (LLUUID) configuration_result;
  331. break;
  332. case "estate_covanant_uuid":
  333. CovenantID = (LLUUID) configuration_result;
  334. break;
  335. case "master_avatar_first":
  336. MasterAvatarFirstName = (string) configuration_result;
  337. break;
  338. case "master_avatar_last":
  339. MasterAvatarLastName = (string) configuration_result;
  340. break;
  341. case "master_avatar_pass":
  342. string tempMD5Passwd = (string) configuration_result;
  343. MasterAvatarSandboxPassword = Util.Md5Hash(Util.Md5Hash(tempMD5Passwd) + ":" + "");
  344. break;
  345. }
  346. return true;
  347. }
  348. public void SaveEstatecovenantUUID(LLUUID notecard)
  349. {
  350. configMember.forceSetConfigurationOption("estate_covanant_uuid", notecard.ToString());
  351. }
  352. }
  353. }