clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 using System;
28 using System.Collections.Generic;
29 using System.Reflection;
30  
31 using OpenSim.Framework;
32 using OpenSim.Region.Framework.Scenes;
33 using OpenSim.Services.Interfaces;
34  
35 using OpenMetaverse;
36 using log4net;
37  
38 namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser
39 {
40 public class ActivityDetector
41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43  
44 private IGridUserService m_GridUserService;
45  
46 public ActivityDetector(IGridUserService guservice)
47 {
48 m_GridUserService = guservice;
49 m_log.DebugFormat("[ACTIVITY DETECTOR]: starting ");
50 }
51  
52 public void AddRegion(Scene scene)
53 {
54 // For now the only events we listen to are these
55 // But we could trigger the position update more often
56 scene.EventManager.OnMakeRootAgent += OnMakeRootAgent;
57 scene.EventManager.OnNewClient += OnNewClient;
58 }
59  
60 public void RemoveRegion(Scene scene)
61 {
62 scene.EventManager.OnMakeRootAgent -= OnMakeRootAgent;
63 scene.EventManager.OnNewClient -= OnNewClient;
64 }
65  
66 public void OnMakeRootAgent(ScenePresence sp)
67 {
68 if (sp.PresenceType != PresenceType.Npc)
69 {
70 string userid = sp.Scene.UserManagementModule.GetUserUUI(sp.UUID);
71 //m_log.DebugFormat("[ACTIVITY DETECTOR]: Detected root presence {0} in {1}", userid, sp.Scene.RegionInfo.RegionName);
72 m_GridUserService.SetLastPosition(
73 userid, UUID.Zero, sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
74 }
75 }
76  
77 public void OnNewClient(IClientAPI client)
78 {
79 client.OnConnectionClosed += OnConnectionClose;
80 }
81  
82 public void OnConnectionClose(IClientAPI client)
83 {
84 if (client == null)
85 return;
86 if (client.SceneAgent == null)
87 return;
88  
89 if (client.SceneAgent.IsChildAgent)
90 return;
91  
92 string userId = client.AgentId.ToString();
93 if (client.Scene is Scene)
94 {
95 Scene s = (Scene)client.Scene;
96 userId = s.UserManagementModule.GetUserUUI(client.AgentId);
97 }
98 //m_log.DebugFormat("[ACTIVITY DETECTOR]: Detected client logout {0} in {1}", userId, client.Scene.RegionInfo.RegionName);
99  
100 m_GridUserService.LoggedOut(
101 userId, client.SessionId, client.Scene.RegionInfo.RegionID,
102 client.SceneAgent.AbsolutePosition, client.SceneAgent.Lookat);
103 }
104 }
105 }