Better friends notification: get rid of OnLogout and use OnClientClose for sending notifications. This takes care of crashed sessions. Also, made the notifications themselves asynchronous.

soprefactor
Diva Canto 2010-06-11 06:32:24 -07:00
parent 2e1269e4ca
commit 7f349d61cb
1 changed files with 14 additions and 23 deletions

View File

@ -220,8 +220,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
client.OnGrantUserRights += OnGrantUserRights; client.OnGrantUserRights += OnGrantUserRights;
client.OnLogout += OnLogout;
lock (m_Friends) lock (m_Friends)
{ {
if (m_Friends.ContainsKey(client.AgentId)) if (m_Friends.ContainsKey(client.AgentId))
@ -240,36 +238,25 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
m_Friends.Add(client.AgentId, newFriends); m_Friends.Add(client.AgentId, newFriends);
} }
//StatusChange(client.AgentId, true);
} }
private void OnClientClosed(UUID agentID, Scene scene) private void OnClientClosed(UUID agentID, Scene scene)
{ {
ScenePresence sp = scene.GetScenePresence(agentID); ScenePresence sp = scene.GetScenePresence(agentID);
if (sp != null && !sp.IsChildAgent)
// do this for root agents closing out
StatusChange(agentID, false);
lock (m_Friends) lock (m_Friends)
if (m_Friends.ContainsKey(agentID)) if (m_Friends.ContainsKey(agentID))
{ {
if (m_Friends[agentID].Refcount == 1) if (m_Friends[agentID].Refcount == 1)
{
if (sp != null && sp.IsChildAgent)
// we do this only for child agents
// Root agents' closing = logout; that's
// processed with OnLogout
{
m_Friends.Remove(agentID); m_Friends.Remove(agentID);
}
}
else else
m_Friends[agentID].Refcount--; m_Friends[agentID].Refcount--;
} }
} }
private void OnLogout(IClientAPI client)
{
StatusChange(client.AgentId, false);
m_Friends.Remove(client.AgentId);
}
private void OnMakeRootAgent(ScenePresence sp) private void OnMakeRootAgent(ScenePresence sp)
{ {
UUID agentID = sp.ControllingClient.AgentId; UUID agentID = sp.ControllingClient.AgentId;
@ -457,12 +444,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
if (((fi.MyFlags & 1) != 0) && (fi.TheirFlags != -1)) if (((fi.MyFlags & 1) != 0) && (fi.TheirFlags != -1))
friendList.Add(fi); friendList.Add(fi);
} }
Util.FireAndForget(delegate
{
foreach (FriendInfo fi in friendList) foreach (FriendInfo fi in friendList)
{ {
//m_log.DebugFormat("[FRIENDS]: Notifying {0}", fi.PrincipalID); //m_log.DebugFormat("[FRIENDS]: Notifying {0}", fi.PrincipalID);
// Notify about this user status // Notify about this user status
StatusNotify(fi, agentID, online); StatusNotify(fi, agentID, online);
} }
});
} }
else else
m_log.WarnFormat("[FRIENDS]: {0} not found in cache", agentID); m_log.WarnFormat("[FRIENDS]: {0} not found in cache", agentID);