aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Friends
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-03-29 18:31:57 +0100
committerJustin Clark-Casey (justincc)2012-03-29 18:31:57 +0100
commitbf09d6a22be5f8e7a2584eaa11ccbc1c61cc6753 (patch)
tree3f5c8a55d95c539fc8a4887465a1c601b32a0b44 /OpenSim/Region/CoreModules/Avatar/Friends
parentAdd simple regression test for logging in with offline friends. Don't expect... (diff)
downloadopensim-SC-bf09d6a22be5f8e7a2584eaa11ccbc1c61cc6753.zip
opensim-SC-bf09d6a22be5f8e7a2584eaa11ccbc1c61cc6753.tar.gz
opensim-SC-bf09d6a22be5f8e7a2584eaa11ccbc1c61cc6753.tar.bz2
opensim-SC-bf09d6a22be5f8e7a2584eaa11ccbc1c61cc6753.tar.xz
refactor: Stop passing both IClientAPI and agentID to friend event listeners, these are redundant. Replace a few magic numbers with FriendRights enum already used elsewhere.
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Friends')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs40
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs4
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs28
3 files changed, 52 insertions, 20 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
index 0c83679..86e04b9 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
@@ -258,7 +258,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
258 client.OnInstantMessage += OnInstantMessage; 258 client.OnInstantMessage += OnInstantMessage;
259 client.OnApproveFriendRequest += OnApproveFriendRequest; 259 client.OnApproveFriendRequest += OnApproveFriendRequest;
260 client.OnDenyFriendRequest += OnDenyFriendRequest; 260 client.OnDenyFriendRequest += OnDenyFriendRequest;
261 client.OnTerminateFriendship += (thisClient, agentID, exfriendID) => RemoveFriendship(thisClient, exfriendID); 261 client.OnTerminateFriendship += RemoveFriendship;
262 client.OnGrantUserRights += OnGrantUserRights; 262 client.OnGrantUserRights += OnGrantUserRights;
263 263
264 // We need to cache information for child agents as well as root agents so that friend edit/move/delete 264 // We need to cache information for child agents as well as root agents so that friend edit/move/delete
@@ -355,14 +355,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
355 355
356 // Send the friends online 356 // Send the friends online
357 List<UUID> online = GetOnlineFriends(agentID); 357 List<UUID> online = GetOnlineFriends(agentID);
358 if (online.Count > 0)
359 {
360 m_log.DebugFormat(
361 "[FRIENDS MODULE]: User {0} in region {1} has {2} friends online",
362 client.Name, client.Scene.RegionInfo.RegionName, online.Count);
363 358
359// m_log.DebugFormat(
360// "[FRIENDS MODULE]: User {0} in region {1} has {2} friends online",
361// client.Name, client.Scene.RegionInfo.RegionName, online.Count);
362
363 if (online.Count > 0)
364 client.SendAgentOnline(online.ToArray()); 364 client.SendAgentOnline(online.ToArray());
365 }
366 365
367 // Send outstanding friendship offers 366 // Send outstanding friendship offers
368 List<string> outstanding = new List<string>(); 367 List<string> outstanding = new List<string>();
@@ -495,7 +494,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
495 List<FriendInfo> friendList = new List<FriendInfo>(); 494 List<FriendInfo> friendList = new List<FriendInfo>();
496 foreach (FriendInfo fi in friends) 495 foreach (FriendInfo fi in friends)
497 { 496 {
498 if (((fi.MyFlags & 1) != 0) && (fi.TheirFlags != -1)) 497 if (((fi.MyFlags & (int)FriendRights.CanSeeOnline) != 0) && (fi.TheirFlags != -1))
499 friendList.Add(fi); 498 friendList.Add(fi);
500 } 499 }
501 500
@@ -614,7 +613,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
614 return (account == null) ? "Unknown" : account.FirstName + " " + account.LastName; 613 return (account == null) ? "Unknown" : account.FirstName + " " + account.LastName;
615 } 614 }
616 615
617 protected virtual void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) 616 protected virtual void OnApproveFriendRequest(IClientAPI client, UUID friendID, List<UUID> callingCardFolders)
618 { 617 {
619 m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", client.AgentId, friendID); 618 m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", client.AgentId, friendID);
620 619
@@ -659,18 +658,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
659 } 658 }
660 } 659 }
661 660
662 private void OnDenyFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) 661 private void OnDenyFriendRequest(IClientAPI client, UUID friendID, List<UUID> callingCardFolders)
663 { 662 {
664 m_log.DebugFormat("[FRIENDS]: {0} denied friendship to {1}", agentID, friendID); 663 m_log.DebugFormat("[FRIENDS]: {0} denied friendship to {1}", client.AgentId, friendID);
665 664
666 DeleteFriendship(agentID, friendID); 665 DeleteFriendship(client.AgentId, friendID);
667 666
668 // 667 //
669 // Notify the friend 668 // Notify the friend
670 // 669 //
671 670
672 // Try local 671 // Try local
673 if (LocalFriendshipDenied(agentID, client.Name, friendID)) 672 if (LocalFriendshipDenied(client.AgentId, client.Name, friendID))
674 return; 673 return;
675 674
676 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); 675 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() });
@@ -681,7 +680,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
681 { 680 {
682 GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); 681 GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID);
683 if (region != null) 682 if (region != null)
684 m_FriendsSimConnector.FriendshipDenied(region, agentID, client.Name, friendID); 683 m_FriendsSimConnector.FriendshipDenied(region, client.AgentId, client.Name, friendID);
685 else 684 else
686 m_log.WarnFormat("[FRIENDS]: Could not find region {0} in locating {1}", friendSession.RegionID, friendID); 685 m_log.WarnFormat("[FRIENDS]: Could not find region {0} in locating {1}", friendSession.RegionID, friendID);
687 } 686 }
@@ -718,11 +717,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
718 } 717 }
719 } 718 }
720 719
721 private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights) 720 private void OnGrantUserRights(IClientAPI remoteClient, UUID target, int rights)
722 { 721 {
723 m_log.DebugFormat("[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}", requester, rights, target); 722 UUID requester = remoteClient.AgentId;
724 723
725 FriendInfo[] friends = GetFriends(remoteClient.AgentId); 724 m_log.DebugFormat(
725 "[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}",
726 requester, rights, target);
727
728 FriendInfo[] friends = GetFriends(requester);
726 if (friends.Length == 0) 729 if (friends.Length == 0)
727 { 730 {
728 return; 731 return;
@@ -769,7 +772,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
769 } 772 }
770 } 773 }
771 else 774 else
775 {
772 m_log.DebugFormat("[FRIENDS MODULE]: friend {0} not found for {1}", target, requester); 776 m_log.DebugFormat("[FRIENDS MODULE]: friend {0} not found for {1}", target, requester);
777 }
773 } 778 }
774 779
775 protected virtual FriendInfo GetFriend(FriendInfo[] friends, UUID friendID) 780 protected virtual FriendInfo GetFriend(FriendInfo[] friends, UUID friendID)
@@ -813,7 +818,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
813 ccm.CreateCallingCard(friendID, userID, UUID.Zero); 818 ccm.CreateCallingCard(friendID, userID, UUID.Zero);
814 } 819 }
815 820
816
817 // Update the local cache 821 // Update the local cache
818 RecacheFriends(friendClient); 822 RecacheFriends(friendClient);
819 823
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
index e50a84a..b666dae 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
@@ -105,12 +105,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
105 105
106 #endregion 106 #endregion
107 107
108 protected override void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) 108 protected override void OnApproveFriendRequest(IClientAPI client, UUID friendID, List<UUID> callingCardFolders)
109 { 109 {
110 // Update the local cache. Yes, we need to do it right here 110 // Update the local cache. Yes, we need to do it right here
111 // because the HGFriendsService placed something on the DB 111 // because the HGFriendsService placed something on the DB
112 // from under the sim 112 // from under the sim
113 base.OnApproveFriendRequest(client, agentID, friendID, callingCardFolders); 113 base.OnApproveFriendRequest(client, friendID, callingCardFolders);
114 } 114 }
115 115
116 protected override bool CacheFriends(IClientAPI client) 116 protected override bool CacheFriends(IClientAPI client)
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs
index 34c68cc..94a78cb 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs
@@ -120,6 +120,34 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends.Tests
120 Assert.That(((TestClient)sp1Redux.ControllingClient).ReceivedOnlineNotifications.Count, Is.EqualTo(0)); 120 Assert.That(((TestClient)sp1Redux.ControllingClient).ReceivedOnlineNotifications.Count, Is.EqualTo(0));
121 } 121 }
122 122
123// [Test]
124// public void TestLoginWithOnlineFriends()
125// {
126// TestHelpers.InMethod();
127// log4net.Config.XmlConfigurator.Configure();
128//
129// UUID user1Id = TestHelpers.ParseTail(0x1);
130// UUID user2Id = TestHelpers.ParseTail(0x2);
131//
132//// UserAccountHelpers.CreateUserWithInventory(m_scene, user1Id);
133//// UserAccountHelpers.CreateUserWithInventory(m_scene, user2Id);
134////
135//// m_fm.AddFriendship(user1Id, user2Id);
136//
137// ScenePresence sp1 = SceneHelpers.AddScenePresence(m_scene, user1Id);
138// SceneHelpers.AddScenePresence(m_scene, user2Id);
139//
140// m_fm.AddFriendship(sp1.ControllingClient, user2Id);
141//// m_fm.LocalGrantRights
142//
143// m_scene.RemoveClient(sp1.UUID, true);
144//
145// ScenePresence sp1Redux = SceneHelpers.AddScenePresence(m_scene, user1Id);
146//
147// Assert.That(((TestClient)sp1Redux.ControllingClient).ReceivedOfflineNotifications.Count, Is.EqualTo(0));
148// Assert.That(((TestClient)sp1Redux.ControllingClient).ReceivedOnlineNotifications.Count, Is.EqualTo(1));
149// }
150
123 [Test] 151 [Test]
124 public void TestAddFriendshipWhileOnline() 152 public void TestAddFriendshipWhileOnline()
125 { 153 {