RegionProfileData.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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.Collections;
  29. using libsecondlife;
  30. using Nwc.XmlRpc;
  31. using OpenSim.Framework;
  32. namespace OpenSim.Data
  33. {
  34. /// <summary>
  35. /// A class which contains information known to the grid server about a region
  36. /// </summary>
  37. public class RegionProfileData
  38. {
  39. /// <summary>
  40. /// The name of the region
  41. /// </summary>
  42. public string regionName = String.Empty;
  43. /// <summary>
  44. /// A 64-bit number combining map position into a (mostly) unique ID
  45. /// </summary>
  46. public ulong regionHandle;
  47. /// <summary>
  48. /// OGS/OpenSim Specific ID for a region
  49. /// </summary>
  50. public LLUUID UUID;
  51. /// <summary>
  52. /// Coordinates of the region
  53. /// </summary>
  54. public uint regionLocX;
  55. public uint regionLocY;
  56. public uint regionLocZ; // Reserved (round-robin, layers, etc)
  57. /// <summary>
  58. /// Authentication secrets
  59. /// </summary>
  60. /// <remarks>Not very secure, needs improvement.</remarks>
  61. public string regionSendKey = String.Empty;
  62. public string regionRecvKey = String.Empty;
  63. public string regionSecret = String.Empty;
  64. /// <summary>
  65. /// Whether the region is online
  66. /// </summary>
  67. public bool regionOnline;
  68. /// <summary>
  69. /// Information about the server that the region is currently hosted on
  70. /// </summary>
  71. public string serverIP = String.Empty;
  72. public uint serverPort;
  73. public string serverURI = String.Empty;
  74. public uint httpPort;
  75. public uint remotingPort;
  76. public string httpServerURI = String.Empty;
  77. /// <summary>
  78. /// Set of optional overrides. Can be used to create non-eulicidean spaces.
  79. /// </summary>
  80. public ulong regionNorthOverrideHandle;
  81. public ulong regionSouthOverrideHandle;
  82. public ulong regionEastOverrideHandle;
  83. public ulong regionWestOverrideHandle;
  84. /// <summary>
  85. /// Optional: URI Location of the region database
  86. /// </summary>
  87. /// <remarks>Used for floating sim pools where the region data is not nessecarily coupled to a specific server</remarks>
  88. public string regionDataURI = String.Empty;
  89. /// <summary>
  90. /// Region Asset Details
  91. /// </summary>
  92. public string regionAssetURI = String.Empty;
  93. public string regionAssetSendKey = String.Empty;
  94. public string regionAssetRecvKey = String.Empty;
  95. /// <summary>
  96. /// Region Userserver Details
  97. /// </summary>
  98. public string regionUserURI = String.Empty;
  99. public string regionUserSendKey = String.Empty;
  100. public string regionUserRecvKey = String.Empty;
  101. /// <summary>
  102. /// Region Map Texture Asset
  103. /// </summary>
  104. public LLUUID regionMapTextureID = new LLUUID("00000000-0000-1111-9999-000000000006");
  105. /// <summary>
  106. /// this particular mod to the file provides support within the spec for RegionProfileData for the
  107. /// owner_uuid for the region
  108. /// </summary>
  109. public LLUUID owner_uuid = LLUUID.Zero;
  110. /// <summary>
  111. /// OGS/OpenSim Specific original ID for a region after move/split
  112. /// </summary>
  113. public LLUUID originUUID;
  114. /// <summary>
  115. /// Request sim profile information from a grid server, by Region UUID
  116. /// </summary>
  117. /// <param name="region_uuid">The region UUID to look for</param>
  118. /// <param name="gridserver_url"></param>
  119. /// <param name="gridserver_sendkey"></param>
  120. /// <param name="gridserver_recvkey"></param>
  121. /// <returns>The sim profile. Null if there was a request failure</returns>
  122. /// <remarks>This method should be statics</remarks>
  123. public RegionProfileData RequestSimProfileData(LLUUID region_uuid, string gridserver_url,
  124. string gridserver_sendkey, string gridserver_recvkey)
  125. {
  126. Hashtable requestData = new Hashtable();
  127. requestData["region_uuid"] = region_uuid.UUID.ToString();
  128. requestData["authkey"] = gridserver_sendkey;
  129. ArrayList SendParams = new ArrayList();
  130. SendParams.Add(requestData);
  131. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
  132. XmlRpcResponse GridResp = GridReq.Send(gridserver_url, 3000);
  133. Hashtable responseData = (Hashtable) GridResp.Value;
  134. if (responseData.ContainsKey("error"))
  135. {
  136. return null;
  137. }
  138. RegionProfileData simData = new RegionProfileData();
  139. simData.regionLocX = Convert.ToUInt32((string) responseData["region_locx"]);
  140. simData.regionLocY = Convert.ToUInt32((string) responseData["region_locy"]);
  141. simData.regionHandle = Helpers.UIntsToLong((simData.regionLocX * Constants.RegionSize), (simData.regionLocY * Constants.RegionSize));
  142. simData.serverIP = (string) responseData["sim_ip"];
  143. simData.serverPort = Convert.ToUInt32((string) responseData["sim_port"]);
  144. simData.httpPort = Convert.ToUInt32((string) responseData["http_port"]);
  145. simData.remotingPort = Convert.ToUInt32((string) responseData["remoting_port"]);
  146. simData.serverURI = (string)responseData["server_uri"];
  147. simData.httpServerURI = "http://" + simData.serverIP + ":" + simData.httpPort.ToString() + "/";
  148. simData.UUID = new LLUUID((string) responseData["region_UUID"]);
  149. simData.regionName = (string) responseData["region_name"];
  150. return simData;
  151. }
  152. /// <summary>
  153. /// Request sim profile information from a grid server, by Region Handle
  154. /// </summary>
  155. /// <param name="region_handle">the region handle to look for</param>
  156. /// <param name="gridserver_url"></param>
  157. /// <param name="gridserver_sendkey"></param>
  158. /// <param name="gridserver_recvkey"></param>
  159. /// <returns>The sim profile. Null if there was a request failure</returns>
  160. public static RegionProfileData RequestSimProfileData(ulong region_handle, string gridserver_url,
  161. string gridserver_sendkey, string gridserver_recvkey)
  162. {
  163. Hashtable requestData = new Hashtable();
  164. requestData["region_handle"] = region_handle.ToString();
  165. requestData["authkey"] = gridserver_sendkey;
  166. ArrayList SendParams = new ArrayList();
  167. SendParams.Add(requestData);
  168. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
  169. XmlRpcResponse GridResp = GridReq.Send(gridserver_url, 3000);
  170. Hashtable responseData = (Hashtable) GridResp.Value;
  171. if (responseData.ContainsKey("error"))
  172. {
  173. return null;
  174. }
  175. RegionProfileData simData = new RegionProfileData();
  176. simData.regionLocX = Convert.ToUInt32((string) responseData["region_locx"]);
  177. simData.regionLocY = Convert.ToUInt32((string) responseData["region_locy"]);
  178. simData.regionHandle = Helpers.UIntsToLong((simData.regionLocX * Constants.RegionSize), (simData.regionLocY * Constants.RegionSize));
  179. simData.serverIP = (string) responseData["sim_ip"];
  180. simData.serverPort = Convert.ToUInt32((string) responseData["sim_port"]);
  181. simData.httpPort = Convert.ToUInt32((string) responseData["http_port"]);
  182. simData.remotingPort = Convert.ToUInt32((string) responseData["remoting_port"]);
  183. simData.httpServerURI = "http://" + simData.serverIP + ":" + simData.httpPort.ToString() + "/";
  184. simData.serverURI = (string)responseData["server_uri"];
  185. simData.UUID = new LLUUID((string) responseData["region_UUID"]);
  186. simData.regionName = (string) responseData["region_name"];
  187. return simData;
  188. }
  189. /// <summary>
  190. /// Request sim profile information from a grid server, by Region Name
  191. /// </summary>
  192. /// <param name="region_handle">the region name to look for</param>
  193. /// <param name="gridserver_url"></param>
  194. /// <param name="gridserver_sendkey"></param>
  195. /// <param name="gridserver_recvkey"></param>
  196. /// <returns>The sim profile. Null if there was a request failure</returns>
  197. public static RegionProfileData RequestSimProfileData(string regionName, string gridserver_url,
  198. string gridserver_sendkey, string gridserver_recvkey)
  199. {
  200. Hashtable requestData = new Hashtable();
  201. requestData["region_name_search"] = regionName;
  202. requestData["authkey"] = gridserver_sendkey;
  203. ArrayList SendParams = new ArrayList();
  204. SendParams.Add(requestData);
  205. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
  206. XmlRpcResponse GridResp = GridReq.Send(gridserver_url, 3000);
  207. Hashtable responseData = (Hashtable)GridResp.Value;
  208. if (responseData.ContainsKey("error"))
  209. {
  210. return null;
  211. }
  212. RegionProfileData simData = new RegionProfileData();
  213. simData.regionLocX = Convert.ToUInt32((string)responseData["region_locx"]);
  214. simData.regionLocY = Convert.ToUInt32((string)responseData["region_locy"]);
  215. simData.regionHandle = Helpers.UIntsToLong((simData.regionLocX * Constants.RegionSize), (simData.regionLocY * Constants.RegionSize));
  216. simData.serverIP = (string)responseData["sim_ip"];
  217. simData.serverPort = Convert.ToUInt32((string)responseData["sim_port"]);
  218. simData.httpPort = Convert.ToUInt32((string)responseData["http_port"]);
  219. simData.remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]);
  220. simData.httpServerURI = "http://" + simData.serverIP + ":" + simData.httpPort.ToString() + "/";
  221. simData.serverURI = (string)responseData["server_uri"];
  222. simData.UUID = new LLUUID((string)responseData["region_UUID"]);
  223. simData.regionName = (string)responseData["region_name"];
  224. return simData;
  225. }
  226. }
  227. }