From 4cac87d9f421d937422c0f9afbe1ba66c66bad17 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Mon, 21 Apr 2014 14:57:31 +0300 Subject: 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. --- .../CoreModules/Avatar/Friends/FriendsModule.cs | 24 ++++++++++++++++++++-- .../CoreModules/Avatar/Friends/HGFriendsModule.cs | 2 ++ 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index b693f2d..31bcded 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs @@ -94,6 +94,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends protected Dictionary m_Friends = new Dictionary(); /// + /// 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. + /// + protected HashSet m_NeedsToNotifyStatus = new HashSet(); + + /// /// 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. /// @@ -324,6 +330,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends private void OnMakeRootAgent(ScenePresence sp) { 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) @@ -331,8 +346,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends UUID agentID = client.AgentId; //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 lock (m_NeedsListOfOnlineFriends) diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs index d00945e..be12935 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs @@ -239,6 +239,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends 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()); foreach (PresenceInfo pi in presence) { -- cgit v1.1