UserAgentServerConnector.cs 8.4 KB

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