UserLoginAuthService.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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.Reflection;
  31. using System.Text.RegularExpressions;
  32. using log4net;
  33. using Nwc.XmlRpc;
  34. using OpenMetaverse;
  35. using OpenSim.Data;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Communications;
  38. using OpenSim.Framework.Communications.Services;
  39. using OpenSim.Framework.Communications.Cache;
  40. using OpenSim.Framework.Capabilities;
  41. using OpenSim.Framework.Servers;
  42. using OpenSim.Framework.Servers.HttpServer;
  43. namespace OpenSim.Grid.UserServer.Modules
  44. {
  45. /// <summary>
  46. /// Hypergrid login service used in grid mode.
  47. /// </summary>
  48. public class UserLoginAuthService : HGLoginAuthService
  49. {
  50. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  51. public UserConfig m_config;
  52. private readonly IRegionProfileRouter m_regionProfileService;
  53. protected BaseHttpServer m_httpServer;
  54. public UserLoginAuthService(
  55. UserManagerBase userManager, IInterServiceInventoryServices inventoryService,
  56. LibraryRootFolder libraryRootFolder,
  57. UserConfig config, string welcomeMess, IRegionProfileRouter regionProfileService)
  58. : base(userManager, welcomeMess, inventoryService, null, true, libraryRootFolder, null)
  59. {
  60. m_config = config;
  61. m_defaultHomeX = m_config.DefaultX;
  62. m_defaultHomeY = m_config.DefaultY;
  63. m_interInventoryService = inventoryService;
  64. m_regionProfileService = regionProfileService;
  65. NetworkServersInfo serversinfo = new NetworkServersInfo(1000, 1000);
  66. serversinfo.GridRecvKey = m_config.GridRecvKey;
  67. serversinfo.GridSendKey = m_config.GridSendKey;
  68. serversinfo.GridURL = m_config.GridServerURL.ToString();
  69. serversinfo.InventoryURL = m_config.InventoryUrl.ToString();
  70. serversinfo.UserURL = m_config.AuthUrl.ToString();
  71. SetServersInfo(serversinfo);
  72. }
  73. public void RegisterHandlers(BaseHttpServer httpServer)
  74. {
  75. m_httpServer = httpServer;
  76. httpServer.AddXmlRPCHandler("hg_login", XmlRpcLoginMethod);
  77. httpServer.AddXmlRPCHandler("hg_new_auth_key", XmlRpcGenerateKeyMethod);
  78. httpServer.AddXmlRPCHandler("hg_verify_auth_key", XmlRpcVerifyKeyMethod);
  79. }
  80. public override void LogOffUser(UserProfileData theUser, string message)
  81. {
  82. RegionProfileData SimInfo;
  83. try
  84. {
  85. SimInfo = m_regionProfileService.RequestSimProfileData(
  86. theUser.CurrentAgent.Handle, m_config.GridServerURL,
  87. m_config.GridSendKey, m_config.GridRecvKey);
  88. if (SimInfo == null)
  89. {
  90. m_log.Error("[GRID]: Region user was in isn't currently logged in");
  91. return;
  92. }
  93. }
  94. catch (Exception)
  95. {
  96. m_log.Error("[GRID]: Unable to look up region to log user off");
  97. return;
  98. }
  99. // Prepare notification
  100. Hashtable SimParams = new Hashtable();
  101. SimParams["agent_id"] = theUser.ID.ToString();
  102. SimParams["region_secret"] = theUser.CurrentAgent.SecureSessionID.ToString();
  103. SimParams["region_secret2"] = SimInfo.regionSecret;
  104. //m_log.Info(SimInfo.regionSecret);
  105. SimParams["regionhandle"] = theUser.CurrentAgent.Handle.ToString();
  106. SimParams["message"] = message;
  107. ArrayList SendParams = new ArrayList();
  108. SendParams.Add(SimParams);
  109. m_log.InfoFormat(
  110. "[ASSUMED CRASH]: Telling region {0} @ {1},{2} ({3}) that their agent is dead: {4}",
  111. SimInfo.regionName, SimInfo.regionLocX, SimInfo.regionLocY, SimInfo.httpServerURI,
  112. theUser.FirstName + " " + theUser.SurName);
  113. try
  114. {
  115. XmlRpcRequest GridReq = new XmlRpcRequest("logoff_user", SendParams);
  116. XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000);
  117. if (GridResp.IsFault)
  118. {
  119. m_log.ErrorFormat(
  120. "[LOGIN]: XMLRPC request for {0} failed, fault code: {1}, reason: {2}, This is likely an old region revision.",
  121. SimInfo.httpServerURI, GridResp.FaultCode, GridResp.FaultString);
  122. }
  123. }
  124. catch (Exception)
  125. {
  126. m_log.Error("[LOGIN]: Error telling region to logout user!");
  127. }
  128. // Prepare notification
  129. SimParams = new Hashtable();
  130. SimParams["agent_id"] = theUser.ID.ToString();
  131. SimParams["region_secret"] = SimInfo.regionSecret;
  132. //m_log.Info(SimInfo.regionSecret);
  133. SimParams["regionhandle"] = theUser.CurrentAgent.Handle.ToString();
  134. SimParams["message"] = message;
  135. SendParams = new ArrayList();
  136. SendParams.Add(SimParams);
  137. m_log.InfoFormat(
  138. "[ASSUMED CRASH]: Telling region {0} @ {1},{2} ({3}) that their agent is dead: {4}",
  139. SimInfo.regionName, SimInfo.regionLocX, SimInfo.regionLocY, SimInfo.httpServerURI,
  140. theUser.FirstName + " " + theUser.SurName);
  141. try
  142. {
  143. XmlRpcRequest GridReq = new XmlRpcRequest("logoff_user", SendParams);
  144. XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000);
  145. if (GridResp.IsFault)
  146. {
  147. m_log.ErrorFormat(
  148. "[LOGIN]: XMLRPC request for {0} failed, fault code: {1}, reason: {2}, This is likely an old region revision.",
  149. SimInfo.httpServerURI, GridResp.FaultCode, GridResp.FaultString);
  150. }
  151. }
  152. catch (Exception)
  153. {
  154. m_log.Error("[LOGIN]: Error telling region to logout user!");
  155. }
  156. //base.LogOffUser(theUser);
  157. }
  158. protected override RegionInfo RequestClosestRegion(string region)
  159. {
  160. RegionProfileData profileData = m_regionProfileService.RequestSimProfileData(region,
  161. m_config.GridServerURL, m_config.GridSendKey, m_config.GridRecvKey);
  162. if (profileData != null)
  163. {
  164. return profileData.ToRegionInfo();
  165. }
  166. else
  167. {
  168. return null;
  169. }
  170. }
  171. protected override RegionInfo GetRegionInfo(ulong homeRegionHandle)
  172. {
  173. RegionProfileData profileData = m_regionProfileService.RequestSimProfileData(homeRegionHandle,
  174. m_config.GridServerURL, m_config.GridSendKey,
  175. m_config.GridRecvKey);
  176. if (profileData != null)
  177. {
  178. return profileData.ToRegionInfo();
  179. }
  180. else
  181. {
  182. return null;
  183. }
  184. }
  185. protected override RegionInfo GetRegionInfo(UUID homeRegionId)
  186. {
  187. RegionProfileData profileData = m_regionProfileService.RequestSimProfileData(homeRegionId,
  188. m_config.GridServerURL, m_config.GridSendKey,
  189. m_config.GridRecvKey);
  190. if (profileData != null)
  191. {
  192. return profileData.ToRegionInfo();
  193. }
  194. else
  195. {
  196. return null;
  197. }
  198. }
  199. }
  200. }