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.cs107
1 files changed, 61 insertions, 46 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
index 4879d20..7d94813 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
@@ -272,11 +272,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
272 } 272 }
273 } 273 }
274 274
275 protected virtual FriendInfo[] GetFriendsFromService(IClientAPI client)
276 {
277 return FriendsService.GetFriends(client.AgentId);
278 }
279
280 private void OnClientClosed(UUID agentID, Scene scene) 275 private void OnClientClosed(UUID agentID, Scene scene)
281 { 276 {
282 ScenePresence sp = scene.GetScenePresence(agentID); 277 ScenePresence sp = scene.GetScenePresence(agentID);
@@ -300,7 +295,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
300 295
301 private void OnMakeRootAgent(ScenePresence sp) 296 private void OnMakeRootAgent(ScenePresence sp)
302 { 297 {
303 UpdateFriendsCache(sp.ControllingClient); 298 RefetchFriends(sp.ControllingClient);
304 } 299 }
305 300
306 private void OnClientLogin(IClientAPI client) 301 private void OnClientLogin(IClientAPI client)
@@ -544,11 +539,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
544 } 539 }
545 } 540 }
546 541
547 protected virtual void StoreBackwards(UUID friendID, UUID agentID)
548 {
549 FriendsService.StoreFriend(friendID.ToString(), agentID.ToString(), 0);
550 }
551
552 private void ForwardFriendshipOffer(UUID agentID, UUID friendID, GridInstantMessage im) 542 private void ForwardFriendshipOffer(UUID agentID, UUID friendID, GridInstantMessage im)
553 { 543 {
554 // !!!!!!!! This is a hack so that we don't have to keep state (transactionID/imSessionID) 544 // !!!!!!!! This is a hack so that we don't have to keep state (transactionID/imSessionID)
@@ -587,7 +577,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
587 StoreFriendships(agentID, friendID); 577 StoreFriendships(agentID, friendID);
588 578
589 // Update the local cache 579 // Update the local cache
590 UpdateFriendsCache(client); 580 RefetchFriends(client);
591 581
592 // 582 //
593 // Notify the friend 583 // Notify the friend
@@ -614,18 +604,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
614 } 604 }
615 } 605 }
616 606
617 protected virtual void StoreFriendships(UUID agentID, UUID friendID)
618 {
619 FriendsService.StoreFriend(agentID.ToString(), friendID.ToString(), 1);
620 FriendsService.StoreFriend(friendID.ToString(), agentID.ToString(), 1);
621 }
622
623 private void OnDenyFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) 607 private void OnDenyFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders)
624 { 608 {
625 m_log.DebugFormat("[FRIENDS]: {0} denied friendship to {1}", agentID, friendID); 609 m_log.DebugFormat("[FRIENDS]: {0} denied friendship to {1}", agentID, friendID);
626 610
627 FriendsService.Delete(agentID, friendID.ToString()); 611 DeleteFriendship(agentID, friendID);
628 FriendsService.Delete(friendID, agentID.ToString());
629 612
630 // 613 //
631 // Notify the friend 614 // Notify the friend
@@ -652,10 +635,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
652 635
653 private void OnTerminateFriendship(IClientAPI client, UUID agentID, UUID exfriendID) 636 private void OnTerminateFriendship(IClientAPI client, UUID agentID, UUID exfriendID)
654 { 637 {
655 DeleteFriendship(agentID, exfriendID); 638 if (!DeleteFriendship(agentID, exfriendID))
639 client.SendAlertMessage("Unable to terminate friendship on this sim.");
656 640
657 // Update local cache 641 // Update local cache
658 UpdateFriendsCache(client); 642 RefetchFriends(client);
659 643
660 client.SendTerminateFriend(exfriendID); 644 client.SendTerminateFriend(exfriendID);
661 645
@@ -679,12 +663,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
679 } 663 }
680 } 664 }
681 665
682 protected virtual void DeleteFriendship(UUID agentID, UUID exfriendID)
683 {
684 FriendsService.Delete(agentID, exfriendID.ToString());
685 FriendsService.Delete(exfriendID, agentID.ToString());
686 }
687
688 private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights) 666 private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights)
689 { 667 {
690 m_log.DebugFormat("[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}", requester, rights, target); 668 m_log.DebugFormat("[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}", requester, rights, target);
@@ -702,7 +680,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
702 if (friend != null) // Found it 680 if (friend != null) // Found it
703 { 681 {
704 // Store it on the DB 682 // Store it on the DB
705 if (!SimpleStore(requester, target, rights)) 683 if (!StoreRights(requester, target, rights))
706 { 684 {
707 remoteClient.SendAlertMessage("Unable to grant rights."); 685 remoteClient.SendAlertMessage("Unable to grant rights.");
708 return; 686 return;
@@ -740,12 +718,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
740 m_log.DebugFormat("[FRIENDS MODULE]: friend {0} not found for {1}", target, requester); 718 m_log.DebugFormat("[FRIENDS MODULE]: friend {0} not found for {1}", target, requester);
741 } 719 }
742 720
743 protected virtual bool SimpleStore(UUID agentID, UUID friendID, int rights)
744 {
745 FriendsService.StoreFriend(agentID.ToString(), friendID.ToString(), rights);
746 return true;
747 }
748
749 protected virtual FriendInfo GetFriend(FriendInfo[] friends, UUID friendID) 721 protected virtual FriendInfo GetFriend(FriendInfo[] friends, UUID friendID)
750 { 722 {
751 foreach (FriendInfo fi in friends) 723 foreach (FriendInfo fi in friends)
@@ -782,7 +754,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
782 friendClient.SendInstantMessage(im); 754 friendClient.SendInstantMessage(im);
783 755
784 // Update the local cache 756 // Update the local cache
785 UpdateFriendsCache(friendClient); 757 RefetchFriends(friendClient);
786 758
787 // we're done 759 // we're done
788 return true; 760 return true;
@@ -815,7 +787,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
815 // the friend in this sim as root agent 787 // the friend in this sim as root agent
816 friendClient.SendTerminateFriend(exfriendID); 788 friendClient.SendTerminateFriend(exfriendID);
817 // update local cache 789 // update local cache
818 UpdateFriendsCache(friendClient); 790 RefetchFriends(friendClient);
819 // we're done 791 // we're done
820 return true; 792 return true;
821 } 793 }
@@ -874,6 +846,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
874 846
875 #endregion 847 #endregion
876 848
849 #region Get / Set friends in several flavours
850 /// <summary>
851 /// Get friends from local cache only
852 /// </summary>
853 /// <param name="agentID"></param>
854 /// <returns></returns>
877 protected FriendInfo[] GetFriends(UUID agentID) 855 protected FriendInfo[] GetFriends(UUID agentID)
878 { 856 {
879 UserFriendData friendsData; 857 UserFriendData friendsData;
@@ -887,7 +865,29 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
887 return EMPTY_FRIENDS; 865 return EMPTY_FRIENDS;
888 } 866 }
889 867
890 private void UpdateFriendsCache(IClientAPI client) 868 /// <summary>
869 /// Update loca cache only
870 /// </summary>
871 /// <param name="userID"></param>
872 /// <param name="friendID"></param>
873 /// <param name="rights"></param>
874 protected void UpdateLocalCache(UUID userID, UUID friendID, int rights)
875 {
876 // Update local cache
877 lock (m_Friends)
878 {
879 FriendInfo[] friends = GetFriends(friendID);
880 FriendInfo finfo = GetFriend(friends, userID);
881 finfo.TheirFlags = rights;
882 }
883 }
884
885 protected virtual FriendInfo[] GetFriendsFromService(IClientAPI client)
886 {
887 return FriendsService.GetFriends(client.AgentId);
888 }
889
890 private void RefetchFriends(IClientAPI client)
891 { 891 {
892 UUID agentID = client.AgentId; 892 UUID agentID = client.AgentId;
893 lock (m_Friends) 893 lock (m_Friends)
@@ -898,15 +898,30 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
898 } 898 }
899 } 899 }
900 900
901 protected void UpdateLocalCache(UUID userID, UUID friendID, int rights) 901 protected virtual bool StoreRights(UUID agentID, UUID friendID, int rights)
902 { 902 {
903 // Update local cache 903 FriendsService.StoreFriend(agentID.ToString(), friendID.ToString(), rights);
904 lock (m_Friends) 904 return true;
905 {
906 FriendInfo[] friends = GetFriends(friendID);
907 FriendInfo finfo = GetFriend(friends, userID);
908 finfo.TheirFlags = rights;
909 }
910 } 905 }
906
907 protected virtual void StoreBackwards(UUID friendID, UUID agentID)
908 {
909 FriendsService.StoreFriend(friendID.ToString(), agentID.ToString(), 0);
910 }
911
912 protected virtual void StoreFriendships(UUID agentID, UUID friendID)
913 {
914 FriendsService.StoreFriend(agentID.ToString(), friendID.ToString(), 1);
915 FriendsService.StoreFriend(friendID.ToString(), agentID.ToString(), 1);
916 }
917
918 protected virtual bool DeleteFriendship(UUID agentID, UUID exfriendID)
919 {
920 FriendsService.Delete(agentID, exfriendID.ToString());
921 FriendsService.Delete(exfriendID, agentID.ToString());
922 return true;
923 }
924
925 #endregion
911 } 926 }
912} 927}