OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
ActivityDetector.cs
Go to the documentation of this file.
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 
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 
67  {
68  if (sp.PresenceType != PresenceType.Npc)
69  {
70  string userid;
71  //m_log.DebugFormat("[ACTIVITY DETECTOR]: Detected root presence {0} in {1}", userid, sp.Scene.RegionInfo.RegionName);
72  if (sp.Scene.UserManagementModule.GetUserUUI(sp.UUID, out userid))
73  {
74  /* we only setposition on known agents that have a valid lookup */
75  m_GridUserService.SetLastPosition(
76  userid, UUID.Zero, sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
77  }
78  }
79  }
80 
81  public void OnNewClient(IClientAPI client)
82  {
83  client.OnConnectionClosed += OnConnectionClose;
84  }
85 
86  public void OnConnectionClose(IClientAPI client)
87  {
88  if (client == null)
89  return;
90  if (client.SceneAgent == null)
91  return;
92 
93  if (client.SceneAgent.IsChildAgent)
94  return;
95 
96  string userId;
97  /* without scene we cannot logout correctly at all since we do not know how to send the loggedout message then */
98  if (client.Scene is Scene)
99  {
100  Scene s = (Scene)client.Scene;
101  userId = s.UserManagementModule.GetUserUUI(client.AgentId);
102  if(s.UserManagementModule.GetUserUUI(client.AgentId, out userId))
103  {
104  m_GridUserService.LoggedOut(
105  userId, client.SessionId, client.Scene.RegionInfo.RegionID,
106  client.SceneAgent.AbsolutePosition, client.SceneAgent.Lookat);
107  }
108  }
109 
110  }
111  }
112 }
Scene Scene
The scene to which this entity belongs
Definition: EntityBase.cs:46
IUserManagement UserManagementModule
Definition: Scene.cs:774
bool IsChildAgent
If true, then the agent has no avatar in the scene. The agent exists to relay data from a region that...
Definition: ISceneAgent.cs:56
PresenceType
Indicate the type of ScenePresence.
Definition: PresenceType.cs:34
ISceneAgent SceneAgent
The scene agent for this client. This will only be set if the client has an agent in a scene (i...
Definition: IClientAPI.cs:724
Interactive OpenSim region server
Definition: OpenSim.cs:55