RegionProfileData.cs 12 KB

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