RegionInfo.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Net;
  5. using System.Web;
  6. using System.IO;
  7. using OpenSim.Framework.Interfaces;
  8. using OpenSim.Framework.Utilities;
  9. using libsecondlife;
  10. namespace OpenSim
  11. {
  12. public class RegionInfo // could inherit from SimProfileBase
  13. {
  14. public LLUUID SimUUID;
  15. public string RegionName;
  16. public uint RegionLocX;
  17. public uint RegionLocY;
  18. public ulong RegionHandle;
  19. public ushort RegionWaterHeight = 20;
  20. public bool RegionTerraform = true;
  21. public int IPListenPort;
  22. public string IPListenAddr;
  23. //following should be removed and the GenericConfig object passed around,
  24. //so each class (AssetServer, GridServer etc) can access what config data they want
  25. public string AssetURL = "";
  26. public string AssetSendKey = "";
  27. public string GridURL = "";
  28. public string GridSendKey = "";
  29. public string GridRecvKey = "";
  30. public string UserURL = "";
  31. public string UserSendKey = "";
  32. public string UserRecvKey = "";
  33. private bool isSandbox;
  34. public string DataStore;
  35. public RegionInfo()
  36. {
  37. }
  38. public void SaveToGrid()
  39. {
  40. //we really want to keep any server connection code out of here and out of the code code
  41. // and put it in the server connection classes (those inheriting from IGridServer etc)
  42. string reqtext;
  43. reqtext = "<Root>";
  44. reqtext += "<authkey>" + this.GridSendKey + "</authkey>";
  45. reqtext += "<sim>";
  46. reqtext += "<uuid>" + this.SimUUID.ToString() + "</uuid>";
  47. reqtext += "<regionname>" + this.RegionName + "</regionname>";
  48. reqtext += "<sim_ip>" + this.IPListenAddr + "</sim_ip>";
  49. reqtext += "<sim_port>" + this.IPListenPort.ToString() + "</sim_port>";
  50. reqtext += "<region_locx>" + this.RegionLocX.ToString() + "</region_locx>";
  51. reqtext += "<region_locy>" + this.RegionLocY.ToString() + "</region_locy>";
  52. reqtext += "<estate_id>1</estate_id>";
  53. reqtext += "</sim>";
  54. reqtext += "</Root>";
  55. byte[] reqdata = (new System.Text.ASCIIEncoding()).GetBytes(reqtext);
  56. string newpath = "";
  57. if (this.GridURL.EndsWith("/"))
  58. {
  59. newpath = this.GridURL + "sims/";
  60. }
  61. else
  62. {
  63. newpath = this.GridURL + "/sims/";
  64. }
  65. WebRequest GridSaveReq = WebRequest.Create(newpath + this.SimUUID.ToString());
  66. GridSaveReq.Method = "POST";
  67. GridSaveReq.ContentType = "application/x-www-form-urlencoded";
  68. GridSaveReq.ContentLength = reqdata.Length;
  69. Stream stOut = GridSaveReq.GetRequestStream();
  70. stOut.Write(reqdata, 0, reqdata.Length);
  71. stOut.Close();
  72. WebResponse gridresp = GridSaveReq.GetResponse();
  73. StreamReader stIn = new StreamReader(gridresp.GetResponseStream(), Encoding.ASCII);
  74. string GridResponse = stIn.ReadToEnd();
  75. stIn.Close();
  76. gridresp.Close();
  77. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("RegionInfo.CS:SaveToGrid() - Grid said: " + GridResponse);
  78. }
  79. public void InitConfig(bool sandboxMode, IGenericConfig configData)
  80. {
  81. this.isSandbox = sandboxMode;
  82. try
  83. {
  84. // Sim UUID
  85. string attri = "";
  86. attri = configData.GetAttribute("SimUUID");
  87. if (attri == "")
  88. {
  89. this.SimUUID = LLUUID.Random();
  90. configData.SetAttribute("SimUUID", this.SimUUID.ToString());
  91. }
  92. else
  93. {
  94. this.SimUUID = new LLUUID(attri);
  95. }
  96. // Sim name
  97. attri = "";
  98. attri = configData.GetAttribute("SimName");
  99. if (attri == "")
  100. {
  101. this.RegionName = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Name", "OpenSim test");
  102. configData.SetAttribute("SimName", this.RegionName);
  103. }
  104. else
  105. {
  106. this.RegionName = attri;
  107. }
  108. // Sim/Grid location X
  109. attri = "";
  110. attri = configData.GetAttribute("SimLocationX");
  111. if (attri == "")
  112. {
  113. string location = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Grid Location X", "997");
  114. configData.SetAttribute("SimLocationX", location);
  115. this.RegionLocX = (uint)Convert.ToUInt32(location);
  116. }
  117. else
  118. {
  119. this.RegionLocX = (uint)Convert.ToUInt32(attri);
  120. }
  121. // Sim/Grid location Y
  122. attri = "";
  123. attri = configData.GetAttribute("SimLocationY");
  124. if (attri == "")
  125. {
  126. string location = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Grid Location Y", "996");
  127. configData.SetAttribute("SimLocationY", location);
  128. this.RegionLocY = (uint)Convert.ToUInt32(location);
  129. }
  130. else
  131. {
  132. this.RegionLocY = (uint)Convert.ToUInt32(attri);
  133. }
  134. // Local storage datastore
  135. attri = "";
  136. attri = configData.GetAttribute("Datastore");
  137. if (attri == "")
  138. {
  139. string datastore = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Filename for local storage", "localworld.yap");
  140. configData.SetAttribute("Datastore", datastore);
  141. this.DataStore = datastore;
  142. }
  143. else
  144. {
  145. this.DataStore = attri;
  146. }
  147. //Sim Listen Port
  148. attri = "";
  149. attri = configData.GetAttribute("SimListenPort");
  150. if (attri == "")
  151. {
  152. string port = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("UDP port for client connections", "9000");
  153. configData.SetAttribute("SimListenPort", port);
  154. this.IPListenPort = Convert.ToInt32(port);
  155. }
  156. else
  157. {
  158. this.IPListenPort = Convert.ToInt32(attri);
  159. }
  160. //Sim Listen Address
  161. attri = "";
  162. attri = configData.GetAttribute("SimListenAddress");
  163. if (attri == "")
  164. {
  165. this.IPListenAddr = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("IP Address to listen on for client connections", "127.0.0.1");
  166. configData.SetAttribute("SimListenAddress", this.IPListenAddr);
  167. }
  168. else
  169. {
  170. this.IPListenAddr = attri;
  171. }
  172. if (!isSandbox)
  173. {
  174. //shouldn't be reading this data in here, it should be up to the classes implementing the server interfaces to read what they need from the config object
  175. //Grid Server URL
  176. attri = "";
  177. attri = configData.GetAttribute("GridServerURL");
  178. if (attri == "")
  179. {
  180. this.GridURL = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Grid server URL","http://127.0.0.1:8001/");
  181. configData.SetAttribute("GridServerURL", this.GridURL);
  182. }
  183. else
  184. {
  185. this.GridURL = attri;
  186. }
  187. //Grid Send Key
  188. attri = "";
  189. attri = configData.GetAttribute("GridSendKey");
  190. if (attri == "")
  191. {
  192. this.GridSendKey = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Key to send to grid server","null");
  193. configData.SetAttribute("GridSendKey", this.GridSendKey);
  194. }
  195. else
  196. {
  197. this.GridSendKey = attri;
  198. }
  199. //Grid Receive Key
  200. attri = "";
  201. attri = configData.GetAttribute("GridRecvKey");
  202. if (attri == "")
  203. {
  204. this.GridRecvKey = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Key to expect from grid server","null");
  205. configData.SetAttribute("GridRecvKey", this.GridRecvKey);
  206. }
  207. else
  208. {
  209. this.GridRecvKey = attri;
  210. }
  211. }
  212. this.RegionHandle = Util.UIntsToLong((RegionLocX * 256), (RegionLocY * 256));
  213. if (!this.isSandbox)
  214. {
  215. this.SaveToGrid();
  216. }
  217. configData.Commit();
  218. }
  219. catch (Exception e)
  220. {
  221. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Config.cs:InitConfig() - Exception occured");
  222. OpenSim.Framework.Console.MainConsole.Instance.WriteLine(e.ToString());
  223. }
  224. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Sim settings loaded:");
  225. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("UUID: " + this.SimUUID.ToStringHyphenated());
  226. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Name: " + this.RegionName);
  227. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Region Location: [" + this.RegionLocX.ToString() + "," + this.RegionLocY + "]");
  228. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Region Handle: " + this.RegionHandle.ToString());
  229. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Listening on IP: " + this.IPListenAddr + ":" + this.IPListenPort);
  230. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Sandbox Mode? " + isSandbox.ToString());
  231. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Asset URL: " + this.AssetURL);
  232. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Asset key: " + this.AssetSendKey);
  233. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Grid URL: " + this.GridURL);
  234. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Grid key: " + this.GridSendKey);
  235. }
  236. }
  237. }