RegionProfileServiceProxy.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 : IRegionProfileRouter
  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. uint locX = Convert.ToUInt32((string)responseData["region_locx"]);
  55. uint locY = Convert.ToUInt32((string)responseData["region_locy"]);
  56. string externalHostName = (string)responseData["sim_ip"];
  57. uint simPort = Convert.ToUInt32((string)responseData["sim_port"]);
  58. uint httpPort = Convert.ToUInt32((string)responseData["http_port"]);
  59. uint remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]);
  60. string serverUri = (string)responseData["server_uri"];
  61. UUID regionID = new UUID((string)responseData["region_UUID"]);
  62. string regionName = (string)responseData["region_name"];
  63. byte access = Convert.ToByte((string)responseData["access"]);
  64. simData = RegionProfileData.Create(regionID, regionName, locX, locY, externalHostName, simPort, httpPort, remotingPort, serverUri, access);
  65. }
  66. return simData;
  67. }
  68. /// <summary>
  69. /// Request sim profile information from a grid server, by Region UUID
  70. /// </summary>
  71. /// <param name="regionId">The region UUID to look for</param>
  72. /// <param name="gridserverUrl"></param>
  73. /// <param name="gridserverSendkey"></param>
  74. /// <param name="gridserverRecvkey"></param>
  75. /// <returns>The sim profile. Null if there was a request failure</returns>
  76. /// <remarks>This method should be statics</remarks>
  77. public RegionProfileData RequestSimProfileData(UUID regionId, Uri gridserverUrl,
  78. string gridserverSendkey, string gridserverRecvkey)
  79. {
  80. return RequestSimData(gridserverUrl, gridserverSendkey, "region_UUID", regionId.Guid.ToString());
  81. }
  82. /// <summary>
  83. /// Request sim profile information from a grid server, by Region Handle
  84. /// </summary>
  85. /// <param name="regionHandle">the region handle to look for</param>
  86. /// <param name="gridserverUrl"></param>
  87. /// <param name="gridserverSendkey"></param>
  88. /// <param name="gridserverRecvkey"></param>
  89. /// <returns>The sim profile. Null if there was a request failure</returns>
  90. public RegionProfileData RequestSimProfileData(ulong regionHandle, Uri gridserverUrl,
  91. string gridserverSendkey, string gridserverRecvkey)
  92. {
  93. return RequestSimData(gridserverUrl, gridserverSendkey, "region_handle", regionHandle.ToString());
  94. }
  95. /// <summary>
  96. /// Request sim profile information from a grid server, by Region Name
  97. /// </summary>
  98. /// <param name="regionName">the region name to look for</param>
  99. /// <param name="gridserverUrl"></param>
  100. /// <param name="gridserverSendkey"></param>
  101. /// <param name="gridserverRecvkey"></param>
  102. /// <returns>The sim profile. Null if there was a request failure</returns>
  103. public RegionProfileData RequestSimProfileData(string regionName, Uri gridserverUrl,
  104. string gridserverSendkey, string gridserverRecvkey)
  105. {
  106. return RequestSimData(gridserverUrl, gridserverSendkey, "region_name_search", regionName);
  107. }
  108. }
  109. }