From 7f349d61cb8251a1c13811f5ff7bd95b2311706c Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 11 Jun 2010 06:32:24 -0700 Subject: [PATCH] Better friends notification: get rid of OnLogout and use OnClientClose for sending notifications. This takes care of crashed sessions. Also, made the notifications themselves asynchronous. --- .../Avatar/Friends/FriendsModule.cs | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 4f0487bd71..80982fd577 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs @@ -220,8 +220,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends client.OnGrantUserRights += OnGrantUserRights; - client.OnLogout += OnLogout; - lock (m_Friends) { if (m_Friends.ContainsKey(client.AgentId)) @@ -240,36 +238,25 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends m_Friends.Add(client.AgentId, newFriends); } - //StatusChange(client.AgentId, true); } private void OnClientClosed(UUID agentID, Scene scene) { ScenePresence sp = scene.GetScenePresence(agentID); + if (sp != null && !sp.IsChildAgent) + // do this for root agents closing out + StatusChange(agentID, false); + lock (m_Friends) if (m_Friends.ContainsKey(agentID)) { if (m_Friends[agentID].Refcount == 1) - { - if (sp != null && sp.IsChildAgent) - // we do this only for child agents - // Root agents' closing = logout; that's - // processed with OnLogout - { - m_Friends.Remove(agentID); - } - } + m_Friends.Remove(agentID); else m_Friends[agentID].Refcount--; } } - private void OnLogout(IClientAPI client) - { - StatusChange(client.AgentId, false); - m_Friends.Remove(client.AgentId); - } - private void OnMakeRootAgent(ScenePresence sp) { UUID agentID = sp.ControllingClient.AgentId; @@ -457,12 +444,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends if (((fi.MyFlags & 1) != 0) && (fi.TheirFlags != -1)) friendList.Add(fi); } - foreach (FriendInfo fi in friendList) + + Util.FireAndForget(delegate { - //m_log.DebugFormat("[FRIENDS]: Notifying {0}", fi.PrincipalID); - // Notify about this user status - StatusNotify(fi, agentID, online); - } + foreach (FriendInfo fi in friendList) + { + //m_log.DebugFormat("[FRIENDS]: Notifying {0}", fi.PrincipalID); + // Notify about this user status + StatusNotify(fi, agentID, online); + } + }); } else m_log.WarnFormat("[FRIENDS]: {0} not found in cache", agentID);