CommunicationsManager.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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.Generic;
  29. using OpenMetaverse;
  30. using OpenSim.Framework.Communications.Cache;
  31. namespace OpenSim.Framework.Communications
  32. {
  33. /// <summary>
  34. /// This class manages references to OpenSim non-region services (inventory, user, etc.)
  35. /// </summary>
  36. ///
  37. /// TODO: Service retrieval needs to be managed via plugin and interfaces requests, as happens for region
  38. /// modules from scene. Among other things, this will allow this class to be used in many different contexts
  39. /// (from a grid service executable, to provide services on a region) without lots of messy nulls and confusion.
  40. /// Also, a post initialize step on the plugins will be needed so that we don't get tortuous problems with
  41. /// circular dependencies between plugins.
  42. public class CommunicationsManager
  43. {
  44. //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  45. protected Dictionary<UUID, string[]> m_nameRequestCache = new Dictionary<UUID, string[]>();
  46. public IUserService UserService
  47. {
  48. get { return m_userService; }
  49. }
  50. protected IUserService m_userService;
  51. public IMessagingService MessageService
  52. {
  53. get { return m_messageService; }
  54. }
  55. protected IMessagingService m_messageService;
  56. public UserProfileCacheService UserProfileCacheService
  57. {
  58. get { return m_userProfileCacheService; }
  59. }
  60. protected UserProfileCacheService m_userProfileCacheService;
  61. public IAvatarService AvatarService
  62. {
  63. get { return m_avatarService; }
  64. }
  65. protected IAvatarService m_avatarService;
  66. public IInterServiceInventoryServices InterServiceInventoryService
  67. {
  68. get { return m_interServiceInventoryService; }
  69. }
  70. protected IInterServiceInventoryServices m_interServiceInventoryService;
  71. public NetworkServersInfo NetworkServersInfo
  72. {
  73. get { return m_networkServersInfo; }
  74. }
  75. protected NetworkServersInfo m_networkServersInfo;
  76. /// <summary>
  77. /// Interface to user service for administrating users.
  78. /// </summary>
  79. public IUserAdminService UserAdminService
  80. {
  81. get { return m_userAdminService; }
  82. }
  83. protected IUserAdminService m_userAdminService;
  84. /// <summary>
  85. /// Constructor
  86. /// </summary>
  87. /// <param name="serversInfo"></param>
  88. public CommunicationsManager(NetworkServersInfo serversInfo,
  89. LibraryRootFolder libraryRootFolder)
  90. {
  91. m_networkServersInfo = serversInfo;
  92. m_userProfileCacheService = new UserProfileCacheService(this, libraryRootFolder);
  93. }
  94. #region Friend Methods
  95. /// <summary>
  96. /// Adds a new friend to the database for XUser
  97. /// </summary>
  98. /// <param name="friendlistowner">The agent that who's friends list is being added to</param>
  99. /// <param name="friend">The agent that being added to the friends list of the friends list owner</param>
  100. /// <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>
  101. public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
  102. {
  103. m_userService.AddNewUserFriend(friendlistowner, friend, perms);
  104. }
  105. /// <summary>
  106. /// Logs off a user and does the appropriate communications
  107. /// </summary>
  108. /// <param name="userid"></param>
  109. /// <param name="regionid"></param>
  110. /// <param name="regionhandle"></param>
  111. /// <param name="position"></param>
  112. /// <param name="lookat"></param>
  113. public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, Vector3 position, Vector3 lookat)
  114. {
  115. m_userService.LogOffUser(userid, regionid, regionhandle, position, lookat);
  116. }
  117. /// <summary>
  118. /// Logs off a user and does the appropriate communications (deprecated as of 2008-08-27)
  119. /// </summary>
  120. /// <param name="userid"></param>
  121. /// <param name="regionid"></param>
  122. /// <param name="regionhandle"></param>
  123. /// <param name="posx"></param>
  124. /// <param name="posy"></param>
  125. /// <param name="posz"></param>
  126. public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, float posx, float posy, float posz)
  127. {
  128. m_userService.LogOffUser(userid, regionid, regionhandle, posx, posy, posz);
  129. }
  130. /// <summary>
  131. /// Delete friend on friendlistowner's friendlist.
  132. /// </summary>
  133. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  134. /// <param name="friend">The Ex-friend agent</param>
  135. public void RemoveUserFriend(UUID friendlistowner, UUID friend)
  136. {
  137. m_userService.RemoveUserFriend(friendlistowner, friend);
  138. }
  139. /// <summary>
  140. /// Update permissions for friend on friendlistowner's friendlist.
  141. /// </summary>
  142. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  143. /// <param name="friend">The agent that is getting or loosing permissions</param>
  144. /// <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>
  145. public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
  146. {
  147. m_userService.UpdateUserFriendPerms(friendlistowner, friend, perms);
  148. }
  149. /// <summary>
  150. /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for UUID friendslistowner
  151. /// </summary>
  152. /// <param name="friendlistowner">The agent that we're retreiving the friends Data.</param>
  153. public List<FriendListItem> GetUserFriendList(UUID friendlistowner)
  154. {
  155. return m_userService.GetUserFriendList(friendlistowner);
  156. }
  157. public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids)
  158. {
  159. return m_messageService.GetFriendRegionInfos(uuids);
  160. }
  161. #endregion
  162. #region Packet Handlers
  163. public void UpdateAvatarPropertiesRequest(IClientAPI remote_client, UserProfileData UserProfile)
  164. {
  165. m_userService.UpdateUserProfile(UserProfile);
  166. return;
  167. }
  168. public void HandleUUIDNameRequest(UUID uuid, IClientAPI remote_client)
  169. {
  170. if (uuid == m_userProfileCacheService.LibraryRoot.Owner)
  171. {
  172. remote_client.SendNameReply(uuid, "Mr", "OpenSim");
  173. }
  174. else
  175. {
  176. string[] names = doUUIDNameRequest(uuid);
  177. if (names.Length == 2)
  178. {
  179. remote_client.SendNameReply(uuid, names[0], names[1]);
  180. }
  181. }
  182. }
  183. private string[] doUUIDNameRequest(UUID uuid)
  184. {
  185. lock (m_nameRequestCache)
  186. {
  187. if (m_nameRequestCache.ContainsKey(uuid))
  188. return m_nameRequestCache[uuid];
  189. }
  190. string[] returnstring = new string[0];
  191. CachedUserInfo uinfo = UserProfileCacheService.GetUserDetails(uuid);
  192. if ((uinfo != null) && (uinfo.UserProfile != null))
  193. {
  194. returnstring = new string[2];
  195. returnstring[0] = uinfo.UserProfile.FirstName;
  196. returnstring[1] = uinfo.UserProfile.SurName;
  197. lock (m_nameRequestCache)
  198. {
  199. if (!m_nameRequestCache.ContainsKey(uuid))
  200. m_nameRequestCache.Add(uuid, returnstring);
  201. }
  202. }
  203. return returnstring;
  204. }
  205. public bool UUIDNameCachedTest(UUID uuid)
  206. {
  207. lock (m_nameRequestCache)
  208. return m_nameRequestCache.ContainsKey(uuid);
  209. }
  210. public string UUIDNameRequestString(UUID uuid)
  211. {
  212. string[] names = doUUIDNameRequest(uuid);
  213. if (names.Length == 2)
  214. {
  215. string firstname = names[0];
  216. string lastname = names[1];
  217. return firstname + " " + lastname;
  218. }
  219. return "(hippos)";
  220. }
  221. public List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(UUID queryID, string query)
  222. {
  223. List<AvatarPickerAvatar> pickerlist = m_userService.GenerateAgentPickerRequestResponse(queryID, query);
  224. return pickerlist;
  225. }
  226. #endregion
  227. }
  228. }