Revert "Simplify friends caching by only doing this for root agents - no functions require caching for child agents."

We need to cache child agents so that friends object edit/delete permissions will work across boarders on regions hosted by different simulators.

This reverts commit d9f7b8549b.
0.7.4.1
Justin Clark-Casey (justincc) 2012-03-29 01:08:47 +01:00
parent a1de9bc33f
commit 93ac47f0d3
9 changed files with 55 additions and 31 deletions

View File

@ -710,7 +710,7 @@ namespace OpenSim.Framework
/// The scene agent for this client. This will only be set if the client has an agent in a scene (i.e. if it /// The scene agent for this client. This will only be set if the client has an agent in a scene (i.e. if it
/// is connected). /// is connected).
/// </summary> /// </summary>
ISceneAgent SceneAgent { get; set; } ISceneAgent SceneAgent { get; }
UUID SessionId { get; } UUID SessionId { get; }

View File

@ -384,7 +384,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
set { m_startpos = value; } set { m_startpos = value; }
} }
public UUID AgentId { get { return m_agentId; } } public UUID AgentId { get { return m_agentId; } }
public ISceneAgent SceneAgent { get; set; } public ISceneAgent SceneAgent { get; private set; }
public UUID ActiveGroupId { get { return m_activeGroupID; } } public UUID ActiveGroupId { get { return m_activeGroupID; } }
public string ActiveGroupName { get { return m_activeGroupName; } } public string ActiveGroupName { get { return m_activeGroupName; } }
public ulong ActiveGroupPowers { get { return m_activeGroupPowers; } } public ulong ActiveGroupPowers { get { return m_activeGroupPowers; } }
@ -695,7 +695,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public virtual void Start() public virtual void Start()
{ {
m_scene.AddNewClient(this, PresenceType.User); SceneAgent = m_scene.AddNewClient(this, PresenceType.User);
RefreshGroupMembership(); RefreshGroupMembership();
} }

View File

@ -57,6 +57,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
{ {
public UUID PrincipalID; public UUID PrincipalID;
public FriendInfo[] Friends; public FriendInfo[] Friends;
public int Refcount;
public bool IsFriend(string friend) public bool IsFriend(string friend)
{ {
@ -254,9 +255,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
private void OnNewClient(IClientAPI client) private void OnNewClient(IClientAPI client)
{ {
if (client.SceneAgent.IsChildAgent)
return;
client.OnInstantMessage += OnInstantMessage; client.OnInstantMessage += OnInstantMessage;
client.OnApproveFriendRequest += OnApproveFriendRequest; client.OnApproveFriendRequest += OnApproveFriendRequest;
client.OnDenyFriendRequest += OnDenyFriendRequest; client.OnDenyFriendRequest += OnDenyFriendRequest;
@ -283,15 +281,24 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
UUID agentID = client.AgentId; UUID agentID = client.AgentId;
lock (m_Friends) lock (m_Friends)
{ {
UserFriendData friendsData = new UserFriendData(); UserFriendData friendsData;
if (m_Friends.TryGetValue(agentID, out friendsData))
{
friendsData.Refcount++;
return false;
}
else
{
friendsData = new UserFriendData();
friendsData.PrincipalID = agentID; friendsData.PrincipalID = agentID;
friendsData.Friends = GetFriendsFromService(client); friendsData.Friends = GetFriendsFromService(client);
friendsData.Refcount = 1;
m_Friends[agentID] = friendsData; m_Friends[agentID] = friendsData;
}
return true; return true;
} }
}
}
private void OnClientClosed(UUID agentID, Scene scene) private void OnClientClosed(UUID agentID, Scene scene)
{ {
@ -300,17 +307,23 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
{ {
// do this for root agents closing out // do this for root agents closing out
StatusChange(agentID, false); StatusChange(agentID, false);
}
lock (m_Friends) lock (m_Friends)
{
UserFriendData friendsData;
if (m_Friends.TryGetValue(agentID, out friendsData))
{
friendsData.Refcount--;
if (friendsData.Refcount <= 0)
m_Friends.Remove(agentID); m_Friends.Remove(agentID);
} }
} }
}
private void OnMakeRootAgent(ScenePresence sp) private void OnMakeRootAgent(ScenePresence sp)
{ {
// FIXME: Ideally, we want to avoid doing this here since it sits the EventManager.OnMakeRootAgent event RecacheFriends(sp.ControllingClient);
// is on the critical path for transferring an avatar from one region to another.
CacheFriends(sp.ControllingClient);
} }
private void OnClientLogin(IClientAPI client) private void OnClientLogin(IClientAPI client)
@ -616,7 +629,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
} }
// Update the local cache. // Update the local cache.
CacheFriends(client); RecacheFriends(client);
// //
// Notify the friend // Notify the friend
@ -678,7 +691,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
client.SendAlertMessage("Unable to terminate friendship on this sim."); client.SendAlertMessage("Unable to terminate friendship on this sim.");
// Update local cache // Update local cache
CacheFriends(client); RecacheFriends(client);
client.SendTerminateFriend(exfriendID); client.SendTerminateFriend(exfriendID);
@ -799,7 +812,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
// Update the local cache // Update the local cache
CacheFriends(friendClient); RecacheFriends(friendClient);
// we're done // we're done
return true; return true;
@ -832,7 +845,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
// the friend in this sim as root agent // the friend in this sim as root agent
friendClient.SendTerminateFriend(exfriendID); friendClient.SendTerminateFriend(exfriendID);
// update local cache // update local cache
CacheFriends(friendClient); RecacheFriends(friendClient);
// we're done // we're done
return true; return true;
} }
@ -933,6 +946,19 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
return FriendsService.GetFriends(client.AgentId); return FriendsService.GetFriends(client.AgentId);
} }
protected void RecacheFriends(IClientAPI client)
{
// FIXME: Ideally, we want to avoid doing this here since it sits the EventManager.OnMakeRootAgent event
// is on the critical path for transferring an avatar from one region to another.
UUID agentID = client.AgentId;
lock (m_Friends)
{
UserFriendData friendsData;
if (m_Friends.TryGetValue(agentID, out friendsData))
friendsData.Friends = GetFriendsFromService(client);
}
}
/// <summary> /// <summary>
/// Are friends cached on this simulator for a particular user? /// Are friends cached on this simulator for a particular user?
/// </summary> /// </summary>

View File

@ -121,7 +121,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
{ {
UUID agentID = client.AgentId; UUID agentID = client.AgentId;
// we do this only for the root agent // we do this only for the root agent
if (!client.SceneAgent.IsChildAgent) if (m_Friends[agentID].Refcount == 1)
{ {
// We need to preload the user management cache with the names // We need to preload the user management cache with the names
// of foreign friends, just like we do with SOPs' creators // of foreign friends, just like we do with SOPs' creators
@ -426,14 +426,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
agentClientCircuit = ((Scene)(agentClient.Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.CircuitCode); agentClientCircuit = ((Scene)(agentClient.Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.CircuitCode);
agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit); agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit);
agentFriendService = agentClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); agentFriendService = agentClientCircuit.ServiceURLs["FriendsServerURI"].ToString();
CacheFriends(agentClient); RecacheFriends(agentClient);
} }
if (friendClient != null) if (friendClient != null)
{ {
friendClientCircuit = ((Scene)(friendClient.Scene)).AuthenticateHandler.GetAgentCircuitData(friendClient.CircuitCode); friendClientCircuit = ((Scene)(friendClient.Scene)).AuthenticateHandler.GetAgentCircuitData(friendClient.CircuitCode);
friendUUI = Util.ProduceUserUniversalIdentifier(friendClientCircuit); friendUUI = Util.ProduceUserUniversalIdentifier(friendClientCircuit);
friendFriendService = friendClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); friendFriendService = friendClientCircuit.ServiceURLs["FriendsServerURI"].ToString();
CacheFriends(friendClient); RecacheFriends(friendClient);
} }
m_log.DebugFormat("[HGFRIENDS MODULE] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}", m_log.DebugFormat("[HGFRIENDS MODULE] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}",

View File

@ -71,7 +71,6 @@ namespace OpenSim.Region.Framework.Scenes
/// Triggered when a new client is added to the scene. /// Triggered when a new client is added to the scene.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This is triggered for both child and root agent client connections.
/// Triggered before OnClientLogin. /// Triggered before OnClientLogin.
/// </remarks> /// </remarks>
public event OnNewClientDelegate OnNewClient; public event OnNewClientDelegate OnNewClient;
@ -192,7 +191,7 @@ namespace OpenSim.Region.Framework.Scenes
public delegate void ClientClosed(UUID clientID, Scene scene); public delegate void ClientClosed(UUID clientID, Scene scene);
/// <summary> /// <summary>
/// Fired when a client is removed from a scene whether it's a child or a root agent. /// Fired when a client is removed from a scene.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// At the point of firing, the scene still contains the client's scene presence. /// At the point of firing, the scene still contains the client's scene presence.

View File

@ -2670,7 +2670,6 @@ namespace OpenSim.Region.Framework.Scenes
sp.IsChildAgent ? "child" : "root", sp.Name, RegionInfo.RegionName); sp.IsChildAgent ? "child" : "root", sp.Name, RegionInfo.RegionName);
} }
client.SceneAgent = sp;
m_LastLogin = Util.EnvironmentTickCount(); m_LastLogin = Util.EnvironmentTickCount();
// Cache the user's name // Cache the user's name

View File

@ -55,7 +55,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
private UUID m_agentID = UUID.Random(); private UUID m_agentID = UUID.Random();
public ISceneAgent SceneAgent { get; set; } public ISceneAgent SceneAgent { get; private set; }
private string m_username; private string m_username;
private string m_nick; private string m_nick;
@ -895,7 +895,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
public void Start() public void Start()
{ {
m_scene.AddNewClient(this, PresenceType.User); SceneAgent = m_scene.AddNewClient(this, PresenceType.User);
// Mimicking LLClientView which gets always set appearance from client. // Mimicking LLClientView which gets always set appearance from client.
AvatarAppearance appearance; AvatarAppearance appearance;

View File

@ -72,7 +72,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
get { return m_ownerID; } get { return m_ownerID; }
} }
public ISceneAgent SceneAgent { get; set; } public ISceneAgent SceneAgent { get { throw new NotImplementedException(); } }
public void Say(string message) public void Say(string message)
{ {

View File

@ -327,7 +327,7 @@ namespace OpenSim.Tests.Common.Mock
/// </value> /// </value>
private UUID m_agentId; private UUID m_agentId;
public ISceneAgent SceneAgent { get; set; } public ISceneAgent SceneAgent { get { throw new NotImplementedException(); } }
/// <value> /// <value>
/// The last caps seed url that this client was given. /// The last caps seed url that this client was given.