From 5c5966545d14de43500b95109e8ce81058ebe2c3 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 28 Feb 2010 12:07:38 -0800 Subject: Initial Online friends notification seems to be working reliably now. All this needs more testing, but everything is there. --- .../CoreModules/Avatar/Friends/FriendsModule.cs | 54 +++++++++++++++------- 1 file changed, 38 insertions(+), 16 deletions(-) (limited to 'OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs') diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index cc3a3ee..8aa5b91 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs @@ -79,6 +79,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends protected Dictionary m_Friends = new Dictionary(); + protected List m_NeedsListOfFriends = new List(); + protected IPresenceService PresenceService { get @@ -170,6 +172,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends scene.EventManager.OnClientClosed += OnClientClosed; scene.EventManager.OnMakeRootAgent += OnMakeRootAgent; scene.EventManager.OnMakeChildAgent += OnMakeChildAgent; + scene.EventManager.OnClientLogin += OnClientLogin; } public void RegionLoaded(Scene scene) @@ -220,7 +223,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends client.OnGrantUserRights += OnGrantUserRights; client.OnLogout += OnLogout; - client.OnEconomyDataRequest += SendPresence; if (m_Friends.ContainsKey(client.AgentId)) { @@ -285,30 +287,50 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } } - private void SendPresence(UUID agentID) + private void OnClientLogin(IClientAPI client) { + UUID agentID = client.AgentId; + // Inform the friends that this user is online StatusChange(agentID, true); - // Now send the list of online friends to this user - if (!m_Friends.ContainsKey(agentID)) - { - m_log.DebugFormat("[FRIENDS MODULE]: agent {0} not found in local cache", agentID); - return; - } + // Register that we need to send the list of online friends to this user + lock (m_NeedsListOfFriends) + if (!m_NeedsListOfFriends.Contains(agentID)) + { + m_NeedsListOfFriends.Add(agentID); + } + } - IClientAPI client = LocateClientObject(agentID); - if (client == null) + public void SendFriendsOnlineIfNeeded(IClientAPI client) + { + UUID agentID = client.AgentId; + if (m_NeedsListOfFriends.Contains(agentID)) { - m_log.DebugFormat("[FRIENDS MODULE]: agent's client {0} not found in local scene", agentID); - return; - } + if (!m_Friends.ContainsKey(agentID)) + { + m_log.DebugFormat("[FRIENDS MODULE]: agent {0} not found in local cache", agentID); + return; + } + + client = LocateClientObject(agentID); + if (client == null) + { + m_log.DebugFormat("[FRIENDS MODULE]: agent's client {0} not found in local scene", agentID); + return; + } - List online = GetOnlineFriends(agentID); + List online = GetOnlineFriends(agentID); - m_log.DebugFormat("[FRIENDS]: User {0} in region {1} has {2} friends online", client.AgentId, client.Scene.RegionInfo.RegionName, online.Count); - client.SendAgentOnline(online.ToArray()); + if (online.Count > 0) + { + m_log.DebugFormat("[FRIENDS MODULE]: User {0} in region {1} has {2} friends online", client.AgentId, client.Scene.RegionInfo.RegionName, online.Count); + client.SendAgentOnline(online.ToArray()); + } + lock (m_NeedsListOfFriends) + m_NeedsListOfFriends.Remove(agentID); + } } List GetOnlineFriends(UUID userID) -- cgit v1.1