public List<UUID> GetOnlineFriends(UUID foreignUserID, List<string> friends)
{
List<UUID> online = new List<UUID> ();
if (m_FriendsService == null || m_PresenceService == null)
{
MainConsole.Instance.WarnFormat ("[USER AGENT SERVICE]: Unable to get online friends because friends or presence services are missing");
return online;
}
MainConsole.Instance.DebugFormat ("[USER AGENT SERVICE]: Foreign user {0} wants to know status of {1} local friends", foreignUserID, friends.Count);
// First, let's double check that the reported friends are, indeed, friends of that user
// And let's check that the secret matches and the rights
List<string> usersToBeNotified = new List<string> ();
foreach (string uui in friends)
{
UUID localUserID;
string secret = string.Empty, tmp = string.Empty;
if (HGUtil.ParseUniversalUserIdentifier (uui, out localUserID, out tmp, out tmp, out tmp, out secret))
{
List<FriendInfo> friendInfos = m_FriendsService.GetFriends (localUserID);
foreach (FriendInfo finfo in friendInfos)
{
if (finfo.Friend.StartsWith (foreignUserID.ToString ()) && finfo.Friend.EndsWith (secret) &&
(finfo.TheirFlags & (int)FriendRights.CanSeeOnline) != 0 && (finfo.TheirFlags != -1))
{
// great!
usersToBeNotified.Add (localUserID.ToString ());
}
}
}
}
// Now, let's find out their status
MainConsole.Instance.DebugFormat ("[USER AGENT SERVICE]: GetOnlineFriends: user has {0} local friends with status rights", usersToBeNotified.Count);
// First, let's send notifications to local users who are online in the home grid
List<UserInfo> friendSessions = m_PresenceService.GetUserInfos (usersToBeNotified);
if (friendSessions != null && friendSessions.Count > 0)
{
foreach (UserInfo pi in friendSessions)
{
UUID presenceID;
if (UUID.TryParse (pi.UserID, out presenceID))
online.Add (presenceID);
}
}
return online;
}