From b97f3860cbda43b28b1ac76d9472823924cc5a16 Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 25 Feb 2010 03:55:21 +0000 Subject: Begin tracking users and friends --- .../CoreModules/Avatar/Friends/FriendsModule.cs | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 6134416..df0be97 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs @@ -43,11 +43,20 @@ using OpenSim.Services.Interfaces; using OpenSim.Server.Base; using OpenSim.Framework.Servers.HttpServer; using log4net; +using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; namespace OpenSim.Region.CoreModules.Avatar.Friends { public class FriendsModule : BaseStreamHandler, ISharedRegionModule, IFriendsModule { + protected class UserFriendData + { + public UUID PrincipalID; + public FriendInfo[] Friends; + public int Refcount; + public UUID RegionID; + } + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); protected int m_Port = 0; @@ -56,6 +65,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends protected IPresenceService m_PresenceService = null; protected IFriendsService m_FriendsService = null; + protected Dictionary m_Friends = + new Dictionary(); protected IPresenceService PresenceService { @@ -113,6 +124,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends { m_Scenes.Add(scene); scene.RegisterModuleInterface(this); + + scene.EventManager.OnNewClient += OnNewClient; + scene.EventManager.OnClientClosed += OnClientClosed; + scene.EventManager.OnMakeRootAgent += OnMakeRootAgent; + scene.EventManager.OnMakeChildAgent += OnMakeChildAgent; } public void RegionLoaded(Scene scene) @@ -220,5 +236,70 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends return ms.ToArray(); } + + private void OnNewClient(IClientAPI client) + { + client.OnLogout += OnLogout; + + if (m_Friends.ContainsKey(client.AgentId)) + { + m_Friends[client.AgentId].Refcount++; + return; + } + + UserFriendData newFriends = new UserFriendData(); + + newFriends.PrincipalID = client.AgentId; + newFriends.Friends = m_FriendsService.GetFriends(client.AgentId); + newFriends.Refcount = 1; + newFriends.RegionID = UUID.Zero; + + m_Friends.Add(client.AgentId, newFriends); + } + + private void OnClientClosed(UUID agentID, Scene scene) + { + if (m_Friends.ContainsKey(agentID)) + { + if (m_Friends[agentID].Refcount == 1) + m_Friends.Remove(agentID); + else + m_Friends[agentID].Refcount--; + } + } + + private void OnLogout(IClientAPI client) + { + 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 = + m_FriendsService.GetFriends(agentID); + } + m_Friends[agentID].RegionID = + sp.ControllingClient.Scene.RegionInfo.RegionID; + } + } + + + private void OnMakeChildAgent(ScenePresence sp) + { + UUID agentID = sp.ControllingClient.AgentId; + + if (m_Friends.ContainsKey(agentID)) + { + if (m_Friends[agentID].RegionID == sp.ControllingClient.Scene.RegionInfo.RegionID) + m_Friends[agentID].RegionID = UUID.Zero; + } + } + } } -- cgit v1.1