OGS1UserServices.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 System.Text.RegularExpressions;
  33. using System.Xml.Serialization;
  34. using log4net;
  35. using Nwc.XmlRpc;
  36. using OpenMetaverse;
  37. using OpenSim.Data;
  38. using OpenSim.Framework;
  39. using OpenSim.Framework.Communications;
  40. using OpenSim.Framework.Communications.Clients;
  41. namespace OpenSim.Region.Communications.OGS1
  42. {
  43. public class OGS1UserServices : UserManagerBase
  44. {
  45. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  46. public OGS1UserServices(CommunicationsManager commsManager)
  47. : base(commsManager)
  48. {
  49. }
  50. public override void ClearUserAgent(UUID avatarID)
  51. {
  52. // TODO: implement
  53. // It may be possible to use the UserManagerBase implementation.
  54. }
  55. protected virtual string GetUserServerURL(UUID userID)
  56. {
  57. return m_commsManager.NetworkServersInfo.UserURL;
  58. }
  59. /// <summary>
  60. /// Logs off a user on the user server
  61. /// </summary>
  62. /// <param name="UserID">UUID of the user</param>
  63. /// <param name="regionID">UUID of the Region</param>
  64. /// <param name="regionhandle">regionhandle</param>
  65. /// <param name="position">final position</param>
  66. /// <param name="lookat">final lookat</param>
  67. public override void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, Vector3 position, Vector3 lookat)
  68. {
  69. Hashtable param = new Hashtable();
  70. param["avatar_uuid"] = userid.Guid.ToString();
  71. param["region_uuid"] = regionid.Guid.ToString();
  72. param["region_handle"] = regionhandle.ToString();
  73. param["region_pos_x"] = position.X.ToString();
  74. param["region_pos_y"] = position.Y.ToString();
  75. param["region_pos_z"] = position.Z.ToString();
  76. param["lookat_x"] = lookat.X.ToString();
  77. param["lookat_y"] = lookat.Y.ToString();
  78. param["lookat_z"] = lookat.Z.ToString();
  79. IList parameters = new ArrayList();
  80. parameters.Add(param);
  81. XmlRpcRequest req = new XmlRpcRequest("logout_of_simulator", parameters);
  82. try
  83. {
  84. req.Send(GetUserServerURL(userid), 3000);
  85. }
  86. catch (WebException)
  87. {
  88. m_log.Warn("[LOGOFF]: Unable to notify grid server of user logoff");
  89. }
  90. }
  91. /// <summary>
  92. /// Retrieve the user information for the given master uuid.
  93. /// </summary>
  94. /// <param name="uuid"></param>
  95. /// <returns></returns>
  96. public override UserProfileData SetupMasterUser(string firstName, string lastName)
  97. {
  98. return SetupMasterUser(firstName, lastName, String.Empty);
  99. }
  100. /// <summary>
  101. /// Retrieve the user information for the given master uuid.
  102. /// </summary>
  103. /// <param name="uuid"></param>
  104. /// <returns></returns>
  105. public override UserProfileData SetupMasterUser(string firstName, string lastName, string password)
  106. {
  107. UserProfileData profile = GetUserProfile(firstName, lastName);
  108. return profile;
  109. }
  110. /// <summary>
  111. /// Retrieve the user information for the given master uuid.
  112. /// </summary>
  113. /// <param name="uuid"></param>
  114. /// <returns></returns>
  115. public override UserProfileData SetupMasterUser(UUID uuid)
  116. {
  117. UserProfileData data = GetUserProfile(uuid);
  118. if (data == null)
  119. {
  120. throw new Exception(
  121. "Could not retrieve profile for master user " + uuid + ". User server did not respond to the request.");
  122. }
  123. return data;
  124. }
  125. public override bool VerifySession(UUID userID, UUID sessionID)
  126. {
  127. m_log.DebugFormat("[OGS1 USER SERVICES]: Verifying user session for " + userID);
  128. return AuthClient.VerifySession(GetUserServerURL(userID), userID, sessionID);
  129. }
  130. public override bool AuthenticateUserByPassword(UUID userID, string password)
  131. {
  132. Hashtable param = new Hashtable();
  133. param["user_uuid"] = userID.ToString();
  134. param["password"] = password;
  135. IList parameters = new ArrayList();
  136. parameters.Add(param);
  137. XmlRpcRequest req = new XmlRpcRequest("authenticate_user_by_password", parameters);
  138. XmlRpcResponse resp = req.Send(m_commsManager.NetworkServersInfo.UserURL, 30000);
  139. // Temporary measure to deal with older services
  140. if (resp.IsFault && resp.FaultCode == XmlRpcErrorCodes.SERVER_ERROR_METHOD)
  141. {
  142. throw new Exception(
  143. String.Format(
  144. "XMLRPC method 'authenticate_user_by_password' not yet implemented by user service at {0}",
  145. m_commsManager.NetworkServersInfo.UserURL));
  146. }
  147. Hashtable respData = (Hashtable)resp.Value;
  148. if ((string)respData["auth_user"] == "TRUE")
  149. {
  150. return true;
  151. }
  152. else
  153. {
  154. return false;
  155. }
  156. }
  157. }
  158. }