Merge branch 'master' into careminster-presence-refactor

This commit is contained in:
Melanie
2010-06-11 17:46:29 +01:00
5 changed files with 122 additions and 96 deletions

View File

@@ -221,8 +221,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
client.OnGrantUserRights += OnGrantUserRights;
client.OnLogout += OnLogout;
lock (m_Friends)
{
if (m_Friends.ContainsKey(client.AgentId))
@@ -241,11 +239,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
m_Friends.Add(client.AgentId, newFriends);
}
//StatusChange(client.AgentId, true);
}
private void OnClientClosed(UUID agentID, Scene scene)
{
ScenePresence sp = scene.GetScenePresence(agentID);
if (sp != null && !sp.IsChildAgent)
// do this for root agents closing out
StatusChange(agentID, false);
lock (m_Friends)
if (m_Friends.ContainsKey(agentID))
{
@@ -256,23 +258,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
}
}
private void OnLogout(IClientAPI client)
{
StatusChange(client.AgentId, false);
m_Friends.Remove(client.AgentId);
}
private void OnMakeRootAgent(ScenePresence sp)
{
UUID agentID = sp.ControllingClient.AgentId;
if (m_Friends.ContainsKey(agentID))
{
if (m_Friends[agentID].RegionID == UUID.Zero)
{
m_Friends[agentID].Friends =
// This is probably an overkill, but just
// to make sure we have the latest and greatest
// friends list -- always pull OnMakeRoot
m_Friends[agentID].Friends =
m_FriendsService.GetFriends(agentID);
}
m_Friends[agentID].RegionID =
sp.ControllingClient.Scene.RegionInfo.RegionID;
}
@@ -438,56 +435,29 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
/// <param name="online"></param>
private void StatusChange(UUID agentID, bool online)
{
//m_log.DebugFormat("[FRIENDS]: StatusChange {0}", online);
if (m_Friends.ContainsKey(agentID))
{
//m_log.DebugFormat("[FRIENDS]: # of friends: {0}", m_Friends[agentID].Friends.Length);
List<FriendInfo> friendList = new List<FriendInfo>();
foreach (FriendInfo fi in m_Friends[agentID].Friends)
{
if (((fi.MyFlags & 1) != 0) && (fi.TheirFlags != -1))
friendList.Add(fi);
}
/*
foreach (FriendInfo fi in friendList)
{
// Notify about this user status
StatusNotify(fi, agentID, online);
}
*/
StatusNotifyMass(friendList, agentID, online);
}
}
private void StatusNotifyMass(List<FriendInfo> friendList, UUID userID, bool online)
{
int fct = friendList.Count;
string[] friendIDs = new string[fct];
int notlocal = 0;
for (int x = 0 ; x < fct ; x++)
{
UUID friendID = UUID.Zero;
if (UUID.TryParse(friendList[x].Friend, out friendID))
Util.FireAndForget(delegate
{
if (!LocalStatusNotification(userID, friendID, online))
foreach (FriendInfo fi in friendList)
{
friendIDs[notlocal++] = friendID.ToString();
//m_log.DebugFormat("[FRIENDS]: Notifying {0}", fi.PrincipalID);
// Notify about this user status
StatusNotify(fi, agentID, online);
}
}
}
PresenceInfo[] friendSessions = PresenceService.GetAgents(friendIDs);
for (int x = 0; x < friendSessions.GetLength(0); x++)
{
if (friendIDs.Length <= x)
continue;
PresenceInfo friendSession = friendSessions[x];
if (friendSession != null)
{
GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID);
m_FriendsSimConnector.StatusNotify(region, userID, new UUID(friendIDs[x]), online);
}
});
}
else
m_log.WarnFormat("[FRIENDS]: {0} not found in cache", agentID);
}
private void StatusNotify(FriendInfo friend, UUID userID, bool online)
@@ -504,16 +474,26 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() });
if (friendSessions != null && friendSessions.Length > 0)
{
PresenceInfo friendSession = friendSessions[0];
PresenceInfo friendSession = null;
foreach (PresenceInfo pinfo in friendSessions)
if (pinfo.RegionID != UUID.Zero) // let's guard against sessions-gone-bad
{
friendSession = pinfo;
break;
}
if (friendSession != null)
{
GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID);
//m_log.DebugFormat("[FRIENDS]: Remote Notify to region {0}", region.RegionName);
m_FriendsSimConnector.StatusNotify(region, userID, friendID, online);
}
}
// Friend is not online. Ignore.
}
else
m_log.WarnFormat("[FRIENDS]: Error parsing friend ID {0}", friend.Friend);
}
private void OnInstantMessage(IClientAPI client, GridInstantMessage im)
@@ -800,7 +780,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
IClientAPI friendClient = LocateClientObject(friendID);
if (friendClient != null)
{
//m_log.DebugFormat("[FRIENDS]: Notify {0} that user {1} is {2}", friend.Friend, userID, online);
//m_log.DebugFormat("[FRIENDS]: Local Status Notify {0} that user {1} is {2}", friendID, userID, online);
// the friend in this sim as root agent
if (online)
friendClient.SendAgentOnline(new UUID[] { userID });