From 93ac47f0d3968650bd7758ad0981e8e5d49b8138 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 29 Mar 2012 01:08:47 +0100 Subject: Revert "Simplify friends caching by only doing this for root agents - no functions require caching for child agents." We need to cache child agents so that friends object edit/delete permissions will work across boarders on regions hosted by different simulators. This reverts commit d9f7b8549b3cb9699eb8bd54242d31aac0f8241a. --- .../CoreModules/Avatar/Friends/FriendsModule.cs | 62 +++++++++++++++------- .../CoreModules/Avatar/Friends/HGFriendsModule.cs | 6 +-- 2 files changed, 47 insertions(+), 21 deletions(-) (limited to 'OpenSim/Region/CoreModules/Avatar') diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 4cc0e19..aadd3bc 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs @@ -57,6 +57,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends { public UUID PrincipalID; public FriendInfo[] Friends; + public int Refcount; public bool IsFriend(string friend) { @@ -254,9 +255,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends private void OnNewClient(IClientAPI client) { - if (client.SceneAgent.IsChildAgent) - return; - client.OnInstantMessage += OnInstantMessage; client.OnApproveFriendRequest += OnApproveFriendRequest; client.OnDenyFriendRequest += OnDenyFriendRequest; @@ -283,14 +281,23 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends UUID agentID = client.AgentId; lock (m_Friends) { - UserFriendData friendsData = new UserFriendData(); - friendsData.PrincipalID = agentID; - friendsData.Friends = GetFriendsFromService(client); + UserFriendData friendsData; + if (m_Friends.TryGetValue(agentID, out friendsData)) + { + friendsData.Refcount++; + return false; + } + else + { + friendsData = new UserFriendData(); + friendsData.PrincipalID = agentID; + friendsData.Friends = GetFriendsFromService(client); + friendsData.Refcount = 1; - m_Friends[agentID] = friendsData; + m_Friends[agentID] = friendsData; + return true; + } } - - return true; } private void OnClientClosed(UUID agentID, Scene scene) @@ -300,17 +307,23 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends { // do this for root agents closing out StatusChange(agentID, false); + } - lock (m_Friends) - m_Friends.Remove(agentID); + lock (m_Friends) + { + UserFriendData friendsData; + if (m_Friends.TryGetValue(agentID, out friendsData)) + { + friendsData.Refcount--; + if (friendsData.Refcount <= 0) + m_Friends.Remove(agentID); + } } } private void OnMakeRootAgent(ScenePresence sp) { - // FIXME: Ideally, we want to avoid doing this here since it sits the EventManager.OnMakeRootAgent event - // is on the critical path for transferring an avatar from one region to another. - CacheFriends(sp.ControllingClient); + RecacheFriends(sp.ControllingClient); } private void OnClientLogin(IClientAPI client) @@ -616,7 +629,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } // Update the local cache. - CacheFriends(client); + RecacheFriends(client); // // Notify the friend @@ -678,7 +691,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends client.SendAlertMessage("Unable to terminate friendship on this sim."); // Update local cache - CacheFriends(client); + RecacheFriends(client); client.SendTerminateFriend(exfriendID); @@ -799,7 +812,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends // Update the local cache - CacheFriends(friendClient); + RecacheFriends(friendClient); // we're done return true; @@ -832,7 +845,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends // the friend in this sim as root agent friendClient.SendTerminateFriend(exfriendID); // update local cache - CacheFriends(friendClient); + RecacheFriends(friendClient); // we're done return true; } @@ -933,6 +946,19 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends return FriendsService.GetFriends(client.AgentId); } + protected void RecacheFriends(IClientAPI client) + { + // FIXME: Ideally, we want to avoid doing this here since it sits the EventManager.OnMakeRootAgent event + // is on the critical path for transferring an avatar from one region to another. + UUID agentID = client.AgentId; + lock (m_Friends) + { + UserFriendData friendsData; + if (m_Friends.TryGetValue(agentID, out friendsData)) + friendsData.Friends = GetFriendsFromService(client); + } + } + /// /// Are friends cached on this simulator for a particular user? /// diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs index 7bc3018..e50a84a 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs @@ -121,7 +121,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends { UUID agentID = client.AgentId; // we do this only for the root agent - if (!client.SceneAgent.IsChildAgent) + if (m_Friends[agentID].Refcount == 1) { // We need to preload the user management cache with the names // of foreign friends, just like we do with SOPs' creators @@ -426,14 +426,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends agentClientCircuit = ((Scene)(agentClient.Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.CircuitCode); agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit); agentFriendService = agentClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); - CacheFriends(agentClient); + RecacheFriends(agentClient); } if (friendClient != null) { friendClientCircuit = ((Scene)(friendClient.Scene)).AuthenticateHandler.GetAgentCircuitData(friendClient.CircuitCode); friendUUI = Util.ProduceUserUniversalIdentifier(friendClientCircuit); friendFriendService = friendClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); - CacheFriends(friendClient); + RecacheFriends(friendClient); } m_log.DebugFormat("[HGFRIENDS MODULE] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}", -- cgit v1.1