HypergridHandlers.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.Net;
  31. using System.Reflection;
  32. using OpenSim.Services.Interfaces;
  33. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  34. using log4net;
  35. using Nwc.XmlRpc;
  36. using OpenMetaverse;
  37. namespace OpenSim.Server.Handlers.Hypergrid
  38. {
  39. public class HypergridHandlers
  40. {
  41. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  42. private IGatekeeperService m_GatekeeperService;
  43. public HypergridHandlers(IGatekeeperService gatekeeper)
  44. {
  45. m_GatekeeperService = gatekeeper;
  46. m_log.DebugFormat("[HYPERGRID HANDLERS]: Active");
  47. }
  48. /// <summary>
  49. /// Someone wants to link to us
  50. /// </summary>
  51. /// <param name="request"></param>
  52. /// <returns></returns>
  53. public XmlRpcResponse LinkRegionRequest(XmlRpcRequest request, IPEndPoint remoteClient)
  54. {
  55. Hashtable requestData = (Hashtable)request.Params[0];
  56. //string host = (string)requestData["host"];
  57. //string portstr = (string)requestData["port"];
  58. string name = (string)requestData["region_name"];
  59. if (name == null)
  60. name = string.Empty;
  61. m_log.DebugFormat("[HG Handler]: XMLRequest to link to {0} from {1}", (name.Length == 0) ? "default region" : name, remoteClient.Address.ToString());
  62. bool success = m_GatekeeperService.LinkLocalRegion(name, out UUID regionID, out ulong regionHandle, out string externalName,
  63. out string imageURL, out string reason, out int sizeX, out int sizeY);
  64. Hashtable hash = new Hashtable();
  65. hash["result"] = success.ToString();
  66. hash["uuid"] = regionID.ToString();
  67. hash["handle"] = regionHandle.ToString();
  68. hash["size_x"] = sizeX.ToString();
  69. hash["size_y"] = sizeY.ToString();
  70. hash["region_image"] = imageURL;
  71. hash["external_name"] = externalName;
  72. XmlRpcResponse response = new XmlRpcResponse();
  73. response.Value = hash;
  74. return response;
  75. }
  76. public XmlRpcResponse GetRegion(XmlRpcRequest request, IPEndPoint remoteClient)
  77. {
  78. Hashtable requestData = (Hashtable)request.Params[0];
  79. //string host = (string)requestData["host"];
  80. //string portstr = (string)requestData["port"];
  81. string regionID_str = (string)requestData["region_uuid"];
  82. UUID regionID = UUID.Zero;
  83. UUID.TryParse(regionID_str, out regionID);
  84. UUID agentID = UUID.Zero;
  85. string agentHomeURI = null;
  86. if (requestData.ContainsKey("agent_id"))
  87. agentID = UUID.Parse((string)requestData["agent_id"]);
  88. if (requestData.ContainsKey("agent_home_uri"))
  89. agentHomeURI = (string)requestData["agent_home_uri"];
  90. string message;
  91. GridRegion regInfo = m_GatekeeperService.GetHyperlinkRegion(regionID, agentID, agentHomeURI, out message);
  92. Hashtable hash = new Hashtable();
  93. if (regInfo == null)
  94. {
  95. hash["result"] = "false";
  96. }
  97. else
  98. {
  99. hash["result"] = "true";
  100. hash["uuid"] = regInfo.RegionID.ToString();
  101. hash["x"] = regInfo.RegionLocX.ToString();
  102. hash["y"] = regInfo.RegionLocY.ToString();
  103. hash["size_x"] = regInfo.RegionSizeX.ToString();
  104. hash["size_y"] = regInfo.RegionSizeY.ToString();
  105. hash["region_name"] = regInfo.RegionName;
  106. hash["hostname"] = regInfo.ExternalHostName;
  107. hash["http_port"] = regInfo.HttpPort.ToString();
  108. hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString();
  109. hash["server_uri"] = regInfo.ServerURI;
  110. }
  111. if (message != null)
  112. hash["message"] = message;
  113. XmlRpcResponse response = new XmlRpcResponse();
  114. response.Value = hash;
  115. return response;
  116. }
  117. }
  118. }