public List<UUID> StatusNotification(List<string> friends, UUID foreignUserID, bool online)
{
if (m_FriendsService == null || m_PresenceService == null)
{
MainConsole.Instance.WarnFormat ("[USER AGENT SERVICE]: Unable to perform status notifications because friends or presence services are missing");
return new List<UUID> ();
}
List<UUID> localFriendsOnline = new List<UUID> ();
MainConsole.Instance.DebugFormat ("[USER AGENT SERVICE]: Status notification: foreign user {0} wants to notify {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
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))
{
// great!
usersToBeNotified.Add (localUserID.ToString ());
}
}
}
}
// Now, let's send the notifications
MainConsole.Instance.DebugFormat ("[USER AGENT SERVICE]: Status notification: user has {0} local friends", usersToBeNotified.Count);
// First, let's send notifications to local users who are online in the home grid
//Send "" because if we pass the UUID, it will get the locations for all friends, even on the grid they came from
List<UserInfo> friendSessions = m_PresenceService.GetUserInfos (usersToBeNotified);
foreach (UserInfo friend in friendSessions)
{
if (friend.IsOnline)
{
GridRegion ourRegion = m_GridService.GetRegionByUUID(null, friend.CurrentRegionID);
if (ourRegion != null)
m_asyncPostService.Post (ourRegion.RegionHandle,
SyncMessageHelper.AgentStatusChange (foreignUserID, UUID.Parse (friend.UserID), true));
}
}
// Lastly, let's notify the rest who may be online somewhere else
foreach (string user in usersToBeNotified)
{
UUID id = new UUID (user);
if (m_TravelingAgents.ContainsKey (id) && m_TravelingAgents[id].GridExternalName != m_GridName)
{
string url = m_TravelingAgents[id].GridExternalName;
// forward
MainConsole.Instance.WarnFormat ("[USER AGENT SERVICE]: User {0} is visiting {1}. HG Status notifications still not implemented.", user, url);
}
}
// and finally, let's send the online friends
if (online)
{
return localFriendsOnline;
}
else
return new List<UUID> ();
}