From 59911963caa35ea9c18605ce0bee8c4e1804ac5c Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 29 Mar 2012 18:31:57 +0100 Subject: [PATCH] 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. --- OpenSim/Framework/IClientAPI.cs | 6 +-- .../ClientStack/Linden/UDP/LLClientView.cs | 13 +++--- .../Avatar/Friends/FriendsModule.cs | 40 ++++++++++--------- .../Avatar/Friends/HGFriendsModule.cs | 8 ++++ .../Avatar/Friends/Tests/FriendModuleTests.cs | 28 +++++++++++++ .../Services/Interfaces/IFriendsService.cs | 2 +- 6 files changed, 68 insertions(+), 29 deletions(-) diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index c57497f28d..fd57c0bdeb 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs @@ -296,9 +296,9 @@ namespace OpenSim.Framework public delegate void ConfirmXfer(IClientAPI remoteClient, ulong xferID, uint packetID); public delegate void FriendActionDelegate( - IClientAPI remoteClient, UUID agentID, UUID transactionID, List callingCardFolders); + IClientAPI remoteClient, UUID transactionID, List callingCardFolders); - public delegate void FriendshipTermination(IClientAPI remoteClient, UUID agentID, UUID ExID); + public delegate void FriendshipTermination(IClientAPI remoteClient, UUID ExID); public delegate void MoneyTransferRequest( UUID sourceID, UUID destID, int amount, int transactionType, string description); @@ -458,7 +458,7 @@ namespace OpenSim.Framework public delegate void AvatarNotesUpdate(IClientAPI client, UUID targetID, string notes); public delegate void MuteListRequest(IClientAPI client, uint muteCRC); public delegate void AvatarInterestUpdate(IClientAPI client, uint wantmask, string wanttext, uint skillsmask, string skillstext, string languages); - public delegate void GrantUserFriendRights(IClientAPI client, UUID requester, UUID target, int rights); + public delegate void GrantUserFriendRights(IClientAPI client, UUID target, int rights); public delegate void PlacesQuery(UUID QueryID, UUID TransactionID, string QueryText, uint QueryFlags, byte Category, string SimName, IClientAPI client); public delegate void AgentFOV(IClientAPI client, float verticalAngle); diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index 2c7b0795e0..11dd8a67f2 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs @@ -5787,7 +5787,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP // My guess is this is the folder to stick the calling card into List callingCardFolders = new List(); - UUID agentID = afriendpack.AgentData.AgentID; UUID transactionID = afriendpack.TransactionBlock.TransactionID; for (int fi = 0; fi < afriendpack.FolderData.Length; fi++) @@ -5798,10 +5797,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP FriendActionDelegate handlerApproveFriendRequest = OnApproveFriendRequest; if (handlerApproveFriendRequest != null) { - handlerApproveFriendRequest(this, agentID, transactionID, callingCardFolders); + handlerApproveFriendRequest(this, transactionID, callingCardFolders); } - return true; + return true; } private bool HandlerDeclineFriendship(IClientAPI sender, Packet Pack) @@ -5820,7 +5819,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (OnDenyFriendRequest != null) { OnDenyFriendRequest(this, - dfriendpack.AgentData.AgentID, dfriendpack.TransactionBlock.TransactionID, null); } @@ -5840,14 +5838,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP } #endregion - UUID listOwnerAgentID = tfriendpack.AgentData.AgentID; UUID exFriendID = tfriendpack.ExBlock.OtherID; FriendshipTermination TerminateFriendshipHandler = OnTerminateFriendship; if (TerminateFriendshipHandler != null) { - TerminateFriendshipHandler(this, listOwnerAgentID, exFriendID); + TerminateFriendshipHandler(this, exFriendID); return true; } + return false; } @@ -11165,12 +11163,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP return true; } #endregion + GrantUserFriendRights GrantUserRightsHandler = OnGrantUserRights; if (GrantUserRightsHandler != null) GrantUserRightsHandler(this, - GrantUserRights.AgentData.AgentID, GrantUserRights.Rights[0].AgentRelated, GrantUserRights.Rights[0].RelatedRights); + return true; } diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 7a7b0f7665..ba37798b7d 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 client.OnInstantMessage += OnInstantMessage; client.OnApproveFriendRequest += OnApproveFriendRequest; client.OnDenyFriendRequest += OnDenyFriendRequest; - client.OnTerminateFriendship += (thisClient, agentID, exfriendID) => RemoveFriendship(thisClient, exfriendID); + client.OnTerminateFriendship += RemoveFriendship; client.OnGrantUserRights += OnGrantUserRights; // 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 // Send the friends online List online = GetOnlineFriends(agentID); - if (online.Count > 0) - { - m_log.DebugFormat( - "[FRIENDS MODULE]: User {0} in region {1} has {2} friends online", - client.Name, client.Scene.RegionInfo.RegionName, online.Count); +// m_log.DebugFormat( +// "[FRIENDS MODULE]: User {0} in region {1} has {2} friends online", +// client.Name, client.Scene.RegionInfo.RegionName, online.Count); + + if (online.Count > 0) client.SendAgentOnline(online.ToArray()); - } // Send outstanding friendship offers List outstanding = new List(); @@ -495,7 +494,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends List friendList = new List(); foreach (FriendInfo fi in friends) { - if (((fi.MyFlags & 1) != 0) && (fi.TheirFlags != -1)) + if (((fi.MyFlags & (int)FriendRights.CanSeeOnline) != 0) && (fi.TheirFlags != -1)) friendList.Add(fi); } @@ -600,7 +599,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends return (account == null) ? "Unknown" : account.FirstName + " " + account.LastName; } - private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List callingCardFolders) + protected virtual void OnApproveFriendRequest(IClientAPI client, UUID friendID, List callingCardFolders) { m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", client.AgentId, friendID); @@ -645,18 +644,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } } - private void OnDenyFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List callingCardFolders) + private void OnDenyFriendRequest(IClientAPI client, UUID friendID, List callingCardFolders) { - m_log.DebugFormat("[FRIENDS]: {0} denied friendship to {1}", agentID, friendID); + m_log.DebugFormat("[FRIENDS]: {0} denied friendship to {1}", client.AgentId, friendID); - DeleteFriendship(agentID, friendID); + DeleteFriendship(client.AgentId, friendID); // // Notify the friend // // Try local - if (LocalFriendshipDenied(agentID, client.Name, friendID)) + if (LocalFriendshipDenied(client.AgentId, client.Name, friendID)) return; PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); @@ -667,7 +666,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends { GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); if (region != null) - m_FriendsSimConnector.FriendshipDenied(region, agentID, client.Name, friendID); + m_FriendsSimConnector.FriendshipDenied(region, client.AgentId, client.Name, friendID); else m_log.WarnFormat("[FRIENDS]: Could not find region {0} in locating {1}", friendSession.RegionID, friendID); } @@ -704,11 +703,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } } - private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights) + private void OnGrantUserRights(IClientAPI remoteClient, UUID target, int rights) { - m_log.DebugFormat("[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}", requester, rights, target); + UUID requester = remoteClient.AgentId; - FriendInfo[] friends = GetFriends(remoteClient.AgentId); + m_log.DebugFormat( + "[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}", + requester, rights, target); + + FriendInfo[] friends = GetFriends(requester); if (friends.Length == 0) { return; @@ -755,7 +758,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } } else + { m_log.DebugFormat("[FRIENDS MODULE]: friend {0} not found for {1}", target, requester); + } } protected virtual FriendInfo GetFriend(FriendInfo[] friends, UUID friendID) @@ -799,7 +804,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends ccm.CreateCallingCard(friendID, userID, UUID.Zero); } - // Update the local cache RecacheFriends(friendClient); diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs index 9c53fc4ac8..f83b15c827 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs @@ -94,6 +94,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends #endregion + protected override void OnApproveFriendRequest(IClientAPI client, UUID friendID, List callingCardFolders) + { + // Update the local cache. Yes, we need to do it right here + // because the HGFriendsService placed something on the DB + // from under the sim + base.OnApproveFriendRequest(client, friendID, callingCardFolders); + } + protected override bool CacheFriends(IClientAPI client) { // m_log.DebugFormat("[HGFRIENDS MODULE]: Entered CacheFriends for {0}", client.Name); diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs index 34c68cced5..94a78cbd25 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 Assert.That(((TestClient)sp1Redux.ControllingClient).ReceivedOnlineNotifications.Count, Is.EqualTo(0)); } +// [Test] +// public void TestLoginWithOnlineFriends() +// { +// TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); +// +// UUID user1Id = TestHelpers.ParseTail(0x1); +// UUID user2Id = TestHelpers.ParseTail(0x2); +// +//// UserAccountHelpers.CreateUserWithInventory(m_scene, user1Id); +//// UserAccountHelpers.CreateUserWithInventory(m_scene, user2Id); +//// +//// m_fm.AddFriendship(user1Id, user2Id); +// +// ScenePresence sp1 = SceneHelpers.AddScenePresence(m_scene, user1Id); +// SceneHelpers.AddScenePresence(m_scene, user2Id); +// +// m_fm.AddFriendship(sp1.ControllingClient, user2Id); +//// m_fm.LocalGrantRights +// +// m_scene.RemoveClient(sp1.UUID, true); +// +// ScenePresence sp1Redux = SceneHelpers.AddScenePresence(m_scene, user1Id); +// +// Assert.That(((TestClient)sp1Redux.ControllingClient).ReceivedOfflineNotifications.Count, Is.EqualTo(0)); +// Assert.That(((TestClient)sp1Redux.ControllingClient).ReceivedOnlineNotifications.Count, Is.EqualTo(1)); +// } + [Test] public void TestAddFriendshipWhileOnline() { diff --git a/OpenSim/Services/Interfaces/IFriendsService.cs b/OpenSim/Services/Interfaces/IFriendsService.cs index 1664f3b3e1..fe94242d90 100644 --- a/OpenSim/Services/Interfaces/IFriendsService.cs +++ b/OpenSim/Services/Interfaces/IFriendsService.cs @@ -51,7 +51,7 @@ namespace OpenSim.Services.Interfaces Friend = string.Empty; if (kvp.ContainsKey("Friend") && kvp["Friend"] != null) Friend = kvp["Friend"].ToString(); - MyFlags = 0; + MyFlags = (int)FriendRights.None; if (kvp.ContainsKey("MyFlags") && kvp["MyFlags"] != null) Int32.TryParse(kvp["MyFlags"].ToString(), out MyFlags); TheirFlags = 0;