CommunicationsManager.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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 OpenSim 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.Collections.Generic;
  28. using OpenMetaverse;
  29. using OpenSim.Framework.Communications.Cache;
  30. using OpenSim.Framework.Servers;
  31. namespace OpenSim.Framework.Communications
  32. {
  33. /// <summary>
  34. /// This class manages references to OpenSim non-region services (asset, inventory, user, etc.)
  35. /// </summary>
  36. public class CommunicationsManager
  37. {
  38. //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  39. protected Dictionary<UUID, string[]> m_nameRequestCache = new Dictionary<UUID, string[]>();
  40. public IUserService UserService
  41. {
  42. get { return m_userService; }
  43. }
  44. protected IUserService m_userService;
  45. public IMessagingService MessageService
  46. {
  47. get { return m_messageService; }
  48. }
  49. protected IMessagingService m_messageService;
  50. public IGridServices GridService
  51. {
  52. get { return m_gridService; }
  53. }
  54. protected IGridServices m_gridService;
  55. public IInterRegionCommunications InterRegion
  56. {
  57. get { return m_interRegion; }
  58. }
  59. protected IInterRegionCommunications m_interRegion;
  60. public UserProfileCacheService UserProfileCacheService
  61. {
  62. get { return m_userProfileCacheService; }
  63. }
  64. protected UserProfileCacheService m_userProfileCacheService;
  65. // protected AgentAssetTransactionsManager m_transactionsManager;
  66. // public AgentAssetTransactionsManager TransactionsManager
  67. // {
  68. // get { return m_transactionsManager; }
  69. // }
  70. public IAvatarService AvatarService
  71. {
  72. get { return m_avatarService; }
  73. }
  74. protected IAvatarService m_avatarService;
  75. public IAssetCache AssetCache
  76. {
  77. get { return m_assetCache; }
  78. }
  79. protected IAssetCache m_assetCache;
  80. public IInterServiceInventoryServices InterServiceInventoryService
  81. {
  82. get { return m_interServiceInventoryService; }
  83. }
  84. protected IInterServiceInventoryServices m_interServiceInventoryService;
  85. public NetworkServersInfo NetworkServersInfo
  86. {
  87. get { return m_networkServersInfo; }
  88. }
  89. protected NetworkServersInfo m_networkServersInfo;
  90. /// <summary>
  91. /// Interface to user service for administrating users.
  92. /// </summary>
  93. public IUserAdminService UserAdminService
  94. {
  95. get { return m_userAdminService; }
  96. }
  97. protected IUserAdminService m_userAdminService;
  98. public BaseHttpServer HttpServer
  99. {
  100. get { return m_httpServer; }
  101. }
  102. protected BaseHttpServer m_httpServer;
  103. /// <summary>
  104. /// Constructor
  105. /// </summary>
  106. /// <param name="serversInfo"></param>
  107. /// <param name="httpServer"></param>
  108. /// <param name="assetCache"></param>
  109. /// <param name="dumpAssetsToFile"></param>
  110. public CommunicationsManager(NetworkServersInfo serversInfo, BaseHttpServer httpServer, IAssetCache assetCache,
  111. bool dumpAssetsToFile, LibraryRootFolder libraryRootFolder)
  112. {
  113. m_networkServersInfo = serversInfo;
  114. m_assetCache = assetCache;
  115. m_userProfileCacheService = new UserProfileCacheService(this, libraryRootFolder);
  116. m_httpServer = httpServer;
  117. // m_transactionsManager = new AgentAssetTransactionsManager(this, dumpAssetsToFile);
  118. }
  119. #region Inventory
  120. protected string m_defaultInventoryHost = "default";
  121. protected List<IInventoryServices> m_inventoryServices = new List<IInventoryServices>();
  122. // protected IInventoryServices m_inventoryService;
  123. protected List<ISecureInventoryService> m_secureinventoryServices = new List<ISecureInventoryService>();
  124. public ISecureInventoryService SecureInventoryService
  125. {
  126. get
  127. {
  128. if (m_secureinventoryServices.Count > 0)
  129. {
  130. // return m_inventoryServices[0];
  131. ISecureInventoryService invService;
  132. if (TryGetSecureInventoryService(m_defaultInventoryHost, out invService))
  133. {
  134. return invService;
  135. }
  136. }
  137. return null;
  138. }
  139. }
  140. public IInventoryServices InventoryService
  141. {
  142. get
  143. {
  144. if (m_inventoryServices.Count > 0)
  145. {
  146. // return m_inventoryServices[0];
  147. IInventoryServices invService;
  148. if (TryGetInventoryService(m_defaultInventoryHost, out invService))
  149. {
  150. return invService;
  151. }
  152. }
  153. return null;
  154. }
  155. }
  156. public bool TryGetSecureInventoryService(string host, out ISecureInventoryService inventoryService)
  157. {
  158. if ((host == string.Empty) || (host == "default"))
  159. {
  160. host = m_defaultInventoryHost;
  161. }
  162. lock (m_secureinventoryServices)
  163. {
  164. foreach (ISecureInventoryService service in m_secureinventoryServices)
  165. {
  166. if (service.Host == host)
  167. {
  168. inventoryService = service;
  169. return true;
  170. }
  171. }
  172. }
  173. inventoryService = null;
  174. return false;
  175. }
  176. public bool TryGetInventoryService(string host, out IInventoryServices inventoryService)
  177. {
  178. if ((host == string.Empty) || (host == "default"))
  179. {
  180. host = m_defaultInventoryHost;
  181. }
  182. lock (m_inventoryServices)
  183. {
  184. foreach (IInventoryServices service in m_inventoryServices)
  185. {
  186. if (service.Host == host)
  187. {
  188. inventoryService = service;
  189. return true;
  190. }
  191. }
  192. }
  193. inventoryService = null;
  194. return false;
  195. }
  196. public virtual void AddInventoryService(string hostUrl)
  197. {
  198. }
  199. public virtual void AddSecureInventoryService(string hostUrl)
  200. {
  201. }
  202. public virtual void AddSecureInventoryService(ISecureInventoryService service)
  203. {
  204. lock (m_secureinventoryServices)
  205. {
  206. m_secureinventoryServices.Add(service);
  207. }
  208. }
  209. public virtual void AddInventoryService(IInventoryServices service)
  210. {
  211. lock (m_inventoryServices)
  212. {
  213. m_inventoryServices.Add(service);
  214. }
  215. }
  216. #endregion
  217. #region Friend Methods
  218. /// <summary>
  219. /// Adds a new friend to the database for XUser
  220. /// </summary>
  221. /// <param name="friendlistowner">The agent that who's friends list is being added to</param>
  222. /// <param name="friend">The agent that being added to the friends list of the friends list owner</param>
  223. /// <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>
  224. public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
  225. {
  226. m_userService.AddNewUserFriend(friendlistowner, friend, perms);
  227. }
  228. /// <summary>
  229. /// Logs off a user and does the appropriate communications
  230. /// </summary>
  231. /// <param name="userid"></param>
  232. /// <param name="regionid"></param>
  233. /// <param name="regionhandle"></param>
  234. /// <param name="position"></param>
  235. /// <param name="lookat"></param>
  236. public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, Vector3 position, Vector3 lookat)
  237. {
  238. m_userService.LogOffUser(userid, regionid, regionhandle, position, lookat);
  239. }
  240. /// <summary>
  241. /// Logs off a user and does the appropriate communications (deprecated as of 2008-08-27)
  242. /// </summary>
  243. /// <param name="userid"></param>
  244. /// <param name="regionid"></param>
  245. /// <param name="regionhandle"></param>
  246. /// <param name="posx"></param>
  247. /// <param name="posy"></param>
  248. /// <param name="posz"></param>
  249. public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, float posx, float posy, float posz)
  250. {
  251. m_userService.LogOffUser(userid, regionid, regionhandle, posx, posy, posz);
  252. }
  253. /// <summary>
  254. /// Delete friend on friendlistowner's friendlist.
  255. /// </summary>
  256. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  257. /// <param name="friend">The Ex-friend agent</param>
  258. public void RemoveUserFriend(UUID friendlistowner, UUID friend)
  259. {
  260. m_userService.RemoveUserFriend(friendlistowner, friend);
  261. }
  262. /// <summary>
  263. /// Update permissions for friend on friendlistowner's friendlist.
  264. /// </summary>
  265. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  266. /// <param name="friend">The agent that is getting or loosing permissions</param>
  267. /// <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>
  268. public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
  269. {
  270. m_userService.UpdateUserFriendPerms(friendlistowner, friend, perms);
  271. }
  272. /// <summary>
  273. /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for UUID friendslistowner
  274. /// </summary>
  275. /// <param name="friendlistowner">The agent that we're retreiving the friends Data.</param>
  276. public List<FriendListItem> GetUserFriendList(UUID friendlistowner)
  277. {
  278. return m_userService.GetUserFriendList(friendlistowner);
  279. }
  280. public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids)
  281. {
  282. return m_messageService.GetFriendRegionInfos(uuids);
  283. }
  284. public List<UUID> InformFriendsInOtherRegion(UUID agentId, ulong destRegionHandle, List<UUID> friends, bool online)
  285. {
  286. return m_interRegion.InformFriendsInOtherRegion(agentId, destRegionHandle, friends, online);
  287. }
  288. public bool TriggerTerminateFriend(ulong regionHandle, UUID agentID, UUID exFriendID)
  289. {
  290. return m_interRegion.TriggerTerminateFriend(regionHandle, agentID, exFriendID);
  291. }
  292. #endregion
  293. #region Packet Handlers
  294. public void UpdateAvatarPropertiesRequest(IClientAPI remote_client, UserProfileData UserProfile)
  295. {
  296. m_userService.UpdateUserProfile(UserProfile);
  297. return;
  298. }
  299. public void HandleUUIDNameRequest(UUID uuid, IClientAPI remote_client)
  300. {
  301. if (uuid == m_userProfileCacheService.LibraryRoot.Owner)
  302. {
  303. remote_client.SendNameReply(uuid, "Mr", "OpenSim");
  304. }
  305. else
  306. {
  307. string[] names = doUUIDNameRequest(uuid);
  308. if (names.Length == 2)
  309. {
  310. remote_client.SendNameReply(uuid, names[0], names[1]);
  311. }
  312. }
  313. }
  314. private string[] doUUIDNameRequest(UUID uuid)
  315. {
  316. string[] returnstring = new string[0];
  317. bool doLookup = false;
  318. lock (m_nameRequestCache)
  319. {
  320. if (m_nameRequestCache.ContainsKey(uuid))
  321. {
  322. returnstring = m_nameRequestCache[uuid];
  323. }
  324. else
  325. {
  326. // we don't want to lock the dictionary while we're doing the lookup
  327. doLookup = true;
  328. }
  329. }
  330. if (doLookup) {
  331. UserProfileData profileData = m_userService.GetUserProfile(uuid);
  332. if (profileData != null)
  333. {
  334. returnstring = new string[2];
  335. // UUID profileId = profileData.ID;
  336. returnstring[0] = profileData.FirstName;
  337. returnstring[1] = profileData.SurName;
  338. lock (m_nameRequestCache)
  339. {
  340. if (!m_nameRequestCache.ContainsKey(uuid))
  341. m_nameRequestCache.Add(uuid, returnstring);
  342. }
  343. }
  344. }
  345. return returnstring;
  346. }
  347. public bool UUIDNameCachedTest(UUID uuid)
  348. {
  349. lock (m_nameRequestCache)
  350. return m_nameRequestCache.ContainsKey(uuid);
  351. }
  352. public string UUIDNameRequestString(UUID uuid)
  353. {
  354. string[] names = doUUIDNameRequest(uuid);
  355. if (names.Length == 2)
  356. {
  357. string firstname = names[0];
  358. string lastname = names[1];
  359. return firstname + " " + lastname;
  360. }
  361. return "(hippos)";
  362. }
  363. public List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(UUID queryID, string query)
  364. {
  365. List<AvatarPickerAvatar> pickerlist = m_userService.GenerateAgentPickerRequestResponse(queryID, query);
  366. return pickerlist;
  367. }
  368. #endregion
  369. }
  370. }