From 44d5b2910ff7f794c960d90006149522c0844c5f Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 25 Feb 2010 04:22:51 +0000 Subject: Implement initial online notifications --- .../CoreModules/Avatar/Friends/FriendsModule.cs | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 0d9fd94..7c81d6a 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs @@ -44,6 +44,7 @@ using OpenSim.Server.Base; using OpenSim.Framework.Servers.HttpServer; using log4net; using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; +using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; namespace OpenSim.Region.CoreModules.Avatar.Friends { @@ -250,6 +251,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends private void OnNewClient(IClientAPI client) { client.OnLogout += OnLogout; + client.OnEconomyDataRequest += SendPresence; if (m_Friends.ContainsKey(client.AgentId)) { @@ -311,5 +313,67 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } } + private void SendPresence(UUID agentID) + { + if (!m_Friends.ContainsKey(agentID)) + return; + + IClientAPI client = LocateClientObject(agentID); + if (client == null) + return; + + List friendList = new List(); + + foreach (FriendInfo fi in m_Friends[agentID].Friends) + friendList.Add(fi.Friend); + + PresenceInfo[] presence = PresenceService.GetAgents(friendList.ToArray()); + + List online = new List(); + + foreach (PresenceInfo pi in presence) + { + if (pi.Online) + online.Add(new UUID(pi.UserID)); + } + + client.SendAgentOnline(online.ToArray()); + } + + // + // Find the client for a ID + // + private IClientAPI LocateClientObject(UUID agentID) + { + Scene scene=GetClientScene(agentID); + if(scene == null) + return null; + + ScenePresence presence=scene.GetScenePresence(agentID); + if(presence == null) + return null; + + return presence.ControllingClient; + } + + // + // Find the scene for an agent + // + private Scene GetClientScene(UUID agentId) + { + lock (m_Scenes) + { + foreach (Scene scene in m_Scenes) + { + ScenePresence presence = scene.GetScenePresence(agentId); + if (presence != null) + { + if (!presence.IsChildAgent) + return scene; + } + } + } + return null; + } } } -- cgit v1.1