aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorMelanie2010-02-25 03:55:21 +0000
committerMelanie2010-02-25 03:55:21 +0000
commitb97f3860cbda43b28b1ac76d9472823924cc5a16 (patch)
tree16293a6a8fce2c012d66f7af2fc2a87f621199d8 /OpenSim
parentAdd part of the needed config examples (diff)
downloadopensim-SC-b97f3860cbda43b28b1ac76d9472823924cc5a16.zip
opensim-SC-b97f3860cbda43b28b1ac76d9472823924cc5a16.tar.gz
opensim-SC-b97f3860cbda43b28b1ac76d9472823924cc5a16.tar.bz2
opensim-SC-b97f3860cbda43b28b1ac76d9472823924cc5a16.tar.xz
Begin tracking users and friends
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs81
1 files changed, 81 insertions, 0 deletions
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;
43using OpenSim.Server.Base; 43using OpenSim.Server.Base;
44using OpenSim.Framework.Servers.HttpServer; 44using OpenSim.Framework.Servers.HttpServer;
45using log4net; 45using log4net;
46using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
46 47
47namespace OpenSim.Region.CoreModules.Avatar.Friends 48namespace OpenSim.Region.CoreModules.Avatar.Friends
48{ 49{
49 public class FriendsModule : BaseStreamHandler, ISharedRegionModule, IFriendsModule 50 public class FriendsModule : BaseStreamHandler, ISharedRegionModule, IFriendsModule
50 { 51 {
52 protected class UserFriendData
53 {
54 public UUID PrincipalID;
55 public FriendInfo[] Friends;
56 public int Refcount;
57 public UUID RegionID;
58 }
59
51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 60 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 61
53 protected int m_Port = 0; 62 protected int m_Port = 0;
@@ -56,6 +65,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
56 65
57 protected IPresenceService m_PresenceService = null; 66 protected IPresenceService m_PresenceService = null;
58 protected IFriendsService m_FriendsService = null; 67 protected IFriendsService m_FriendsService = null;
68 protected Dictionary<UUID, UserFriendData> m_Friends =
69 new Dictionary<UUID, UserFriendData>();
59 70
60 protected IPresenceService PresenceService 71 protected IPresenceService PresenceService
61 { 72 {
@@ -113,6 +124,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
113 { 124 {
114 m_Scenes.Add(scene); 125 m_Scenes.Add(scene);
115 scene.RegisterModuleInterface<IFriendsModule>(this); 126 scene.RegisterModuleInterface<IFriendsModule>(this);
127
128 scene.EventManager.OnNewClient += OnNewClient;
129 scene.EventManager.OnClientClosed += OnClientClosed;
130 scene.EventManager.OnMakeRootAgent += OnMakeRootAgent;
131 scene.EventManager.OnMakeChildAgent += OnMakeChildAgent;
116 } 132 }
117 133
118 public void RegionLoaded(Scene scene) 134 public void RegionLoaded(Scene scene)
@@ -220,5 +236,70 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
220 236
221 return ms.ToArray(); 237 return ms.ToArray();
222 } 238 }
239
240 private void OnNewClient(IClientAPI client)
241 {
242 client.OnLogout += OnLogout;
243
244 if (m_Friends.ContainsKey(client.AgentId))
245 {
246 m_Friends[client.AgentId].Refcount++;
247 return;
248 }
249
250 UserFriendData newFriends = new UserFriendData();
251
252 newFriends.PrincipalID = client.AgentId;
253 newFriends.Friends = m_FriendsService.GetFriends(client.AgentId);
254 newFriends.Refcount = 1;
255 newFriends.RegionID = UUID.Zero;
256
257 m_Friends.Add(client.AgentId, newFriends);
258 }
259
260 private void OnClientClosed(UUID agentID, Scene scene)
261 {
262 if (m_Friends.ContainsKey(agentID))
263 {
264 if (m_Friends[agentID].Refcount == 1)
265 m_Friends.Remove(agentID);
266 else
267 m_Friends[agentID].Refcount--;
268 }
269 }
270
271 private void OnLogout(IClientAPI client)
272 {
273 m_Friends.Remove(client.AgentId);
274 }
275
276 private void OnMakeRootAgent(ScenePresence sp)
277 {
278 UUID agentID = sp.ControllingClient.AgentId;
279
280 if (m_Friends.ContainsKey(agentID))
281 {
282 if (m_Friends[agentID].RegionID == UUID.Zero)
283 {
284 m_Friends[agentID].Friends =
285 m_FriendsService.GetFriends(agentID);
286 }
287 m_Friends[agentID].RegionID =
288 sp.ControllingClient.Scene.RegionInfo.RegionID;
289 }
290 }
291
292
293 private void OnMakeChildAgent(ScenePresence sp)
294 {
295 UUID agentID = sp.ControllingClient.AgentId;
296
297 if (m_Friends.ContainsKey(agentID))
298 {
299 if (m_Friends[agentID].RegionID == sp.ControllingClient.Scene.RegionInfo.RegionID)
300 m_Friends[agentID].RegionID = UUID.Zero;
301 }
302 }
303
223 } 304 }
224} 305}