aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs62
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs6
2 files changed, 47 insertions, 21 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>
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
121 { 121 {
122 UUID agentID = client.AgentId; 122 UUID agentID = client.AgentId;
123 // we do this only for the root agent 123 // we do this only for the root agent
124 if (!client.SceneAgent.IsChildAgent) 124 if (m_Friends[agentID].Refcount == 1)
125 { 125 {
126 // We need to preload the user management cache with the names 126 // We need to preload the user management cache with the names
127 // of foreign friends, just like we do with SOPs' creators 127 // of foreign friends, just like we do with SOPs' creators
@@ -426,14 +426,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
426 agentClientCircuit = ((Scene)(agentClient.Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.CircuitCode); 426 agentClientCircuit = ((Scene)(agentClient.Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.CircuitCode);
427 agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit); 427 agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit);
428 agentFriendService = agentClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); 428 agentFriendService = agentClientCircuit.ServiceURLs["FriendsServerURI"].ToString();
429 CacheFriends(agentClient); 429 RecacheFriends(agentClient);
430 } 430 }
431 if (friendClient != null) 431 if (friendClient != null)
432 { 432 {
433 friendClientCircuit = ((Scene)(friendClient.Scene)).AuthenticateHandler.GetAgentCircuitData(friendClient.CircuitCode); 433 friendClientCircuit = ((Scene)(friendClient.Scene)).AuthenticateHandler.GetAgentCircuitData(friendClient.CircuitCode);
434 friendUUI = Util.ProduceUserUniversalIdentifier(friendClientCircuit); 434 friendUUI = Util.ProduceUserUniversalIdentifier(friendClientCircuit);
435 friendFriendService = friendClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); 435 friendFriendService = friendClientCircuit.ServiceURLs["FriendsServerURI"].ToString();
436 CacheFriends(friendClient); 436 RecacheFriends(friendClient);
437 } 437 }
438 438
439 m_log.DebugFormat("[HGFRIENDS MODULE] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}", 439 m_log.DebugFormat("[HGFRIENDS MODULE] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}",