UserAgentServerConnector.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 Nini.Config;
  33. using OpenSim.Framework;
  34. using OpenSim.Server.Base;
  35. using OpenSim.Services.Interfaces;
  36. using OpenSim.Framework.Servers.HttpServer;
  37. using OpenSim.Server.Handlers.Base;
  38. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  39. using log4net;
  40. using Nwc.XmlRpc;
  41. using OpenMetaverse;
  42. namespace OpenSim.Server.Handlers.Hypergrid
  43. {
  44. public class UserAgentServerConnector : ServiceConnector
  45. {
  46. private static readonly ILog m_log =
  47. LogManager.GetLogger(
  48. MethodBase.GetCurrentMethod().DeclaringType);
  49. private IUserAgentService m_HomeUsersService;
  50. public UserAgentServerConnector(IConfigSource config, IHttpServer server) :
  51. base(config, server, String.Empty)
  52. {
  53. IConfig gridConfig = config.Configs["UserAgentService"];
  54. if (gridConfig != null)
  55. {
  56. string serviceDll = gridConfig.GetString("LocalServiceModule", string.Empty);
  57. Object[] args = new Object[] { config };
  58. m_HomeUsersService = ServerUtils.LoadPlugin<IUserAgentService>(serviceDll, args);
  59. }
  60. if (m_HomeUsersService == null)
  61. throw new Exception("UserAgent server connector cannot proceed because of missing service");
  62. server.AddXmlRPCHandler("agent_is_coming_home", AgentIsComingHome, false);
  63. server.AddXmlRPCHandler("get_home_region", GetHomeRegion, false);
  64. server.AddXmlRPCHandler("verify_agent", VerifyAgent, false);
  65. server.AddXmlRPCHandler("verify_client", VerifyClient, false);
  66. server.AddXmlRPCHandler("logout_agent", LogoutAgent, false);
  67. server.AddHTTPHandler("/homeagent/", new HomeAgentHandler(m_HomeUsersService).Handler);
  68. }
  69. public XmlRpcResponse GetHomeRegion(XmlRpcRequest request, IPEndPoint remoteClient)
  70. {
  71. Hashtable requestData = (Hashtable)request.Params[0];
  72. //string host = (string)requestData["host"];
  73. //string portstr = (string)requestData["port"];
  74. string userID_str = (string)requestData["userID"];
  75. UUID userID = UUID.Zero;
  76. UUID.TryParse(userID_str, out userID);
  77. Vector3 position = Vector3.UnitY, lookAt = Vector3.UnitY;
  78. GridRegion regInfo = m_HomeUsersService.GetHomeRegion(userID, out position, out lookAt);
  79. Hashtable hash = new Hashtable();
  80. if (regInfo == null)
  81. hash["result"] = "false";
  82. else
  83. {
  84. hash["result"] = "true";
  85. hash["uuid"] = regInfo.RegionID.ToString();
  86. hash["x"] = regInfo.RegionLocX.ToString();
  87. hash["y"] = regInfo.RegionLocY.ToString();
  88. hash["region_name"] = regInfo.RegionName;
  89. hash["hostname"] = regInfo.ExternalHostName;
  90. hash["http_port"] = regInfo.HttpPort.ToString();
  91. hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString();
  92. hash["position"] = position.ToString();
  93. hash["lookAt"] = lookAt.ToString();
  94. }
  95. XmlRpcResponse response = new XmlRpcResponse();
  96. response.Value = hash;
  97. return response;
  98. }
  99. public XmlRpcResponse AgentIsComingHome(XmlRpcRequest request, IPEndPoint remoteClient)
  100. {
  101. Hashtable requestData = (Hashtable)request.Params[0];
  102. //string host = (string)requestData["host"];
  103. //string portstr = (string)requestData["port"];
  104. string sessionID_str = (string)requestData["sessionID"];
  105. UUID sessionID = UUID.Zero;
  106. UUID.TryParse(sessionID_str, out sessionID);
  107. string gridName = (string)requestData["externalName"];
  108. bool success = m_HomeUsersService.AgentIsComingHome(sessionID, gridName);
  109. Hashtable hash = new Hashtable();
  110. hash["result"] = success.ToString();
  111. XmlRpcResponse response = new XmlRpcResponse();
  112. response.Value = hash;
  113. return response;
  114. }
  115. public XmlRpcResponse VerifyAgent(XmlRpcRequest request, IPEndPoint remoteClient)
  116. {
  117. Hashtable requestData = (Hashtable)request.Params[0];
  118. //string host = (string)requestData["host"];
  119. //string portstr = (string)requestData["port"];
  120. string sessionID_str = (string)requestData["sessionID"];
  121. UUID sessionID = UUID.Zero;
  122. UUID.TryParse(sessionID_str, out sessionID);
  123. string token = (string)requestData["token"];
  124. bool success = m_HomeUsersService.VerifyAgent(sessionID, token);
  125. Hashtable hash = new Hashtable();
  126. hash["result"] = success.ToString();
  127. XmlRpcResponse response = new XmlRpcResponse();
  128. response.Value = hash;
  129. return response;
  130. }
  131. public XmlRpcResponse VerifyClient(XmlRpcRequest request, IPEndPoint remoteClient)
  132. {
  133. Hashtable requestData = (Hashtable)request.Params[0];
  134. //string host = (string)requestData["host"];
  135. //string portstr = (string)requestData["port"];
  136. string sessionID_str = (string)requestData["sessionID"];
  137. UUID sessionID = UUID.Zero;
  138. UUID.TryParse(sessionID_str, out sessionID);
  139. string token = (string)requestData["token"];
  140. bool success = m_HomeUsersService.VerifyClient(sessionID, token);
  141. Hashtable hash = new Hashtable();
  142. hash["result"] = success.ToString();
  143. XmlRpcResponse response = new XmlRpcResponse();
  144. response.Value = hash;
  145. return response;
  146. }
  147. public XmlRpcResponse LogoutAgent(XmlRpcRequest request, IPEndPoint remoteClient)
  148. {
  149. Hashtable requestData = (Hashtable)request.Params[0];
  150. //string host = (string)requestData["host"];
  151. //string portstr = (string)requestData["port"];
  152. string sessionID_str = (string)requestData["sessionID"];
  153. UUID sessionID = UUID.Zero;
  154. UUID.TryParse(sessionID_str, out sessionID);
  155. string userID_str = (string)requestData["userID"];
  156. UUID userID = UUID.Zero;
  157. UUID.TryParse(userID_str, out userID);
  158. m_HomeUsersService.LogoutAgent(userID, sessionID);
  159. Hashtable hash = new Hashtable();
  160. hash["result"] = "true";
  161. XmlRpcResponse response = new XmlRpcResponse();
  162. response.Value = hash;
  163. return response;
  164. }
  165. }
  166. }