1
0

HypergridHandlers.cs 5.9 KB

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