HGStatusNotifier.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using OpenSim.Framework;
  7. using OpenSim.Region.Framework.Interfaces;
  8. using OpenSim.Services.Interfaces;
  9. using OpenSim.Services.Connectors.Hypergrid;
  10. using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
  11. using OpenMetaverse;
  12. using log4net;
  13. namespace OpenSim.Region.CoreModules.Avatar.Friends
  14. {
  15. public class HGStatusNotifier
  16. {
  17. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  18. private HGFriendsModule m_FriendsModule;
  19. public HGStatusNotifier(HGFriendsModule friendsModule)
  20. {
  21. m_FriendsModule = friendsModule;
  22. }
  23. public void Notify(UUID userID, Dictionary<string, List<FriendInfo>> friendsPerDomain, bool online)
  24. {
  25. if(m_FriendsModule is null)
  26. return;
  27. foreach (KeyValuePair<string, List<FriendInfo>> kvp in friendsPerDomain)
  28. {
  29. // For the others, call the user agent service
  30. List<string> ids = new(kvp.Value.Count);
  31. foreach (FriendInfo f in kvp.Value)
  32. ids.Add(f.Friend);
  33. if (ids.Count == 0)
  34. continue; // no one to notify. caller don't do this
  35. //m_log.DebugFormat("[HG STATUS NOTIFIER]: Notifying {0} friends in {1}", ids.Count, kvp.Key);
  36. // ASSUMPTION: we assume that all users for one home domain
  37. // have exactly the same set of service URLs.
  38. // If this is ever not true, we need to change this.
  39. if (Util.ParseUniversalUserIdentifier(ids[0], out UUID friendID))
  40. {
  41. string friendsServerURI = m_FriendsModule.UserManagementModule.GetUserServerURL(friendID, "FriendsServerURI");
  42. if (!string.IsNullOrEmpty(friendsServerURI))
  43. {
  44. HGFriendsServicesConnector fConn = new(friendsServerURI);
  45. List<UUID> friendsOnline = fConn.StatusNotification(ids, userID, online);
  46. if (friendsOnline.Count > 0)
  47. {
  48. IClientAPI client = m_FriendsModule.LocateClientObject(userID);
  49. if(client is not null)
  50. {
  51. m_FriendsModule.CacheFriendsOnline(userID, friendsOnline, online);
  52. if(online)
  53. client?.SendAgentOnline(friendsOnline.ToArray());
  54. else
  55. client?.SendAgentOffline(friendsOnline.ToArray());
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }
  62. }
  63. }