From 1a3ad3ae80a3b01c08008e2aca0bfaccb497ac5c Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 25 Feb 2010 23:32:38 +0000 Subject: Implement local online/offline notifications --- .../CoreModules/Avatar/Friends/FriendsModule.cs | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index e654b1f..8b15abb 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs @@ -56,6 +56,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends public FriendInfo[] Friends; public int Refcount; public UUID RegionID; + + public bool IsFriend(string friend) + { + foreach (FriendInfo fi in Friends) + { + if (fi.Friend == friend) + return true; + } + + return false; + } } private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -267,6 +278,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends newFriends.RegionID = UUID.Zero; m_Friends.Add(client.AgentId, newFriends); + + StatusChange(client.AgentId, true); } private void OnClientClosed(UUID agentID, Scene scene) @@ -283,6 +296,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends private void OnLogout(IClientAPI client) { m_Friends.Remove(client.AgentId); + + StatusChange(client.AgentId, false); } private void OnMakeRootAgent(ScenePresence sp) @@ -378,5 +393,27 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } return null; } + + private void StatusChange(UUID agentID, bool online) + { + foreach (UserFriendData fd in m_Friends.Values) + { + // Is this a root agent? If not, they will get updates + // through the root and this next check is redundant + // + if (fd.RegionID == UUID.Zero) + continue; + + if (fd.IsFriend(agentID.ToString())) + { + UUID[] changed = new UUID[] { agentID }; + IClientAPI client = LocateClientObject(fd.PrincipalID); + if (online) + client.SendAgentOnline(changed); + else + client.SendAgentOffline(changed); + } + } + } } } -- cgit v1.1