aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs243
1 files changed, 103 insertions, 140 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
index 4cc0e19..f64c161 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
@@ -51,12 +51,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
51{ 51{
52 public class FriendsModule : ISharedRegionModule, IFriendsModule 52 public class FriendsModule : ISharedRegionModule, IFriendsModule
53 { 53 {
54 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55
54 protected bool m_Enabled = false; 56 protected bool m_Enabled = false;
55 57
56 protected class UserFriendData 58 protected class UserFriendData
57 { 59 {
58 public UUID PrincipalID; 60 public UUID PrincipalID;
59 public FriendInfo[] Friends; 61 public FriendInfo[] Friends;
62 public int Refcount;
60 63
61 public bool IsFriend(string friend) 64 public bool IsFriend(string friend)
62 { 65 {
@@ -71,7 +74,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
71 } 74 }
72 75
73 protected static readonly FriendInfo[] EMPTY_FRIENDS = new FriendInfo[0]; 76 protected static readonly FriendInfo[] EMPTY_FRIENDS = new FriendInfo[0];
74 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
75 77
76 protected List<Scene> m_Scenes = new List<Scene>(); 78 protected List<Scene> m_Scenes = new List<Scene>();
77 79
@@ -108,7 +110,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
108 } 110 }
109 } 111 }
110 112
111 protected IFriendsService FriendsService 113 public IFriendsService FriendsService
112 { 114 {
113 get 115 get
114 { 116 {
@@ -155,7 +157,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
155 InitModule(config); 157 InitModule(config);
156 158
157 m_Enabled = true; 159 m_Enabled = true;
158 m_log.InfoFormat("[FRIENDS MODULE]: {0} enabled.", Name); 160 m_log.DebugFormat("[FRIENDS MODULE]: {0} enabled.", Name);
159 } 161 }
160 } 162 }
161 } 163 }
@@ -200,7 +202,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
200 if (!m_Enabled) 202 if (!m_Enabled)
201 return; 203 return;
202 204
203 m_log.DebugFormat("[FRIENDS MODULE]: AddRegion on {0}", Name); 205// m_log.DebugFormat("[FRIENDS MODULE]: AddRegion on {0}", Name);
204 206
205 m_Scenes.Add(scene); 207 m_Scenes.Add(scene);
206 scene.RegisterModuleInterface<IFriendsModule>(this); 208 scene.RegisterModuleInterface<IFriendsModule>(this);
@@ -211,14 +213,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
211 scene.EventManager.OnClientLogin += OnClientLogin; 213 scene.EventManager.OnClientLogin += OnClientLogin;
212 } 214 }
213 215
214 public virtual void RegionLoaded(Scene scene) 216 public virtual void RegionLoaded(Scene scene) {}
215 {
216 scene.AddCommand(
217 "Friends", this, "friends show cache",
218 "friends show cache [<first-name> <last-name>]",
219 "Show the friends cache for the given user",
220 HandleFriendsShowCacheCommand);
221 }
222 217
223 public void RemoveRegion(Scene scene) 218 public void RemoveRegion(Scene scene)
224 { 219 {
@@ -240,13 +235,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
240 235
241 #endregion 236 #endregion
242 237
243 public virtual uint GetFriendPerms(UUID principalID, UUID friendID) 238 public virtual int GetRightsGrantedByFriend(UUID principalID, UUID friendID)
244 { 239 {
245 FriendInfo[] friends = GetFriends(principalID); 240 FriendInfo[] friends = GetFriendsFromCache(principalID);
246 FriendInfo finfo = GetFriend(friends, friendID); 241 FriendInfo finfo = GetFriend(friends, friendID);
247 if (finfo != null) 242 if (finfo != null)
248 { 243 {
249 return (uint)finfo.TheirFlags; 244 return finfo.TheirFlags;
250 } 245 }
251 246
252 return 0; 247 return 0;
@@ -254,15 +249,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
254 249
255 private void OnNewClient(IClientAPI client) 250 private void OnNewClient(IClientAPI client)
256 { 251 {
257 if (client.SceneAgent.IsChildAgent)
258 return;
259
260 client.OnInstantMessage += OnInstantMessage; 252 client.OnInstantMessage += OnInstantMessage;
261 client.OnApproveFriendRequest += OnApproveFriendRequest; 253 client.OnApproveFriendRequest += OnApproveFriendRequest;
262 client.OnDenyFriendRequest += OnDenyFriendRequest; 254 client.OnDenyFriendRequest += OnDenyFriendRequest;
263 client.OnTerminateFriendship += (thisClient, agentID, exfriendID) => RemoveFriendship(thisClient, exfriendID); 255 client.OnTerminateFriendship += RemoveFriendship;
264 client.OnGrantUserRights += OnGrantUserRights; 256 client.OnGrantUserRights += GrantRights;
265 257
258 // We need to cache information for child agents as well as root agents so that friend edit/move/delete
259 // permissions will work across borders where both regions are on different simulators.
260 //
266 // Do not do this asynchronously. If we do, then subsequent code can outrace CacheFriends() and 261 // Do not do this asynchronously. If we do, then subsequent code can outrace CacheFriends() and
267 // return misleading results from the still empty friends cache. 262 // return misleading results from the still empty friends cache.
268 // If we absolutely need to do this asynchronously, then a signalling mechanism is needed so that calls 263 // If we absolutely need to do this asynchronously, then a signalling mechanism is needed so that calls
@@ -283,14 +278,23 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
283 UUID agentID = client.AgentId; 278 UUID agentID = client.AgentId;
284 lock (m_Friends) 279 lock (m_Friends)
285 { 280 {
286 UserFriendData friendsData = new UserFriendData(); 281 UserFriendData friendsData;
287 friendsData.PrincipalID = agentID; 282 if (m_Friends.TryGetValue(agentID, out friendsData))
288 friendsData.Friends = GetFriendsFromService(client); 283 {
284 friendsData.Refcount++;
285 return false;
286 }
287 else
288 {
289 friendsData = new UserFriendData();
290 friendsData.PrincipalID = agentID;
291 friendsData.Friends = GetFriendsFromService(client);
292 friendsData.Refcount = 1;
289 293
290 m_Friends[agentID] = friendsData; 294 m_Friends[agentID] = friendsData;
295 return true;
296 }
291 } 297 }
292
293 return true;
294 } 298 }
295 299
296 private void OnClientClosed(UUID agentID, Scene scene) 300 private void OnClientClosed(UUID agentID, Scene scene)
@@ -300,17 +304,23 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
300 { 304 {
301 // do this for root agents closing out 305 // do this for root agents closing out
302 StatusChange(agentID, false); 306 StatusChange(agentID, false);
307 }
303 308
304 lock (m_Friends) 309 lock (m_Friends)
305 m_Friends.Remove(agentID); 310 {
311 UserFriendData friendsData;
312 if (m_Friends.TryGetValue(agentID, out friendsData))
313 {
314 friendsData.Refcount--;
315 if (friendsData.Refcount <= 0)
316 m_Friends.Remove(agentID);
317 }
306 } 318 }
307 } 319 }
308 320
309 private void OnMakeRootAgent(ScenePresence sp) 321 private void OnMakeRootAgent(ScenePresence sp)
310 { 322 {
311 // FIXME: Ideally, we want to avoid doing this here since it sits the EventManager.OnMakeRootAgent event 323 RecacheFriends(sp.ControllingClient);
312 // is on the critical path for transferring an avatar from one region to another.
313 CacheFriends(sp.ControllingClient);
314 } 324 }
315 325
316 private void OnClientLogin(IClientAPI client) 326 private void OnClientLogin(IClientAPI client)
@@ -339,18 +349,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
339 349
340 // Send the friends online 350 // Send the friends online
341 List<UUID> online = GetOnlineFriends(agentID); 351 List<UUID> online = GetOnlineFriends(agentID);
342 if (online.Count > 0)
343 {
344 m_log.DebugFormat(
345 "[FRIENDS MODULE]: User {0} in region {1} has {2} friends online",
346 client.Name, client.Scene.RegionInfo.RegionName, online.Count);
347 352
353 if (online.Count > 0)
348 client.SendAgentOnline(online.ToArray()); 354 client.SendAgentOnline(online.ToArray());
349 }
350 355
351 // Send outstanding friendship offers 356 // Send outstanding friendship offers
352 List<string> outstanding = new List<string>(); 357 List<string> outstanding = new List<string>();
353 FriendInfo[] friends = GetFriends(agentID); 358 FriendInfo[] friends = GetFriendsFromCache(agentID);
354 foreach (FriendInfo fi in friends) 359 foreach (FriendInfo fi in friends)
355 { 360 {
356 if (fi.TheirFlags == -1) 361 if (fi.TheirFlags == -1)
@@ -406,23 +411,30 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
406 List<UUID> GetOnlineFriends(UUID userID) 411 List<UUID> GetOnlineFriends(UUID userID)
407 { 412 {
408 List<string> friendList = new List<string>(); 413 List<string> friendList = new List<string>();
409 List<UUID> online = new List<UUID>();
410 414
411 FriendInfo[] friends = GetFriends(userID); 415 FriendInfo[] friends = GetFriendsFromCache(userID);
412 foreach (FriendInfo fi in friends) 416 foreach (FriendInfo fi in friends)
413 { 417 {
414 if (((fi.TheirFlags & 1) != 0) && (fi.TheirFlags != -1)) 418 if (((fi.TheirFlags & (int)FriendRights.CanSeeOnline) != 0) && (fi.TheirFlags != -1))
415 friendList.Add(fi.Friend); 419 friendList.Add(fi.Friend);
416 } 420 }
417 421
422 List<UUID> online = new List<UUID>();
423
418 if (friendList.Count > 0) 424 if (friendList.Count > 0)
419 GetOnlineFriends(userID, friendList, online); 425 GetOnlineFriends(userID, friendList, online);
420 426
427// m_log.DebugFormat(
428// "[FRIENDS MODULE]: User {0} has {1} friends online", userID, online.Count);
429
421 return online; 430 return online;
422 } 431 }
423 432
424 protected virtual void GetOnlineFriends(UUID userID, List<string> friendList, /*collector*/ List<UUID> online) 433 protected virtual void GetOnlineFriends(UUID userID, List<string> friendList, /*collector*/ List<UUID> online)
425 { 434 {
435// m_log.DebugFormat(
436// "[FRIENDS MODULE]: Looking for online presence of {0} users for {1}", friendList.Count, userID);
437
426 PresenceInfo[] presence = PresenceService.GetAgents(friendList.ToArray()); 438 PresenceInfo[] presence = PresenceService.GetAgents(friendList.ToArray());
427 foreach (PresenceInfo pi in presence) 439 foreach (PresenceInfo pi in presence)
428 { 440 {
@@ -473,13 +485,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
473 /// <param name="online"></param> 485 /// <param name="online"></param>
474 private void StatusChange(UUID agentID, bool online) 486 private void StatusChange(UUID agentID, bool online)
475 { 487 {
476 FriendInfo[] friends = GetFriends(agentID); 488 FriendInfo[] friends = GetFriendsFromCache(agentID);
477 if (friends.Length > 0) 489 if (friends.Length > 0)
478 { 490 {
479 List<FriendInfo> friendList = new List<FriendInfo>(); 491 List<FriendInfo> friendList = new List<FriendInfo>();
480 foreach (FriendInfo fi in friends) 492 foreach (FriendInfo fi in friends)
481 { 493 {
482 if (((fi.MyFlags & 1) != 0) && (fi.TheirFlags != -1)) 494 if (((fi.MyFlags & (int)FriendRights.CanSeeOnline) != 0) && (fi.TheirFlags != -1))
483 friendList.Add(fi); 495 friendList.Add(fi);
484 } 496 }
485 497
@@ -545,7 +557,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
545 m_log.DebugFormat("[FRIENDS]: {0} ({1}) offered friendship to {2} ({3})", principalID, client.FirstName + client.LastName, friendID, im.fromAgentName); 557 m_log.DebugFormat("[FRIENDS]: {0} ({1}) offered friendship to {2} ({3})", principalID, client.FirstName + client.LastName, friendID, im.fromAgentName);
546 558
547 // Check that the friendship doesn't exist yet 559 // Check that the friendship doesn't exist yet
548 FriendInfo[] finfos = GetFriends(principalID); 560 FriendInfo[] finfos = GetFriendsFromCache(principalID);
549 if (finfos != null) 561 if (finfos != null)
550 { 562 {
551 FriendInfo f = GetFriend(finfos, friendID); 563 FriendInfo f = GetFriend(finfos, friendID);
@@ -598,7 +610,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
598 return (account == null) ? "Unknown" : account.FirstName + " " + account.LastName; 610 return (account == null) ? "Unknown" : account.FirstName + " " + account.LastName;
599 } 611 }
600 612
601 protected virtual void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) 613 protected virtual void OnApproveFriendRequest(IClientAPI client, UUID friendID, List<UUID> callingCardFolders)
602 { 614 {
603 m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", client.AgentId, friendID); 615 m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", client.AgentId, friendID);
604 616
@@ -616,7 +628,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
616 } 628 }
617 629
618 // Update the local cache. 630 // Update the local cache.
619 CacheFriends(client); 631 RecacheFriends(client);
620 632
621 // 633 //
622 // Notify the friend 634 // Notify the friend
@@ -643,18 +655,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
643 } 655 }
644 } 656 }
645 657
646 private void OnDenyFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) 658 private void OnDenyFriendRequest(IClientAPI client, UUID friendID, List<UUID> callingCardFolders)
647 { 659 {
648 m_log.DebugFormat("[FRIENDS]: {0} denied friendship to {1}", agentID, friendID); 660 m_log.DebugFormat("[FRIENDS]: {0} denied friendship to {1}", client.AgentId, friendID);
649 661
650 DeleteFriendship(agentID, friendID); 662 DeleteFriendship(client.AgentId, friendID);
651 663
652 // 664 //
653 // Notify the friend 665 // Notify the friend
654 // 666 //
655 667
656 // Try local 668 // Try local
657 if (LocalFriendshipDenied(agentID, client.Name, friendID)) 669 if (LocalFriendshipDenied(client.AgentId, client.Name, friendID))
658 return; 670 return;
659 671
660 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); 672 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() });
@@ -665,7 +677,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
665 { 677 {
666 GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); 678 GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID);
667 if (region != null) 679 if (region != null)
668 m_FriendsSimConnector.FriendshipDenied(region, agentID, client.Name, friendID); 680 m_FriendsSimConnector.FriendshipDenied(region, client.AgentId, client.Name, friendID);
669 else 681 else
670 m_log.WarnFormat("[FRIENDS]: Could not find region {0} in locating {1}", friendSession.RegionID, friendID); 682 m_log.WarnFormat("[FRIENDS]: Could not find region {0} in locating {1}", friendSession.RegionID, friendID);
671 } 683 }
@@ -678,7 +690,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
678 client.SendAlertMessage("Unable to terminate friendship on this sim."); 690 client.SendAlertMessage("Unable to terminate friendship on this sim.");
679 691
680 // Update local cache 692 // Update local cache
681 CacheFriends(client); 693 RecacheFriends(client);
682 694
683 client.SendTerminateFriend(exfriendID); 695 client.SendTerminateFriend(exfriendID);
684 696
@@ -702,23 +714,27 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
702 } 714 }
703 } 715 }
704 716
705 private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights) 717 public void GrantRights(IClientAPI remoteClient, UUID friendID, int rights)
706 { 718 {
707 m_log.DebugFormat("[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}", requester, rights, target); 719 UUID requester = remoteClient.AgentId;
708 720
709 FriendInfo[] friends = GetFriends(remoteClient.AgentId); 721 m_log.DebugFormat(
722 "[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}",
723 requester, rights, friendID);
724
725 FriendInfo[] friends = GetFriendsFromCache(requester);
710 if (friends.Length == 0) 726 if (friends.Length == 0)
711 { 727 {
712 return; 728 return;
713 } 729 }
714 730
715 // Let's find the friend in this user's friend list 731 // Let's find the friend in this user's friend list
716 FriendInfo friend = GetFriend(friends, target); 732 FriendInfo friend = GetFriend(friends, friendID);
717 733
718 if (friend != null) // Found it 734 if (friend != null) // Found it
719 { 735 {
720 // Store it on the DB 736 // Store it on the DB
721 if (!StoreRights(requester, target, rights)) 737 if (!StoreRights(requester, friendID, rights))
722 { 738 {
723 remoteClient.SendAlertMessage("Unable to grant rights."); 739 remoteClient.SendAlertMessage("Unable to grant rights.");
724 return; 740 return;
@@ -729,17 +745,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
729 friend.MyFlags = rights; 745 friend.MyFlags = rights;
730 746
731 // Always send this back to the original client 747 // Always send this back to the original client
732 remoteClient.SendChangeUserRights(requester, target, rights); 748 remoteClient.SendChangeUserRights(requester, friendID, rights);
733 749
734 // 750 //
735 // Notify the friend 751 // Notify the friend
736 // 752 //
737 753
738 // Try local 754 // Try local
739 if (LocalGrantRights(requester, target, myFlags, rights)) 755 if (LocalGrantRights(requester, friendID, myFlags, rights))
740 return; 756 return;
741 757
742 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { target.ToString() }); 758 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() });
743 if (friendSessions != null && friendSessions.Length > 0) 759 if (friendSessions != null && friendSessions.Length > 0)
744 { 760 {
745 PresenceInfo friendSession = friendSessions[0]; 761 PresenceInfo friendSession = friendSessions[0];
@@ -748,12 +764,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
748 GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); 764 GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID);
749 // TODO: You might want to send the delta to save the lookup 765 // TODO: You might want to send the delta to save the lookup
750 // on the other end!! 766 // on the other end!!
751 m_FriendsSimConnector.GrantRights(region, requester, target, myFlags, rights); 767 m_FriendsSimConnector.GrantRights(region, requester, friendID, myFlags, rights);
752 } 768 }
753 } 769 }
754 } 770 }
755 else 771 else
756 m_log.DebugFormat("[FRIENDS MODULE]: friend {0} not found for {1}", target, requester); 772 {
773 m_log.DebugFormat("[FRIENDS MODULE]: friend {0} not found for {1}", friendID, requester);
774 }
757 } 775 }
758 776
759 protected virtual FriendInfo GetFriend(FriendInfo[] friends, UUID friendID) 777 protected virtual FriendInfo GetFriend(FriendInfo[] friends, UUID friendID)
@@ -797,9 +815,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
797 ccm.CreateCallingCard(friendID, userID, UUID.Zero); 815 ccm.CreateCallingCard(friendID, userID, UUID.Zero);
798 } 816 }
799 817
800
801 // Update the local cache 818 // Update the local cache
802 CacheFriends(friendClient); 819 RecacheFriends(friendClient);
803 820
804 // we're done 821 // we're done
805 return true; 822 return true;
@@ -832,7 +849,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
832 // the friend in this sim as root agent 849 // the friend in this sim as root agent
833 friendClient.SendTerminateFriend(exfriendID); 850 friendClient.SendTerminateFriend(exfriendID);
834 // update local cache 851 // update local cache
835 CacheFriends(friendClient); 852 RecacheFriends(friendClient);
836 // we're done 853 // we're done
837 return true; 854 return true;
838 } 855 }
@@ -891,20 +908,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
891 #endregion 908 #endregion
892 909
893 #region Get / Set friends in several flavours 910 #region Get / Set friends in several flavours
894 /// <summary> 911
895 /// Get friends from local cache only 912 public FriendInfo[] GetFriendsFromCache(UUID userID)
896 /// </summary>
897 /// <param name="agentID"></param>
898 /// <returns>
899 /// An empty array if the user has no friends or friends have not been cached.
900 /// </returns>
901 protected FriendInfo[] GetFriends(UUID agentID)
902 { 913 {
903 UserFriendData friendsData; 914 UserFriendData friendsData;
904 915
905 lock (m_Friends) 916 lock (m_Friends)
906 { 917 {
907 if (m_Friends.TryGetValue(agentID, out friendsData)) 918 if (m_Friends.TryGetValue(userID, out friendsData))
908 return friendsData.Friends; 919 return friendsData.Friends;
909 } 920 }
910 921
@@ -922,23 +933,31 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
922 // Update local cache 933 // Update local cache
923 lock (m_Friends) 934 lock (m_Friends)
924 { 935 {
925 FriendInfo[] friends = GetFriends(friendID); 936 FriendInfo[] friends = GetFriendsFromCache(friendID);
926 FriendInfo finfo = GetFriend(friends, userID); 937 FriendInfo finfo = GetFriend(friends, userID);
927 finfo.TheirFlags = rights; 938 finfo.TheirFlags = rights;
928 } 939 }
929 } 940 }
930 941
931 protected virtual FriendInfo[] GetFriendsFromService(IClientAPI client) 942 public virtual FriendInfo[] GetFriendsFromService(IClientAPI client)
932 { 943 {
933 return FriendsService.GetFriends(client.AgentId); 944 return FriendsService.GetFriends(client.AgentId);
934 } 945 }
935 946
936 /// <summary> 947 protected void RecacheFriends(IClientAPI client)
937 /// Are friends cached on this simulator for a particular user? 948 {
938 /// </summary> 949 // FIXME: Ideally, we want to avoid doing this here since it sits the EventManager.OnMakeRootAgent event
939 /// <param name="userID"></param> 950 // is on the critical path for transferring an avatar from one region to another.
940 /// <returns></returns> 951 UUID agentID = client.AgentId;
941 protected bool AreFriendsCached(UUID userID) 952 lock (m_Friends)
953 {
954 UserFriendData friendsData;
955 if (m_Friends.TryGetValue(agentID, out friendsData))
956 friendsData.Friends = GetFriendsFromService(client);
957 }
958 }
959
960 public bool AreFriendsCached(UUID userID)
942 { 961 {
943 lock (m_Friends) 962 lock (m_Friends)
944 return m_Friends.ContainsKey(userID); 963 return m_Friends.ContainsKey(userID);
@@ -957,8 +976,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
957 976
958 protected virtual void StoreFriendships(UUID agentID, UUID friendID) 977 protected virtual void StoreFriendships(UUID agentID, UUID friendID)
959 { 978 {
960 FriendsService.StoreFriend(agentID.ToString(), friendID.ToString(), 1); 979 FriendsService.StoreFriend(agentID.ToString(), friendID.ToString(), (int)FriendRights.CanSeeOnline);
961 FriendsService.StoreFriend(friendID.ToString(), agentID.ToString(), 1); 980 FriendsService.StoreFriend(friendID.ToString(), agentID.ToString(), (int)FriendRights.CanSeeOnline);
962 } 981 }
963 982
964 protected virtual bool DeleteFriendship(UUID agentID, UUID exfriendID) 983 protected virtual bool DeleteFriendship(UUID agentID, UUID exfriendID)
@@ -969,61 +988,5 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
969 } 988 }
970 989
971 #endregion 990 #endregion
972
973 protected void HandleFriendsShowCacheCommand(string module, string[] cmd)
974 {
975 if (cmd.Length != 5)
976 {
977 MainConsole.Instance.OutputFormat("Usage: friends show cache [<first-name> <last-name>]");
978 return;
979 }
980
981 string firstName = cmd[3];
982 string lastName = cmd[4];
983
984 IUserManagement umModule = m_Scenes[0].RequestModuleInterface<IUserManagement>();
985 UUID userId = umModule.GetUserIdByName(firstName, lastName);
986
987// UserAccount ua
988// = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, firstName, lastName);
989
990 if (userId == UUID.Zero)
991 {
992 MainConsole.Instance.OutputFormat("No such user as {0} {1}", firstName, lastName);
993 return;
994 }
995
996 if (!AreFriendsCached(userId))
997 {
998 MainConsole.Instance.OutputFormat("No friends cached on this simulator for {0} {1}", firstName, lastName);
999 return;
1000 }
1001
1002 MainConsole.Instance.OutputFormat("Cached friends for {0} {1}:", firstName, lastName);
1003
1004 MainConsole.Instance.OutputFormat("UUID\n");
1005
1006 FriendInfo[] friends = GetFriends(userId);
1007
1008 foreach (FriendInfo friend in friends)
1009 {
1010// MainConsole.Instance.OutputFormat(friend.PrincipalID.ToString());
1011
1012// string friendFirstName, friendLastName;
1013//
1014// UserAccount friendUa
1015// = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, friend.PrincipalID);
1016
1017 UUID friendId;
1018 string friendName;
1019
1020 if (UUID.TryParse(friend.Friend, out friendId))
1021 friendName = umModule.GetUserName(friendId);
1022 else
1023 friendName = friend.Friend;
1024
1025 MainConsole.Instance.OutputFormat("{0} {1} {2}", friendName, friend.MyFlags, friend.TheirFlags);
1026 }
1027 }
1028 } 991 }
1029} 992}