RegionProfileServiceProxy.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 OpenSimulator 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 System.Collections.Generic;
  30. using System.Text;
  31. using Nwc.XmlRpc;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. namespace OpenSim.Data
  35. {
  36. public class RegionProfileServiceProxy : IRegionProfileService
  37. {
  38. /// <summary>
  39. /// Request sim data based on arbitrary key/value
  40. /// </summary>
  41. private RegionProfileData RequestSimData(Uri gridserverUrl, string gridserverSendkey, string keyField, string keyValue)
  42. {
  43. Hashtable requestData = new Hashtable();
  44. requestData[keyField] = keyValue;
  45. requestData["authkey"] = gridserverSendkey;
  46. ArrayList SendParams = new ArrayList();
  47. SendParams.Add(requestData);
  48. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
  49. XmlRpcResponse GridResp = GridReq.Send(gridserverUrl.ToString(), 3000);
  50. Hashtable responseData = (Hashtable) GridResp.Value;
  51. RegionProfileData simData = null;
  52. if (!responseData.ContainsKey("error"))
  53. {
  54. simData = new RegionProfileData();
  55. simData.regionLocX = Convert.ToUInt32((string) responseData["region_locx"]);
  56. simData.regionLocY = Convert.ToUInt32((string) responseData["region_locy"]);
  57. simData.regionHandle =
  58. Utils.UIntsToLong((simData.regionLocX * Constants.RegionSize),
  59. (simData.regionLocY*Constants.RegionSize));
  60. simData.serverIP = (string) responseData["sim_ip"];
  61. simData.serverPort = Convert.ToUInt32((string) responseData["sim_port"]);
  62. simData.httpPort = Convert.ToUInt32((string) responseData["http_port"]);
  63. simData.remotingPort = Convert.ToUInt32((string) responseData["remoting_port"]);
  64. simData.serverURI = (string) responseData["server_uri"];
  65. simData.httpServerURI = "http://" + (string)responseData["sim_ip"] + ":" + simData.httpPort.ToString() + "/";
  66. simData.UUID = new UUID((string) responseData["region_UUID"]);
  67. simData.regionName = (string) responseData["region_name"];
  68. }
  69. return simData;
  70. }
  71. /// <summary>
  72. /// Request sim profile information from a grid server, by Region UUID
  73. /// </summary>
  74. /// <param name="regionId">The region UUID to look for</param>
  75. /// <param name="gridserverUrl"></param>
  76. /// <param name="gridserverSendkey"></param>
  77. /// <param name="gridserverRecvkey"></param>
  78. /// <returns>The sim profile. Null if there was a request failure</returns>
  79. /// <remarks>This method should be statics</remarks>
  80. public RegionProfileData RequestSimProfileData(UUID regionId, Uri gridserverUrl,
  81. string gridserverSendkey, string gridserverRecvkey)
  82. {
  83. return RequestSimData(gridserverUrl, gridserverSendkey, "region_UUID", regionId.Guid.ToString());
  84. }
  85. /// <summary>
  86. /// Request sim profile information from a grid server, by Region Handle
  87. /// </summary>
  88. /// <param name="regionHandle">the region handle to look for</param>
  89. /// <param name="gridserverUrl"></param>
  90. /// <param name="gridserverSendkey"></param>
  91. /// <param name="gridserverRecvkey"></param>
  92. /// <returns>The sim profile. Null if there was a request failure</returns>
  93. public RegionProfileData RequestSimProfileData(ulong regionHandle, Uri gridserverUrl,
  94. string gridserverSendkey, string gridserverRecvkey)
  95. {
  96. return RequestSimData(gridserverUrl, gridserverSendkey, "region_handle", regionHandle.ToString());
  97. }
  98. /// <summary>
  99. /// Request sim profile information from a grid server, by Region Name
  100. /// </summary>
  101. /// <param name="regionName">the region name to look for</param>
  102. /// <param name="gridserverUrl"></param>
  103. /// <param name="gridserverSendkey"></param>
  104. /// <param name="gridserverRecvkey"></param>
  105. /// <returns>The sim profile. Null if there was a request failure</returns>
  106. public RegionProfileData RequestSimProfileData(string regionName, Uri gridserverUrl,
  107. string gridserverSendkey, string gridserverRecvkey)
  108. {
  109. return RequestSimData(gridserverUrl, gridserverSendkey, "region_name_search", regionName );
  110. }
  111. }
  112. }