RegionInfo.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /*
  2. * Copyright (c) Contributors, http://www.openmetaverse.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.Globalization;
  30. using System.Net;
  31. using System.Net.Sockets;
  32. using libsecondlife;
  33. using OpenSim.Framework.Console;
  34. using OpenSim.Framework.Interfaces;
  35. using OpenSim.Framework.Utilities;
  36. namespace OpenSim.Framework.Types
  37. {
  38. public class RegionInfo
  39. {
  40. public LLUUID SimUUID = new LLUUID();
  41. public string RegionName = "";
  42. private IPEndPoint m_internalEndPoint;
  43. public IPEndPoint InternalEndPoint
  44. {
  45. get
  46. {
  47. return m_internalEndPoint;
  48. }
  49. }
  50. public IPEndPoint ExternalEndPoint
  51. {
  52. get
  53. {
  54. // Old one defaults to IPv6
  55. //return new IPEndPoint( Dns.GetHostAddresses( m_externalHostName )[0], m_internalEndPoint.Port );
  56. // New method favors IPv4
  57. IPAddress ia = null;
  58. foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
  59. {
  60. if (ia == null)
  61. ia = Adr;
  62. if (Adr.AddressFamily == AddressFamily.InterNetwork)
  63. {
  64. ia = Adr;
  65. break;
  66. }
  67. }
  68. return new IPEndPoint(ia, m_internalEndPoint.Port);
  69. }
  70. }
  71. private string m_externalHostName;
  72. public string ExternalHostName
  73. {
  74. get
  75. {
  76. return m_externalHostName;
  77. }
  78. }
  79. private uint? m_regionLocX;
  80. public uint RegionLocX
  81. {
  82. get
  83. {
  84. return m_regionLocX.Value;
  85. }
  86. }
  87. private uint? m_regionLocY;
  88. public uint RegionLocY
  89. {
  90. get
  91. {
  92. return m_regionLocY.Value;
  93. }
  94. }
  95. private ulong? m_regionHandle;
  96. public ulong RegionHandle
  97. {
  98. get
  99. {
  100. if (!m_regionHandle.HasValue)
  101. {
  102. m_regionHandle = Util.UIntsToLong((RegionLocX * 256), (RegionLocY * 256));
  103. }
  104. return m_regionHandle.Value;
  105. }
  106. }
  107. // Only used for remote regions , ie ones not in the current instance
  108. private uint m_remotingPort;
  109. public uint RemotingPort
  110. {
  111. get
  112. {
  113. return m_remotingPort;
  114. }
  115. set
  116. {
  117. m_remotingPort = value;
  118. }
  119. }
  120. public string RemotingAddress;
  121. public string DataStore = "";
  122. public bool isSandbox = false;
  123. public LLUUID MasterAvatarAssignedUUID = new LLUUID();
  124. public string MasterAvatarFirstName = "";
  125. public string MasterAvatarLastName = "";
  126. public string MasterAvatarSandboxPassword = "";
  127. public EstateSettings estateSettings;
  128. public RegionInfo()
  129. {
  130. estateSettings = new EstateSettings();
  131. }
  132. public RegionInfo(uint regionLocX, uint regionLocY, IPEndPoint internalEndPoint, string externalUri)
  133. : this()
  134. {
  135. m_regionLocX = regionLocX;
  136. m_regionLocY = regionLocY;
  137. m_internalEndPoint = internalEndPoint;
  138. m_externalHostName = externalUri;
  139. }
  140. public void InitConfig(bool sandboxMode, IGenericConfig configData)
  141. {
  142. this.isSandbox = sandboxMode;
  143. try
  144. {
  145. string attri = "";
  146. // Sim UUID
  147. string simId = configData.GetAttribute("SimUUID");
  148. if (String.IsNullOrEmpty( simId ))
  149. {
  150. this.SimUUID = LLUUID.Random();
  151. }
  152. else
  153. {
  154. this.SimUUID = new LLUUID(simId);
  155. }
  156. configData.SetAttribute("SimUUID", this.SimUUID.ToString());
  157. this.RegionName = GetString(configData, "SimName", "OpenSim test", "Region Name");
  158. //m_regionLocX = (uint) GetInt(configData, "SimLocationX", 1000, "Grid Location X");
  159. attri = "";
  160. attri = configData.GetAttribute("SimLocationX");
  161. if (attri == "")
  162. {
  163. string location = MainLog.Instance.CmdPrompt("Grid Location X", "1000");
  164. configData.SetAttribute("SimLocationX", location);
  165. m_regionLocX = (uint)Convert.ToUInt32(location);
  166. }
  167. else
  168. {
  169. m_regionLocX = (uint)Convert.ToUInt32(attri);
  170. }
  171. // Sim/Grid location Y
  172. attri = "";
  173. attri = configData.GetAttribute("SimLocationY");
  174. if (attri == "")
  175. {
  176. string location = MainLog.Instance.CmdPrompt("Grid Location Y", "1000");
  177. configData.SetAttribute("SimLocationY", location);
  178. m_regionLocY = (uint)Convert.ToUInt32(location);
  179. }
  180. else
  181. {
  182. m_regionLocY = (uint)Convert.ToUInt32(attri);
  183. }
  184. m_regionHandle = null;
  185. this.DataStore = GetString(configData, "Datastore", "localworld.yap", "Filename for local storage");
  186. IPAddress internalAddress = GetIPAddress(configData, "InternalIPAddress", "0.0.0.0", "Internal IP Address for UDP client connections");
  187. int internalPort = GetIPPort(configData, "InternalIPPort", "9000", "Internal IP Port for UDP client connections");
  188. m_internalEndPoint = new IPEndPoint(internalAddress, internalPort);
  189. m_externalHostName = GetString(configData, "ExternalHostName", "127.0.0.1", "External Host Name");
  190. estateSettings.terrainFile =
  191. GetString(configData, "TerrainFile", "default.r32", "GENERAL SETTING: Default Terrain File");
  192. attri = "";
  193. attri = configData.GetAttribute("TerrainMultiplier");
  194. if (attri == "")
  195. {
  196. string re = MainLog.Instance.CmdPrompt("GENERAL SETTING: Terrain Height Multiplier", "60.0");
  197. this.estateSettings.terrainMultiplier = Convert.ToDouble(re, CultureInfo.InvariantCulture);
  198. configData.SetAttribute("TerrainMultiplier", this.estateSettings.terrainMultiplier.ToString());
  199. }
  200. else
  201. {
  202. this.estateSettings.terrainMultiplier = Convert.ToDouble(attri);
  203. }
  204. attri = "";
  205. attri = configData.GetAttribute("MasterAvatarFirstName");
  206. if (attri == "")
  207. {
  208. this.MasterAvatarFirstName = MainLog.Instance.CmdPrompt("First name of Master Avatar (Land and Region Owner)", "Test");
  209. configData.SetAttribute("MasterAvatarFirstName", this.MasterAvatarFirstName);
  210. }
  211. else
  212. {
  213. this.MasterAvatarFirstName = attri;
  214. }
  215. attri = "";
  216. attri = configData.GetAttribute("MasterAvatarLastName");
  217. if (attri == "")
  218. {
  219. this.MasterAvatarLastName = MainLog.Instance.CmdPrompt("Last name of Master Avatar (Land and Region Owner)", "User");
  220. configData.SetAttribute("MasterAvatarLastName", this.MasterAvatarLastName);
  221. }
  222. else
  223. {
  224. this.MasterAvatarLastName = attri;
  225. }
  226. if (isSandbox) //Sandbox Mode Specific Settings
  227. {
  228. attri = "";
  229. attri = configData.GetAttribute("MasterAvatarSandboxPassword");
  230. if (attri == "")
  231. {
  232. this.MasterAvatarSandboxPassword = MainLog.Instance.CmdPrompt("Password of Master Avatar (Needed for sandbox mode account creation only)", "test");
  233. //Should I store this?
  234. configData.SetAttribute("MasterAvatarSandboxPassword", this.MasterAvatarSandboxPassword);
  235. }
  236. else
  237. {
  238. this.MasterAvatarSandboxPassword = attri;
  239. }
  240. }
  241. configData.Commit();
  242. }
  243. catch (Exception e)
  244. {
  245. MainLog.Instance.Warn("Config.cs:InitConfig() - Exception occured");
  246. MainLog.Instance.Warn(e.ToString());
  247. }
  248. MainLog.Instance.Verbose("Sim settings loaded:");
  249. MainLog.Instance.Verbose("UUID: " + this.SimUUID.ToStringHyphenated());
  250. MainLog.Instance.Verbose("Name: " + this.RegionName);
  251. MainLog.Instance.Verbose("Region Location: [" + this.RegionLocX.ToString() + "," + this.RegionLocY + "]");
  252. MainLog.Instance.Verbose("Region Handle: " + this.RegionHandle.ToString());
  253. MainLog.Instance.Verbose("Listening on IP end point: " + m_internalEndPoint.ToString() );
  254. MainLog.Instance.Verbose("Sandbox Mode? " + isSandbox.ToString());
  255. }
  256. private uint GetInt(IGenericConfig configData, string p, int p_3, string p_4)
  257. {
  258. throw new Exception("The method or operation is not implemented.");
  259. }
  260. private string GetString(IGenericConfig configData, string attrName, string defaultvalue, string prompt)
  261. {
  262. string s = configData.GetAttribute(attrName);
  263. if (String.IsNullOrEmpty( s ))
  264. {
  265. s = MainLog.Instance.CmdPrompt(prompt, defaultvalue);
  266. configData.SetAttribute(attrName, s );
  267. }
  268. return s;
  269. }
  270. private IPAddress GetIPAddress(IGenericConfig configData, string attrName, string defaultvalue, string prompt)
  271. {
  272. string addressStr = configData.GetAttribute(attrName);
  273. IPAddress address;
  274. if (!IPAddress.TryParse(addressStr, out address))
  275. {
  276. address = MainLog.Instance.CmdPromptIPAddress(prompt, defaultvalue);
  277. configData.SetAttribute(attrName, address.ToString());
  278. }
  279. return address;
  280. }
  281. private int GetIPPort(IGenericConfig configData, string attrName, string defaultvalue, string prompt)
  282. {
  283. string portStr = configData.GetAttribute(attrName);
  284. int port;
  285. if (!int.TryParse(portStr, out port))
  286. {
  287. port = MainLog.Instance.CmdPromptIPPort(prompt, defaultvalue);
  288. configData.SetAttribute(attrName, port.ToString());
  289. }
  290. return port;
  291. }
  292. }
  293. }