HGUserServices.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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 OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Framework.Communications;
  33. using OpenSim.Framework.Communications.Cache;
  34. using OpenSim.Framework.Communications.Clients;
  35. using OpenSim.Region.Communications.OGS1;
  36. using OpenSim.Region.Communications.Local;
  37. using OpenSim.Services.Interfaces;
  38. namespace OpenSim.Region.Communications.Hypergrid
  39. {
  40. /// <summary>
  41. /// For the time being, this class is just an identity wrapper around OGS1UserServices,
  42. /// so it always fails for foreign users.
  43. /// Later it needs to talk with the foreign users' user servers.
  44. /// </summary>
  45. public class HGUserServices : OGS1UserServices
  46. {
  47. //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. //private OGS1UserServices m_remoteUserServices;
  49. private LocalUserServices m_localUserServices;
  50. // Constructor called when running in grid mode
  51. public HGUserServices(CommunicationsManager commsManager)
  52. : base(commsManager)
  53. {
  54. }
  55. // Constructor called when running in standalone
  56. public HGUserServices(CommunicationsManager commsManager, LocalUserServices local)
  57. : base(commsManager)
  58. {
  59. m_localUserServices = local;
  60. }
  61. public override void SetInventoryService(IInventoryService invService)
  62. {
  63. base.SetInventoryService(invService);
  64. if (m_localUserServices != null)
  65. m_localUserServices.SetInventoryService(invService);
  66. }
  67. public override UUID AddUser(
  68. string firstName, string lastName, string password, string email, uint regX, uint regY, UUID uuid)
  69. {
  70. // Only valid to create users locally
  71. if (m_localUserServices != null)
  72. return m_localUserServices.AddUser(firstName, lastName, password, email, regX, regY, uuid);
  73. return UUID.Zero;
  74. }
  75. public override bool AddUserAgent(UserAgentData agentdata)
  76. {
  77. if (m_localUserServices != null)
  78. return m_localUserServices.AddUserAgent(agentdata);
  79. return base.AddUserAgent(agentdata);
  80. }
  81. public override UserAgentData GetAgentByUUID(UUID userId)
  82. {
  83. string url = string.Empty;
  84. if ((m_localUserServices != null) && !IsForeignUser(userId, out url))
  85. return m_localUserServices.GetAgentByUUID(userId);
  86. return base.GetAgentByUUID(userId);
  87. }
  88. public override void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, Vector3 position, Vector3 lookat)
  89. {
  90. string url = string.Empty;
  91. if ((m_localUserServices != null) && !IsForeignUser(userid, out url))
  92. m_localUserServices.LogOffUser(userid, regionid, regionhandle, position, lookat);
  93. else
  94. base.LogOffUser(userid, regionid, regionhandle, position, lookat);
  95. }
  96. public override UserProfileData GetUserProfile(string firstName, string lastName)
  97. {
  98. if (m_localUserServices != null)
  99. return m_localUserServices.GetUserProfile(firstName, lastName);
  100. return base.GetUserProfile(firstName, lastName);
  101. }
  102. public override List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(UUID queryID, string query)
  103. {
  104. if (m_localUserServices != null)
  105. return m_localUserServices.GenerateAgentPickerRequestResponse(queryID, query);
  106. return base.GenerateAgentPickerRequestResponse(queryID, query);
  107. }
  108. /// <summary>
  109. /// Get a user profile from the user server
  110. /// </summary>
  111. /// <param name="avatarID"></param>
  112. /// <returns>null if the request fails</returns>
  113. public override UserProfileData GetUserProfile(UUID avatarID)
  114. {
  115. //string url = string.Empty;
  116. // Unfortunately we can't query for foreigners here,
  117. // because we'll end up in an infinite loop...
  118. //if ((m_localUserServices != null) && (!IsForeignUser(avatarID, out url)))
  119. if (m_localUserServices != null)
  120. return m_localUserServices.GetUserProfile(avatarID);
  121. return base.GetUserProfile(avatarID);
  122. }
  123. public override void ClearUserAgent(UUID avatarID)
  124. {
  125. if (m_localUserServices != null)
  126. m_localUserServices.ClearUserAgent(avatarID);
  127. else
  128. base.ClearUserAgent(avatarID);
  129. }
  130. /// <summary>
  131. /// Retrieve the user information for the given master uuid.
  132. /// </summary>
  133. /// <param name="uuid"></param>
  134. /// <returns></returns>
  135. public override UserProfileData SetupMasterUser(string firstName, string lastName)
  136. {
  137. if (m_localUserServices != null)
  138. return m_localUserServices.SetupMasterUser(firstName, lastName);
  139. return base.SetupMasterUser(firstName, lastName);
  140. }
  141. /// <summary>
  142. /// Retrieve the user information for the given master uuid.
  143. /// </summary>
  144. /// <param name="uuid"></param>
  145. /// <returns></returns>
  146. public override UserProfileData SetupMasterUser(string firstName, string lastName, string password)
  147. {
  148. if (m_localUserServices != null)
  149. return m_localUserServices.SetupMasterUser(firstName, lastName, password);
  150. return base.SetupMasterUser(firstName, lastName, password);
  151. }
  152. /// <summary>
  153. /// Retrieve the user information for the given master uuid.
  154. /// </summary>
  155. /// <param name="uuid"></param>
  156. /// <returns></returns>
  157. public override UserProfileData SetupMasterUser(UUID uuid)
  158. {
  159. if (m_localUserServices != null)
  160. return m_localUserServices.SetupMasterUser(uuid);
  161. return base.SetupMasterUser(uuid);
  162. }
  163. public override bool ResetUserPassword(string firstName, string lastName, string newPassword)
  164. {
  165. if (m_localUserServices != null)
  166. return m_localUserServices.ResetUserPassword(firstName, lastName, newPassword);
  167. else
  168. return base.ResetUserPassword(firstName, lastName, newPassword);
  169. }
  170. public override bool UpdateUserProfile(UserProfileData userProfile)
  171. {
  172. string url = string.Empty;
  173. if ((m_localUserServices != null) && (!IsForeignUser(userProfile.ID, out url)))
  174. return m_localUserServices.UpdateUserProfile(userProfile);
  175. return base.UpdateUserProfile(userProfile);
  176. }
  177. #region IUserServices Friend Methods
  178. // NOTE: We're still not dealing with foreign user friends
  179. /// <summary>
  180. /// Adds a new friend to the database for XUser
  181. /// </summary>
  182. /// <param name="friendlistowner">The agent that who's friends list is being added to</param>
  183. /// <param name="friend">The agent that being added to the friends list of the friends list owner</param>
  184. /// <param name="perms">A uint bit vector for set perms that the friend being added has; 0 = none, 1=This friend can see when they sign on, 2 = map, 4 edit objects </param>
  185. public override void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
  186. {
  187. if (m_localUserServices != null)
  188. m_localUserServices.AddNewUserFriend(friendlistowner, friend, perms);
  189. else
  190. base.AddNewUserFriend(friendlistowner, friend, perms);
  191. }
  192. /// <summary>
  193. /// Delete friend on friendlistowner's friendlist.
  194. /// </summary>
  195. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  196. /// <param name="friend">The Ex-friend agent</param>
  197. public override void RemoveUserFriend(UUID friendlistowner, UUID friend)
  198. {
  199. if (m_localUserServices != null)
  200. m_localUserServices.RemoveUserFriend(friendlistowner, friend);
  201. else
  202. base.RemoveUserFriend(friend, friend);
  203. }
  204. /// <summary>
  205. /// Update permissions for friend on friendlistowner's friendlist.
  206. /// </summary>
  207. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  208. /// <param name="friend">The agent that is getting or loosing permissions</param>
  209. /// <param name="perms">A uint bit vector for set perms that the friend being added has; 0 = none, 1=This friend can see when they sign on, 2 = map, 4 edit objects </param>
  210. public override void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
  211. {
  212. if (m_localUserServices != null)
  213. m_localUserServices.UpdateUserFriendPerms(friendlistowner, friend, perms);
  214. else
  215. base.UpdateUserFriendPerms(friendlistowner, friend, perms);
  216. }
  217. /// <summary>
  218. /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for UUID friendslistowner
  219. /// </summary>
  220. /// <param name="friendlistowner">The agent that we're retreiving the friends Data.</param>
  221. public override List<FriendListItem> GetUserFriendList(UUID friendlistowner)
  222. {
  223. if (m_localUserServices != null)
  224. return m_localUserServices.GetUserFriendList(friendlistowner);
  225. return base.GetUserFriendList(friendlistowner);
  226. }
  227. #endregion
  228. /// Appearance
  229. public override AvatarAppearance GetUserAppearance(UUID user)
  230. {
  231. string url = string.Empty;
  232. if ((m_localUserServices != null) && (!IsForeignUser(user, out url)))
  233. return m_localUserServices.GetUserAppearance(user);
  234. else
  235. return base.GetUserAppearance(user);
  236. }
  237. public override void UpdateUserAppearance(UUID user, AvatarAppearance appearance)
  238. {
  239. string url = string.Empty;
  240. if ((m_localUserServices != null) && (!IsForeignUser(user, out url)))
  241. m_localUserServices.UpdateUserAppearance(user, appearance);
  242. else
  243. base.UpdateUserAppearance(user, appearance);
  244. }
  245. #region IMessagingService
  246. public override Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids)
  247. {
  248. if (m_localUserServices != null)
  249. return m_localUserServices.GetFriendRegionInfos(uuids);
  250. return base.GetFriendRegionInfos(uuids);
  251. }
  252. #endregion
  253. public override bool VerifySession(UUID userID, UUID sessionID)
  254. {
  255. string url = string.Empty;
  256. if ((m_localUserServices != null) && (!IsForeignUser(userID, out url)))
  257. return m_localUserServices.VerifySession(userID, sessionID);
  258. else
  259. return base.VerifySession(userID, sessionID);
  260. }
  261. protected override string GetUserServerURL(UUID userID)
  262. {
  263. string serverURL = string.Empty;
  264. if (IsForeignUser(userID, out serverURL))
  265. return serverURL;
  266. return m_commsManager.NetworkServersInfo.UserURL;
  267. }
  268. private bool IsForeignUser(UUID userID, out string userServerURL)
  269. {
  270. userServerURL = string.Empty;
  271. CachedUserInfo uinfo = m_commsManager.UserProfileCacheService.GetUserDetails(userID);
  272. if (uinfo != null)
  273. {
  274. if (!HGNetworkServersInfo.Singleton.IsLocalUser(uinfo.UserProfile))
  275. {
  276. userServerURL = ((ForeignUserProfileData)(uinfo.UserProfile)).UserServerURI;
  277. return true;
  278. }
  279. }
  280. return false;
  281. }
  282. }
  283. }