HypergridHandlers.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. bool success = m_GatekeeperService.LinkRegion(name, out regionID, out regionHandle, out externalName, out imageURL, out reason);
  67. Hashtable hash = new Hashtable();
  68. hash["result"] = success.ToString();
  69. hash["uuid"] = regionID.ToString();
  70. hash["handle"] = regionHandle.ToString();
  71. hash["region_image"] = imageURL;
  72. hash["external_name"] = externalName;
  73. XmlRpcResponse response = new XmlRpcResponse();
  74. response.Value = hash;
  75. return response;
  76. }
  77. public XmlRpcResponse GetRegion(XmlRpcRequest request, IPEndPoint remoteClient)
  78. {
  79. Hashtable requestData = (Hashtable)request.Params[0];
  80. //string host = (string)requestData["host"];
  81. //string portstr = (string)requestData["port"];
  82. string regionID_str = (string)requestData["region_uuid"];
  83. UUID regionID = UUID.Zero;
  84. UUID.TryParse(regionID_str, out regionID);
  85. GridRegion regInfo = m_GatekeeperService.GetHyperlinkRegion(regionID);
  86. Hashtable hash = new Hashtable();
  87. if (regInfo == null)
  88. hash["result"] = "false";
  89. else
  90. {
  91. hash["result"] = "true";
  92. hash["uuid"] = regInfo.RegionID.ToString();
  93. hash["x"] = regInfo.RegionLocX.ToString();
  94. hash["y"] = regInfo.RegionLocY.ToString();
  95. hash["region_name"] = regInfo.RegionName;
  96. hash["hostname"] = regInfo.ExternalHostName;
  97. hash["http_port"] = regInfo.HttpPort.ToString();
  98. hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString();
  99. }
  100. XmlRpcResponse response = new XmlRpcResponse();
  101. response.Value = hash;
  102. return response;
  103. }
  104. }
  105. }