Fixed: when a user logged-in, sometimes he didn't get notified of the Online status of friends, so they continued to appear Offline.

This happened because these notifications (the UDP packets) can only be sent to Root Agents. But the notifications were done in OnClientLogin(), at which point the client is still a Child Agent. Since a FireAndForget is used, it became a race condition as to whether the packets would be sent before or after the client became a Root Agent.

To fix this, we now only send the notifications once the client becomes a Root Agent for the first time.
0.8.0.3
Oren Hurvitz 2014-04-21 14:57:31 +03:00
parent 538ff31b28
commit 4cac87d9f4
2 changed files with 24 additions and 2 deletions

View File

@ -93,6 +93,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
/// </remarks> /// </remarks>
protected Dictionary<UUID, UserFriendData> m_Friends = new Dictionary<UUID, UserFriendData>(); protected Dictionary<UUID, UserFriendData> m_Friends = new Dictionary<UUID, UserFriendData>();
/// <summary>
/// Maintain a record of clients that need to notify about their online status. This only
/// needs to be done on login. Subsequent online/offline friend changes are sent by a different mechanism.
/// </summary>
protected HashSet<UUID> m_NeedsToNotifyStatus = new HashSet<UUID>();
/// <summary> /// <summary>
/// Maintain a record of viewers that need to be sent notifications for friends that are online. This only /// Maintain a record of viewers that need to be sent notifications for friends that are online. This only
/// needs to be done on login. Subsequent online/offline friend changes are sent by a different mechanism. /// needs to be done on login. Subsequent online/offline friend changes are sent by a different mechanism.
@ -324,6 +330,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
private void OnMakeRootAgent(ScenePresence sp) private void OnMakeRootAgent(ScenePresence sp)
{ {
RecacheFriends(sp.ControllingClient); RecacheFriends(sp.ControllingClient);
lock (m_NeedsToNotifyStatus)
{
if (m_NeedsToNotifyStatus.Remove(sp.UUID))
{
// Inform the friends that this user is online. This can only be done once the client is a Root Agent.
StatusChange(sp.UUID, true);
}
}
} }
private void OnClientLogin(IClientAPI client) private void OnClientLogin(IClientAPI client)
@ -331,8 +346,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
UUID agentID = client.AgentId; UUID agentID = client.AgentId;
//m_log.DebugFormat("[XXX]: OnClientLogin!"); //m_log.DebugFormat("[XXX]: OnClientLogin!");
// Inform the friends that this user is online
StatusChange(agentID, true); // Register that we need to send this user's status to friends. This can only be done
// once the client becomes a Root Agent, because as part of sending out the presence
// we also get back the presence of the HG friends, and we need to send that to the
// client, but that can only be done when the client is a Root Agent.
lock (m_NeedsToNotifyStatus)
m_NeedsToNotifyStatus.Add(agentID);
// Register that we need to send the list of online friends to this user // Register that we need to send the list of online friends to this user
lock (m_NeedsListOfOnlineFriends) lock (m_NeedsListOfOnlineFriends)

View File

@ -239,6 +239,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
fList.Add(s.Substring(0, 36)); fList.Add(s.Substring(0, 36));
} }
// FIXME: also query the presence status of friends in other grids (like in HGStatusNotifier.Notify())
PresenceInfo[] presence = PresenceService.GetAgents(fList.ToArray()); PresenceInfo[] presence = PresenceService.GetAgents(fList.ToArray());
foreach (PresenceInfo pi in presence) foreach (PresenceInfo pi in presence)
{ {