CommunicationsManager.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 IGridServices GridService
  57. {
  58. get { return m_gridService; }
  59. }
  60. protected IGridServices m_gridService;
  61. public UserProfileCacheService UserProfileCacheService
  62. {
  63. get { return m_userProfileCacheService; }
  64. }
  65. protected UserProfileCacheService m_userProfileCacheService;
  66. public IAvatarService AvatarService
  67. {
  68. get { return m_avatarService; }
  69. }
  70. protected IAvatarService m_avatarService;
  71. public IInterServiceInventoryServices InterServiceInventoryService
  72. {
  73. get { return m_interServiceInventoryService; }
  74. }
  75. protected IInterServiceInventoryServices m_interServiceInventoryService;
  76. public NetworkServersInfo NetworkServersInfo
  77. {
  78. get { return m_networkServersInfo; }
  79. }
  80. protected NetworkServersInfo m_networkServersInfo;
  81. /// <summary>
  82. /// Interface to user service for administrating users.
  83. /// </summary>
  84. public IUserAdminService UserAdminService
  85. {
  86. get { return m_userAdminService; }
  87. }
  88. protected IUserAdminService m_userAdminService;
  89. /// <summary>
  90. /// Constructor
  91. /// </summary>
  92. /// <param name="serversInfo"></param>
  93. public CommunicationsManager(NetworkServersInfo serversInfo,
  94. LibraryRootFolder libraryRootFolder)
  95. {
  96. m_networkServersInfo = serversInfo;
  97. m_userProfileCacheService = new UserProfileCacheService(this, libraryRootFolder);
  98. }
  99. #region Friend Methods
  100. /// <summary>
  101. /// Adds a new friend to the database for XUser
  102. /// </summary>
  103. /// <param name="friendlistowner">The agent that who's friends list is being added to</param>
  104. /// <param name="friend">The agent that being added to the friends list of the friends list owner</param>
  105. /// <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>
  106. public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
  107. {
  108. m_userService.AddNewUserFriend(friendlistowner, friend, perms);
  109. }
  110. /// <summary>
  111. /// Logs off a user and does the appropriate communications
  112. /// </summary>
  113. /// <param name="userid"></param>
  114. /// <param name="regionid"></param>
  115. /// <param name="regionhandle"></param>
  116. /// <param name="position"></param>
  117. /// <param name="lookat"></param>
  118. public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, Vector3 position, Vector3 lookat)
  119. {
  120. m_userService.LogOffUser(userid, regionid, regionhandle, position, lookat);
  121. }
  122. /// <summary>
  123. /// Logs off a user and does the appropriate communications (deprecated as of 2008-08-27)
  124. /// </summary>
  125. /// <param name="userid"></param>
  126. /// <param name="regionid"></param>
  127. /// <param name="regionhandle"></param>
  128. /// <param name="posx"></param>
  129. /// <param name="posy"></param>
  130. /// <param name="posz"></param>
  131. public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, float posx, float posy, float posz)
  132. {
  133. m_userService.LogOffUser(userid, regionid, regionhandle, posx, posy, posz);
  134. }
  135. /// <summary>
  136. /// Delete friend on friendlistowner's friendlist.
  137. /// </summary>
  138. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  139. /// <param name="friend">The Ex-friend agent</param>
  140. public void RemoveUserFriend(UUID friendlistowner, UUID friend)
  141. {
  142. m_userService.RemoveUserFriend(friendlistowner, friend);
  143. }
  144. /// <summary>
  145. /// Update permissions for friend on friendlistowner's friendlist.
  146. /// </summary>
  147. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  148. /// <param name="friend">The agent that is getting or loosing permissions</param>
  149. /// <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>
  150. public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
  151. {
  152. m_userService.UpdateUserFriendPerms(friendlistowner, friend, perms);
  153. }
  154. /// <summary>
  155. /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for UUID friendslistowner
  156. /// </summary>
  157. /// <param name="friendlistowner">The agent that we're retreiving the friends Data.</param>
  158. public List<FriendListItem> GetUserFriendList(UUID friendlistowner)
  159. {
  160. return m_userService.GetUserFriendList(friendlistowner);
  161. }
  162. public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids)
  163. {
  164. return m_messageService.GetFriendRegionInfos(uuids);
  165. }
  166. #endregion
  167. #region Packet Handlers
  168. public void UpdateAvatarPropertiesRequest(IClientAPI remote_client, UserProfileData UserProfile)
  169. {
  170. m_userService.UpdateUserProfile(UserProfile);
  171. return;
  172. }
  173. public void HandleUUIDNameRequest(UUID uuid, IClientAPI remote_client)
  174. {
  175. if (uuid == m_userProfileCacheService.LibraryRoot.Owner)
  176. {
  177. remote_client.SendNameReply(uuid, "Mr", "OpenSim");
  178. }
  179. else
  180. {
  181. string[] names = doUUIDNameRequest(uuid);
  182. if (names.Length == 2)
  183. {
  184. remote_client.SendNameReply(uuid, names[0], names[1]);
  185. }
  186. }
  187. }
  188. private string[] doUUIDNameRequest(UUID uuid)
  189. {
  190. string[] returnstring = new string[0];
  191. bool doLookup = false;
  192. lock (m_nameRequestCache)
  193. {
  194. if (m_nameRequestCache.ContainsKey(uuid))
  195. {
  196. returnstring = m_nameRequestCache[uuid];
  197. }
  198. else
  199. {
  200. // we don't want to lock the dictionary while we're doing the lookup
  201. doLookup = true;
  202. }
  203. }
  204. if (doLookup) {
  205. UserProfileData profileData = m_userService.GetUserProfile(uuid);
  206. if (profileData != null)
  207. {
  208. returnstring = new string[2];
  209. // UUID profileId = profileData.ID;
  210. returnstring[0] = profileData.FirstName;
  211. returnstring[1] = profileData.SurName;
  212. lock (m_nameRequestCache)
  213. {
  214. if (!m_nameRequestCache.ContainsKey(uuid))
  215. m_nameRequestCache.Add(uuid, returnstring);
  216. }
  217. }
  218. }
  219. return returnstring;
  220. }
  221. public bool UUIDNameCachedTest(UUID uuid)
  222. {
  223. lock (m_nameRequestCache)
  224. return m_nameRequestCache.ContainsKey(uuid);
  225. }
  226. public string UUIDNameRequestString(UUID uuid)
  227. {
  228. string[] names = doUUIDNameRequest(uuid);
  229. if (names.Length == 2)
  230. {
  231. string firstname = names[0];
  232. string lastname = names[1];
  233. return firstname + " " + lastname;
  234. }
  235. return "(hippos)";
  236. }
  237. public List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(UUID queryID, string query)
  238. {
  239. List<AvatarPickerAvatar> pickerlist = m_userService.GenerateAgentPickerRequestResponse(queryID, query);
  240. return pickerlist;
  241. }
  242. #endregion
  243. }
  244. }