HGStatusNotifier.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. UUID friendID = UUID.Zero; String tmp = String.Empty;
  40. if (Util.ParseUniversalUserIdentifier(ids[0], out friendID, out tmp, out tmp, out tmp, out tmp))
  41. {
  42. string friendsServerURI = m_FriendsModule.UserManagementModule.GetUserServerURL(friendID, "FriendsServerURI");
  43. if (friendsServerURI != string.Empty)
  44. {
  45. HGFriendsServicesConnector fConn = new HGFriendsServicesConnector(friendsServerURI);
  46. List<UUID> friendsOnline = fConn.StatusNotification(ids, userID, online);
  47. if (online && friendsOnline.Count > 0)
  48. {
  49. IClientAPI client = m_FriendsModule.LocateClientObject(userID);
  50. if (client != null)
  51. client.SendAgentOnline(friendsOnline.ToArray());
  52. }
  53. }
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }