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.

0.7.3-extended
Justin Clark-Casey (justincc) 2012-03-29 18:31:57 +01:00
parent dc2a4a6ccd
commit 59911963ca
6 changed files with 68 additions and 29 deletions

View File

@ -296,9 +296,9 @@ namespace OpenSim.Framework
public delegate void ConfirmXfer(IClientAPI remoteClient, ulong xferID, uint packetID); public delegate void ConfirmXfer(IClientAPI remoteClient, ulong xferID, uint packetID);
public delegate void FriendActionDelegate( public delegate void FriendActionDelegate(
IClientAPI remoteClient, UUID agentID, UUID transactionID, List<UUID> callingCardFolders); IClientAPI remoteClient, UUID transactionID, List<UUID> callingCardFolders);
public delegate void FriendshipTermination(IClientAPI remoteClient, UUID agentID, UUID ExID); public delegate void FriendshipTermination(IClientAPI remoteClient, UUID ExID);
public delegate void MoneyTransferRequest( public delegate void MoneyTransferRequest(
UUID sourceID, UUID destID, int amount, int transactionType, string description); 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 AvatarNotesUpdate(IClientAPI client, UUID targetID, string notes);
public delegate void MuteListRequest(IClientAPI client, uint muteCRC); 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 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 PlacesQuery(UUID QueryID, UUID TransactionID, string QueryText, uint QueryFlags, byte Category, string SimName, IClientAPI client);
public delegate void AgentFOV(IClientAPI client, float verticalAngle); public delegate void AgentFOV(IClientAPI client, float verticalAngle);

View File

@ -5787,7 +5787,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// My guess is this is the folder to stick the calling card into // My guess is this is the folder to stick the calling card into
List<UUID> callingCardFolders = new List<UUID>(); List<UUID> callingCardFolders = new List<UUID>();
UUID agentID = afriendpack.AgentData.AgentID;
UUID transactionID = afriendpack.TransactionBlock.TransactionID; UUID transactionID = afriendpack.TransactionBlock.TransactionID;
for (int fi = 0; fi < afriendpack.FolderData.Length; fi++) for (int fi = 0; fi < afriendpack.FolderData.Length; fi++)
@ -5798,10 +5797,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
FriendActionDelegate handlerApproveFriendRequest = OnApproveFriendRequest; FriendActionDelegate handlerApproveFriendRequest = OnApproveFriendRequest;
if (handlerApproveFriendRequest != null) if (handlerApproveFriendRequest != null)
{ {
handlerApproveFriendRequest(this, agentID, transactionID, callingCardFolders); handlerApproveFriendRequest(this, transactionID, callingCardFolders);
} }
return true;
return true;
} }
private bool HandlerDeclineFriendship(IClientAPI sender, Packet Pack) private bool HandlerDeclineFriendship(IClientAPI sender, Packet Pack)
@ -5820,7 +5819,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (OnDenyFriendRequest != null) if (OnDenyFriendRequest != null)
{ {
OnDenyFriendRequest(this, OnDenyFriendRequest(this,
dfriendpack.AgentData.AgentID,
dfriendpack.TransactionBlock.TransactionID, dfriendpack.TransactionBlock.TransactionID,
null); null);
} }
@ -5840,14 +5838,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
} }
#endregion #endregion
UUID listOwnerAgentID = tfriendpack.AgentData.AgentID;
UUID exFriendID = tfriendpack.ExBlock.OtherID; UUID exFriendID = tfriendpack.ExBlock.OtherID;
FriendshipTermination TerminateFriendshipHandler = OnTerminateFriendship; FriendshipTermination TerminateFriendshipHandler = OnTerminateFriendship;
if (TerminateFriendshipHandler != null) if (TerminateFriendshipHandler != null)
{ {
TerminateFriendshipHandler(this, listOwnerAgentID, exFriendID); TerminateFriendshipHandler(this, exFriendID);
return true; return true;
} }
return false; return false;
} }
@ -11165,12 +11163,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
return true; return true;
} }
#endregion #endregion
GrantUserFriendRights GrantUserRightsHandler = OnGrantUserRights; GrantUserFriendRights GrantUserRightsHandler = OnGrantUserRights;
if (GrantUserRightsHandler != null) if (GrantUserRightsHandler != null)
GrantUserRightsHandler(this, GrantUserRightsHandler(this,
GrantUserRights.AgentData.AgentID,
GrantUserRights.Rights[0].AgentRelated, GrantUserRights.Rights[0].AgentRelated,
GrantUserRights.Rights[0].RelatedRights); GrantUserRights.Rights[0].RelatedRights);
return true; return true;
} }

View File

@ -258,7 +258,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
client.OnInstantMessage += OnInstantMessage; client.OnInstantMessage += OnInstantMessage;
client.OnApproveFriendRequest += OnApproveFriendRequest; client.OnApproveFriendRequest += OnApproveFriendRequest;
client.OnDenyFriendRequest += OnDenyFriendRequest; client.OnDenyFriendRequest += OnDenyFriendRequest;
client.OnTerminateFriendship += (thisClient, agentID, exfriendID) => RemoveFriendship(thisClient, exfriendID); client.OnTerminateFriendship += RemoveFriendship;
client.OnGrantUserRights += OnGrantUserRights; client.OnGrantUserRights += OnGrantUserRights;
// We need to cache information for child agents as well as root agents so that friend edit/move/delete // 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 // Send the friends online
List<UUID> online = GetOnlineFriends(agentID); List<UUID> 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()); client.SendAgentOnline(online.ToArray());
}
// Send outstanding friendship offers // Send outstanding friendship offers
List<string> outstanding = new List<string>(); List<string> outstanding = new List<string>();
@ -495,7 +494,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
List<FriendInfo> friendList = new List<FriendInfo>(); List<FriendInfo> friendList = new List<FriendInfo>();
foreach (FriendInfo fi in friends) 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); friendList.Add(fi);
} }
@ -600,7 +599,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
return (account == null) ? "Unknown" : account.FirstName + " " + account.LastName; return (account == null) ? "Unknown" : account.FirstName + " " + account.LastName;
} }
private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) protected virtual void OnApproveFriendRequest(IClientAPI client, UUID friendID, List<UUID> callingCardFolders)
{ {
m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", client.AgentId, friendID); 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<UUID> callingCardFolders) private void OnDenyFriendRequest(IClientAPI client, UUID friendID, List<UUID> 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 // Notify the friend
// //
// Try local // Try local
if (LocalFriendshipDenied(agentID, client.Name, friendID)) if (LocalFriendshipDenied(client.AgentId, client.Name, friendID))
return; return;
PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); 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); GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID);
if (region != null) if (region != null)
m_FriendsSimConnector.FriendshipDenied(region, agentID, client.Name, friendID); m_FriendsSimConnector.FriendshipDenied(region, client.AgentId, client.Name, friendID);
else else
m_log.WarnFormat("[FRIENDS]: Could not find region {0} in locating {1}", friendSession.RegionID, friendID); 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) if (friends.Length == 0)
{ {
return; return;
@ -755,7 +758,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
} }
} }
else else
{
m_log.DebugFormat("[FRIENDS MODULE]: friend {0} not found for {1}", target, requester); m_log.DebugFormat("[FRIENDS MODULE]: friend {0} not found for {1}", target, requester);
}
} }
protected virtual FriendInfo GetFriend(FriendInfo[] friends, UUID friendID) protected virtual FriendInfo GetFriend(FriendInfo[] friends, UUID friendID)
@ -799,7 +804,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
ccm.CreateCallingCard(friendID, userID, UUID.Zero); ccm.CreateCallingCard(friendID, userID, UUID.Zero);
} }
// Update the local cache // Update the local cache
RecacheFriends(friendClient); RecacheFriends(friendClient);

View File

@ -94,6 +94,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
#endregion #endregion
protected override void OnApproveFriendRequest(IClientAPI client, UUID friendID, List<UUID> 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) protected override bool CacheFriends(IClientAPI client)
{ {
// m_log.DebugFormat("[HGFRIENDS MODULE]: Entered CacheFriends for {0}", client.Name); // m_log.DebugFormat("[HGFRIENDS MODULE]: Entered CacheFriends for {0}", client.Name);

View File

@ -120,6 +120,34 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends.Tests
Assert.That(((TestClient)sp1Redux.ControllingClient).ReceivedOnlineNotifications.Count, Is.EqualTo(0)); 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] [Test]
public void TestAddFriendshipWhileOnline() public void TestAddFriendshipWhileOnline()
{ {

View File

@ -51,7 +51,7 @@ namespace OpenSim.Services.Interfaces
Friend = string.Empty; Friend = string.Empty;
if (kvp.ContainsKey("Friend") && kvp["Friend"] != null) if (kvp.ContainsKey("Friend") && kvp["Friend"] != null)
Friend = kvp["Friend"].ToString(); Friend = kvp["Friend"].ToString();
MyFlags = 0; MyFlags = (int)FriendRights.None;
if (kvp.ContainsKey("MyFlags") && kvp["MyFlags"] != null) if (kvp.ContainsKey("MyFlags") && kvp["MyFlags"] != null)
Int32.TryParse(kvp["MyFlags"].ToString(), out MyFlags); Int32.TryParse(kvp["MyFlags"].ToString(), out MyFlags);
TheirFlags = 0; TheirFlags = 0;