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.

This commit is contained in:
Justin Clark-Casey (justincc)
2012-03-29 18:31:57 +01:00
parent 012b01f224
commit bf09d6a22b
6 changed files with 62 additions and 31 deletions

View File

@@ -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<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());
}
// Send outstanding friendship offers
List<string> outstanding = new List<string>();
@@ -495,7 +494,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
List<FriendInfo> friendList = new List<FriendInfo>();
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);
}
@@ -614,7 +613,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
return (account == null) ? "Unknown" : account.FirstName + " " + account.LastName;
}
protected virtual 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);
@@ -659,18 +658,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
//
// Try local
if (LocalFriendshipDenied(agentID, client.Name, friendID))
if (LocalFriendshipDenied(client.AgentId, client.Name, friendID))
return;
PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() });
@@ -681,7 +680,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);
}
@@ -718,11 +717,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;
@@ -769,7 +772,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)
@@ -813,7 +818,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
ccm.CreateCallingCard(friendID, userID, UUID.Zero);
}
// Update the local cache
RecacheFriends(friendClient);

View File

@@ -105,12 +105,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
#endregion
protected override void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders)
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, agentID, friendID, callingCardFolders);
base.OnApproveFriendRequest(client, friendID, callingCardFolders);
}
protected override bool CacheFriends(IClientAPI client)

View File

@@ -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()
{