UserAgentServerConnector.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. string loginServerIP = gridConfig.GetString("LoginServerIP", "127.0.0.1");
  63. server.AddXmlRPCHandler("agent_is_coming_home", AgentIsComingHome, false);
  64. server.AddXmlRPCHandler("get_home_region", GetHomeRegion, false);
  65. server.AddXmlRPCHandler("verify_agent", VerifyAgent, false);
  66. server.AddXmlRPCHandler("verify_client", VerifyClient, false);
  67. server.AddXmlRPCHandler("logout_agent", LogoutAgent, false);
  68. server.AddHTTPHandler("/homeagent/", new HomeAgentHandler(m_HomeUsersService, loginServerIP).Handler);
  69. }
  70. public XmlRpcResponse GetHomeRegion(XmlRpcRequest request, IPEndPoint remoteClient)
  71. {
  72. Hashtable requestData = (Hashtable)request.Params[0];
  73. //string host = (string)requestData["host"];
  74. //string portstr = (string)requestData["port"];
  75. string userID_str = (string)requestData["userID"];
  76. UUID userID = UUID.Zero;
  77. UUID.TryParse(userID_str, out userID);
  78. Vector3 position = Vector3.UnitY, lookAt = Vector3.UnitY;
  79. GridRegion regInfo = m_HomeUsersService.GetHomeRegion(userID, out position, out lookAt);
  80. Hashtable hash = new Hashtable();
  81. if (regInfo == null)
  82. hash["result"] = "false";
  83. else
  84. {
  85. hash["result"] = "true";
  86. hash["uuid"] = regInfo.RegionID.ToString();
  87. hash["x"] = regInfo.RegionLocX.ToString();
  88. hash["y"] = regInfo.RegionLocY.ToString();
  89. hash["region_name"] = regInfo.RegionName;
  90. hash["hostname"] = regInfo.ExternalHostName;
  91. hash["http_port"] = regInfo.HttpPort.ToString();
  92. hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString();
  93. hash["position"] = position.ToString();
  94. hash["lookAt"] = lookAt.ToString();
  95. }
  96. XmlRpcResponse response = new XmlRpcResponse();
  97. response.Value = hash;
  98. return response;
  99. }
  100. public XmlRpcResponse AgentIsComingHome(XmlRpcRequest request, IPEndPoint remoteClient)
  101. {
  102. Hashtable requestData = (Hashtable)request.Params[0];
  103. //string host = (string)requestData["host"];
  104. //string portstr = (string)requestData["port"];
  105. string sessionID_str = (string)requestData["sessionID"];
  106. UUID sessionID = UUID.Zero;
  107. UUID.TryParse(sessionID_str, out sessionID);
  108. string gridName = (string)requestData["externalName"];
  109. bool success = m_HomeUsersService.AgentIsComingHome(sessionID, gridName);
  110. Hashtable hash = new Hashtable();
  111. hash["result"] = success.ToString();
  112. XmlRpcResponse response = new XmlRpcResponse();
  113. response.Value = hash;
  114. return response;
  115. }
  116. public XmlRpcResponse VerifyAgent(XmlRpcRequest request, IPEndPoint remoteClient)
  117. {
  118. Hashtable requestData = (Hashtable)request.Params[0];
  119. //string host = (string)requestData["host"];
  120. //string portstr = (string)requestData["port"];
  121. string sessionID_str = (string)requestData["sessionID"];
  122. UUID sessionID = UUID.Zero;
  123. UUID.TryParse(sessionID_str, out sessionID);
  124. string token = (string)requestData["token"];
  125. bool success = m_HomeUsersService.VerifyAgent(sessionID, token);
  126. Hashtable hash = new Hashtable();
  127. hash["result"] = success.ToString();
  128. XmlRpcResponse response = new XmlRpcResponse();
  129. response.Value = hash;
  130. return response;
  131. }
  132. public XmlRpcResponse VerifyClient(XmlRpcRequest request, IPEndPoint remoteClient)
  133. {
  134. Hashtable requestData = (Hashtable)request.Params[0];
  135. //string host = (string)requestData["host"];
  136. //string portstr = (string)requestData["port"];
  137. string sessionID_str = (string)requestData["sessionID"];
  138. UUID sessionID = UUID.Zero;
  139. UUID.TryParse(sessionID_str, out sessionID);
  140. string token = (string)requestData["token"];
  141. bool success = m_HomeUsersService.VerifyClient(sessionID, token);
  142. Hashtable hash = new Hashtable();
  143. hash["result"] = success.ToString();
  144. XmlRpcResponse response = new XmlRpcResponse();
  145. response.Value = hash;
  146. return response;
  147. }
  148. public XmlRpcResponse LogoutAgent(XmlRpcRequest request, IPEndPoint remoteClient)
  149. {
  150. Hashtable requestData = (Hashtable)request.Params[0];
  151. //string host = (string)requestData["host"];
  152. //string portstr = (string)requestData["port"];
  153. string sessionID_str = (string)requestData["sessionID"];
  154. UUID sessionID = UUID.Zero;
  155. UUID.TryParse(sessionID_str, out sessionID);
  156. string userID_str = (string)requestData["userID"];
  157. UUID userID = UUID.Zero;
  158. UUID.TryParse(userID_str, out userID);
  159. m_HomeUsersService.LogoutAgent(userID, sessionID);
  160. Hashtable hash = new Hashtable();
  161. hash["result"] = "true";
  162. XmlRpcResponse response = new XmlRpcResponse();
  163. response.Value = hash;
  164. return response;
  165. }
  166. }
  167. }