HypergridHandlers.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. UUID regionID = UUID.Zero;
  62. string externalName = string.Empty;
  63. string imageURL = string.Empty;
  64. ulong regionHandle = 0;
  65. string reason = string.Empty;
  66. int sizeX = 256;
  67. int sizeY = 256;
  68. bool success = m_GatekeeperService.LinkRegion(name, out regionID, out regionHandle, out externalName, out imageURL, out reason, out sizeX, out sizeY);
  69. Hashtable hash = new Hashtable();
  70. hash["result"] = success.ToString();
  71. hash["uuid"] = regionID.ToString();
  72. hash["handle"] = regionHandle.ToString();
  73. hash["size_x"] = sizeX.ToString();
  74. hash["size_y"] = sizeY.ToString();
  75. hash["region_image"] = imageURL;
  76. hash["external_name"] = externalName;
  77. XmlRpcResponse response = new XmlRpcResponse();
  78. response.Value = hash;
  79. return response;
  80. }
  81. public XmlRpcResponse GetRegion(XmlRpcRequest request, IPEndPoint remoteClient)
  82. {
  83. Hashtable requestData = (Hashtable)request.Params[0];
  84. //string host = (string)requestData["host"];
  85. //string portstr = (string)requestData["port"];
  86. string regionID_str = (string)requestData["region_uuid"];
  87. UUID regionID = UUID.Zero;
  88. UUID.TryParse(regionID_str, out regionID);
  89. UUID agentID = UUID.Zero;
  90. string agentHomeURI = null;
  91. if (requestData.ContainsKey("agent_id"))
  92. agentID = UUID.Parse((string)requestData["agent_id"]);
  93. if (requestData.ContainsKey("agent_home_uri"))
  94. agentHomeURI = (string)requestData["agent_home_uri"];
  95. string message;
  96. GridRegion regInfo = m_GatekeeperService.GetHyperlinkRegion(regionID, agentID, agentHomeURI, out message);
  97. Hashtable hash = new Hashtable();
  98. if (regInfo == null)
  99. {
  100. hash["result"] = "false";
  101. }
  102. else
  103. {
  104. hash["result"] = "true";
  105. hash["uuid"] = regInfo.RegionID.ToString();
  106. hash["x"] = regInfo.RegionLocX.ToString();
  107. hash["y"] = regInfo.RegionLocY.ToString();
  108. hash["size_x"] = regInfo.RegionSizeX.ToString();
  109. hash["size_y"] = regInfo.RegionSizeY.ToString();
  110. hash["region_name"] = regInfo.RegionName;
  111. hash["hostname"] = regInfo.ExternalHostName;
  112. hash["http_port"] = regInfo.HttpPort.ToString();
  113. hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString();
  114. hash["server_uri"] = regInfo.ServerURI;
  115. }
  116. if (message != null)
  117. hash["message"] = message;
  118. XmlRpcResponse response = new XmlRpcResponse();
  119. response.Value = hash;
  120. return response;
  121. }
  122. }
  123. }