HGStatusNotifier.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. foreach (KeyValuePair<string, List<FriendInfo>> kvp in friendsPerDomain)
  26. {
  27. if (kvp.Key != "local")
  28. {
  29. // For the others, call the user agent service
  30. List<string> ids = new List<string>();
  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 (friendsServerURI != string.Empty)
  43. {
  44. HGFriendsServicesConnector fConn = new HGFriendsServicesConnector(friendsServerURI);
  45. List<UUID> friendsOnline = fConn.StatusNotification(ids, userID, online);
  46. if (online && friendsOnline.Count > 0)
  47. {
  48. IClientAPI client = m_FriendsModule.LocateClientObject(userID);
  49. if (client != null)
  50. client.SendAgentOnline(friendsOnline.ToArray());
  51. }
  52. }
  53. }
  54. }
  55. }
  56. }
  57. }
  58. }