aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-03-29 01:08:47 +0100
committerJustin Clark-Casey (justincc)2012-03-29 01:08:47 +0100
commit93ac47f0d3968650bd7758ad0981e8e5d49b8138 (patch)
treede296d7d41d9094365b6d17b6bc9cb98e6d7396c /OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
parentRevert "Add comment about setting client.SceneAgent in AddNewClient()" (diff)
downloadopensim-SC_OLD-93ac47f0d3968650bd7758ad0981e8e5d49b8138.zip
opensim-SC_OLD-93ac47f0d3968650bd7758ad0981e8e5d49b8138.tar.gz
opensim-SC_OLD-93ac47f0d3968650bd7758ad0981e8e5d49b8138.tar.bz2
opensim-SC_OLD-93ac47f0d3968650bd7758ad0981e8e5d49b8138.tar.xz
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.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs62
1 files changed, 44 insertions, 18 deletions
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
57 { 57 {
58 public UUID PrincipalID; 58 public UUID PrincipalID;
59 public FriendInfo[] Friends; 59 public FriendInfo[] Friends;
60 public int Refcount;
60 61
61 public bool IsFriend(string friend) 62 public bool IsFriend(string friend)
62 { 63 {
@@ -254,9 +255,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
254 255
255 private void OnNewClient(IClientAPI client) 256 private void OnNewClient(IClientAPI client)
256 { 257 {
257 if (client.SceneAgent.IsChildAgent)
258 return;
259
260 client.OnInstantMessage += OnInstantMessage; 258 client.OnInstantMessage += OnInstantMessage;
261 client.OnApproveFriendRequest += OnApproveFriendRequest; 259 client.OnApproveFriendRequest += OnApproveFriendRequest;
262 client.OnDenyFriendRequest += OnDenyFriendRequest; 260 client.OnDenyFriendRequest += OnDenyFriendRequest;
@@ -283,14 +281,23 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
283 UUID agentID = client.AgentId; 281 UUID agentID = client.AgentId;
284 lock (m_Friends) 282 lock (m_Friends)
285 { 283 {
286 UserFriendData friendsData = new UserFriendData(); 284 UserFriendData friendsData;
287 friendsData.PrincipalID = agentID; 285 if (m_Friends.TryGetValue(agentID, out friendsData))
288 friendsData.Friends = GetFriendsFromService(client); 286 {
287 friendsData.Refcount++;
288 return false;
289 }
290 else
291 {
292 friendsData = new UserFriendData();
293 friendsData.PrincipalID = agentID;
294 friendsData.Friends = GetFriendsFromService(client);
295 friendsData.Refcount = 1;
289 296
290 m_Friends[agentID] = friendsData; 297 m_Friends[agentID] = friendsData;
298 return true;
299 }
291 } 300 }
292
293 return true;
294 } 301 }
295 302
296 private void OnClientClosed(UUID agentID, Scene scene) 303 private void OnClientClosed(UUID agentID, Scene scene)
@@ -300,17 +307,23 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
300 { 307 {
301 // do this for root agents closing out 308 // do this for root agents closing out
302 StatusChange(agentID, false); 309 StatusChange(agentID, false);
310 }
303 311
304 lock (m_Friends) 312 lock (m_Friends)
305 m_Friends.Remove(agentID); 313 {
314 UserFriendData friendsData;
315 if (m_Friends.TryGetValue(agentID, out friendsData))
316 {
317 friendsData.Refcount--;
318 if (friendsData.Refcount <= 0)
319 m_Friends.Remove(agentID);
320 }
306 } 321 }
307 } 322 }
308 323
309 private void OnMakeRootAgent(ScenePresence sp) 324 private void OnMakeRootAgent(ScenePresence sp)
310 { 325 {
311 // FIXME: Ideally, we want to avoid doing this here since it sits the EventManager.OnMakeRootAgent event 326 RecacheFriends(sp.ControllingClient);
312 // is on the critical path for transferring an avatar from one region to another.
313 CacheFriends(sp.ControllingClient);
314 } 327 }
315 328
316 private void OnClientLogin(IClientAPI client) 329 private void OnClientLogin(IClientAPI client)
@@ -616,7 +629,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
616 } 629 }
617 630
618 // Update the local cache. 631 // Update the local cache.
619 CacheFriends(client); 632 RecacheFriends(client);
620 633
621 // 634 //
622 // Notify the friend 635 // Notify the friend
@@ -678,7 +691,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
678 client.SendAlertMessage("Unable to terminate friendship on this sim."); 691 client.SendAlertMessage("Unable to terminate friendship on this sim.");
679 692
680 // Update local cache 693 // Update local cache
681 CacheFriends(client); 694 RecacheFriends(client);
682 695
683 client.SendTerminateFriend(exfriendID); 696 client.SendTerminateFriend(exfriendID);
684 697
@@ -799,7 +812,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
799 812
800 813
801 // Update the local cache 814 // Update the local cache
802 CacheFriends(friendClient); 815 RecacheFriends(friendClient);
803 816
804 // we're done 817 // we're done
805 return true; 818 return true;
@@ -832,7 +845,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
832 // the friend in this sim as root agent 845 // the friend in this sim as root agent
833 friendClient.SendTerminateFriend(exfriendID); 846 friendClient.SendTerminateFriend(exfriendID);
834 // update local cache 847 // update local cache
835 CacheFriends(friendClient); 848 RecacheFriends(friendClient);
836 // we're done 849 // we're done
837 return true; 850 return true;
838 } 851 }
@@ -933,6 +946,19 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
933 return FriendsService.GetFriends(client.AgentId); 946 return FriendsService.GetFriends(client.AgentId);
934 } 947 }
935 948
949 protected void RecacheFriends(IClientAPI client)
950 {
951 // FIXME: Ideally, we want to avoid doing this here since it sits the EventManager.OnMakeRootAgent event
952 // is on the critical path for transferring an avatar from one region to another.
953 UUID agentID = client.AgentId;
954 lock (m_Friends)
955 {
956 UserFriendData friendsData;
957 if (m_Friends.TryGetValue(agentID, out friendsData))
958 friendsData.Friends = GetFriendsFromService(client);
959 }
960 }
961
936 /// <summary> 962 /// <summary>
937 /// Are friends cached on this simulator for a particular user? 963 /// Are friends cached on this simulator for a particular user?
938 /// </summary> 964 /// </summary>