aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors
diff options
context:
space:
mode:
authorMelanie2010-05-21 03:51:58 +0100
committerMelanie2010-05-21 03:51:58 +0100
commita92780fe5f31a38b2f00459ef00ca28127a60dcf (patch)
treef89850a27564abd01f1b3aaf72aa24001e165a26 /OpenSim/Services/Connectors
parentRefactor scene presence list for lockless iteration. Lock contention will now... (diff)
parentCleaned up MySql migrations a bit more, got rid of all old-form migration fil... (diff)
downloadopensim-SC_OLD-a92780fe5f31a38b2f00459ef00ca28127a60dcf.zip
opensim-SC_OLD-a92780fe5f31a38b2f00459ef00ca28127a60dcf.tar.gz
opensim-SC_OLD-a92780fe5f31a38b2f00459ef00ca28127a60dcf.tar.bz2
opensim-SC_OLD-a92780fe5f31a38b2f00459ef00ca28127a60dcf.tar.xz
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Services/Connectors')
-rw-r--r--OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs2
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianActivityDetector.cs113
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs191
3 files changed, 184 insertions, 122 deletions
diff --git a/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs b/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs
index b4500a5..600ddfd 100644
--- a/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs
+++ b/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs
@@ -84,7 +84,7 @@ namespace OpenSim.Services.Connectors
84 } 84 }
85 85
86 86
87 #region IPresenceService 87 #region IGridUserService
88 88
89 89
90 public GridUserInfo LoggedIn(string userID) 90 public GridUserInfo LoggedIn(string userID)
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianActivityDetector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianActivityDetector.cs
new file mode 100644
index 0000000..a871d07
--- /dev/null
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianActivityDetector.cs
@@ -0,0 +1,113 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using OpenSim.Framework;
32using OpenSim.Region.Framework.Scenes;
33using OpenSim.Services.Interfaces;
34using OpenMetaverse;
35using log4net;
36
37namespace OpenSim.Services.Connectors.SimianGrid
38{
39 public class SimianActivityDetector
40 {
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42
43 private SimianPresenceServiceConnector m_GridUserService;
44 private Scene m_aScene;
45
46 public SimianActivityDetector(SimianPresenceServiceConnector guservice)
47 {
48 m_GridUserService = guservice;
49 m_log.DebugFormat("[SIMIAN ACTIVITY DETECTOR]: Started");
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 scene.EventManager.OnAvatarEnteringNewParcel += OnEnteringNewParcel;
59
60 if (m_aScene == null)
61 m_aScene = scene;
62 }
63
64 public void RemoveRegion(Scene scene)
65 {
66 scene.EventManager.OnMakeRootAgent -= OnMakeRootAgent;
67 scene.EventManager.OnNewClient -= OnNewClient;
68 scene.EventManager.OnAvatarEnteringNewParcel -= OnEnteringNewParcel;
69 }
70
71 public void OnMakeRootAgent(ScenePresence sp)
72 {
73 m_log.DebugFormat("[SIMIAN ACTIVITY DETECTOR]: Detected root presence {0} in {1}", sp.UUID, sp.Scene.RegionInfo.RegionName);
74 m_GridUserService.SetLastPosition(sp.UUID.ToString(), sp.ControllingClient.SessionId, sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
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.IsLoggingOut)
85 {
86 object sp = null;
87 Vector3 position = new Vector3(128, 128, 0);
88 Vector3 lookat = new Vector3(0, 1, 0);
89
90 if (client.Scene.TryGetScenePresence(client.AgentId, out sp))
91 {
92 if (sp is ScenePresence)
93 {
94 if (((ScenePresence)sp).IsChildAgent)
95 return;
96
97 position = ((ScenePresence)sp).AbsolutePosition;
98 lookat = ((ScenePresence)sp).Lookat;
99 }
100 }
101
102 m_log.DebugFormat("[SIMIAN ACTIVITY DETECTOR]: Detected client logout {0} in {1}", client.AgentId, client.Scene.RegionInfo.RegionName);
103 m_GridUserService.LoggedOut(client.AgentId.ToString(), client.Scene.RegionInfo.RegionID, position, lookat);
104 }
105
106 }
107
108 void OnEnteringNewParcel(ScenePresence sp, int localLandID, UUID regionID)
109 {
110 m_GridUserService.SetLastPosition(sp.UUID.ToString(), sp.ControllingClient.SessionId, sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
111 }
112 }
113}
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs
index b86c45c..6f17931 100644
--- a/OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs
@@ -58,6 +58,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
58 MethodBase.GetCurrentMethod().DeclaringType); 58 MethodBase.GetCurrentMethod().DeclaringType);
59 59
60 private string m_serverUrl = String.Empty; 60 private string m_serverUrl = String.Empty;
61 private SimianActivityDetector m_activityDetector;
61 62
62 #region ISharedRegionModule 63 #region ISharedRegionModule
63 64
@@ -66,7 +67,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
66 public void PostInitialise() { } 67 public void PostInitialise() { }
67 public void Close() { } 68 public void Close() { }
68 69
69 public SimianPresenceServiceConnector() { } 70 public SimianPresenceServiceConnector() { m_activityDetector = new SimianActivityDetector(this); }
70 public string Name { get { return "SimianPresenceServiceConnector"; } } 71 public string Name { get { return "SimianPresenceServiceConnector"; } }
71 public void AddRegion(Scene scene) 72 public void AddRegion(Scene scene)
72 { 73 {
@@ -75,9 +76,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
75 scene.RegisterModuleInterface<IPresenceService>(this); 76 scene.RegisterModuleInterface<IPresenceService>(this);
76 scene.RegisterModuleInterface<IGridUserService>(this); 77 scene.RegisterModuleInterface<IGridUserService>(this);
77 78
78 scene.EventManager.OnMakeRootAgent += MakeRootAgentHandler; 79 m_activityDetector.AddRegion(scene);
79 scene.EventManager.OnNewClient += NewClientHandler;
80 scene.EventManager.OnSignificantClientMovement += SignificantClientMovementHandler;
81 80
82 LogoutRegionAgents(scene.RegionInfo.RegionID); 81 LogoutRegionAgents(scene.RegionInfo.RegionID);
83 } 82 }
@@ -89,9 +88,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
89 scene.UnregisterModuleInterface<IPresenceService>(this); 88 scene.UnregisterModuleInterface<IPresenceService>(this);
90 scene.UnregisterModuleInterface<IGridUserService>(this); 89 scene.UnregisterModuleInterface<IGridUserService>(this);
91 90
92 scene.EventManager.OnMakeRootAgent -= MakeRootAgentHandler; 91 m_activityDetector.RemoveRegion(scene);
93 scene.EventManager.OnNewClient -= NewClientHandler;
94 scene.EventManager.OnSignificantClientMovement -= SignificantClientMovementHandler;
95 92
96 LogoutRegionAgents(scene.RegionInfo.RegionID); 93 LogoutRegionAgents(scene.RegionInfo.RegionID);
97 } 94 }
@@ -193,29 +190,8 @@ namespace OpenSim.Services.Connectors.SimianGrid
193 190
194 public bool ReportAgent(UUID sessionID, UUID regionID) 191 public bool ReportAgent(UUID sessionID, UUID regionID)
195 { 192 {
196 return ReportAgent(sessionID, regionID, Vector3.Zero, Vector3.Zero); 193 // Not needed for SimianGrid
197 } 194 return true;
198
199 protected bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt)
200 {
201 //m_log.DebugFormat("[SIMIAN PRESENCE CONNECTOR]: Updating session data for agent with sessionID " + sessionID);
202
203 NameValueCollection requestArgs = new NameValueCollection
204 {
205 { "RequestMethod", "UpdateSession" },
206 { "SessionID", sessionID.ToString() },
207 { "SceneID", regionID.ToString() },
208 { "ScenePosition", position.ToString() },
209 { "SceneLookAt", lookAt.ToString() }
210 };
211
212 OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
213 bool success = response["Success"].AsBoolean();
214
215 if (!success)
216 m_log.Warn("[SIMIAN PRESENCE CONNECTOR]: Failed to update agent session " + sessionID + ": " + response["Message"].AsString());
217
218 return success;
219 } 195 }
220 196
221 public PresenceInfo GetAgent(UUID sessionID) 197 public PresenceInfo GetAgent(UUID sessionID)
@@ -274,14 +250,27 @@ namespace OpenSim.Services.Connectors.SimianGrid
274 250
275 public GridUserInfo LoggedIn(string userID) 251 public GridUserInfo LoggedIn(string userID)
276 { 252 {
277 // never implemented at the sim 253 // Never implemented at the sim
278 return null; 254 return null;
279 } 255 }
280 256
281 public bool LoggedOut(string userID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt) 257 public bool LoggedOut(string userID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
282 { 258 {
283 // Not needed for simian grid, event handler is doing it 259 // Save our last position as user data
284 return true; 260 NameValueCollection requestArgs = new NameValueCollection
261 {
262 { "RequestMethod", "AddUserData" },
263 { "UserID", userID.ToString() },
264 { "LastLocation", SerializeLocation(regionID, lastPosition, lastLookAt) }
265 };
266
267 OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
268 bool success = response["Success"].AsBoolean();
269
270 if (!success)
271 m_log.Warn("[SIMIAN PRESENCE CONNECTOR]: Failed to set last location for " + userID + ": " + response["Message"].AsString());
272
273 return success;
285 } 274 }
286 275
287 public bool SetHome(string userID, UUID regionID, Vector3 position, Vector3 lookAt) 276 public bool SetHome(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
@@ -304,10 +293,15 @@ namespace OpenSim.Services.Connectors.SimianGrid
304 return success; 293 return success;
305 } 294 }
306 295
296 public bool SetLastPosition(string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
297 {
298 return UpdateSession(sessionID, regionID, lastPosition, lastLookAt);
299 }
300
307 public bool SetLastPosition(string userID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt) 301 public bool SetLastPosition(string userID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
308 { 302 {
309 // Not needed for simian grid, presence detection is doing it 303 // Never called
310 return true; 304 return false;
311 } 305 }
312 306
313 public GridUserInfo GetGridUserInfo(string user) 307 public GridUserInfo GetGridUserInfo(string user)
@@ -334,54 +328,6 @@ namespace OpenSim.Services.Connectors.SimianGrid
334 328
335 #endregion 329 #endregion
336 330
337 #region Presence Detection
338
339 private void MakeRootAgentHandler(ScenePresence sp)
340 {
341 m_log.DebugFormat("[PRESENCE DETECTOR]: Detected root presence {0} in {1}", sp.UUID, sp.Scene.RegionInfo.RegionName);
342
343 ReportAgent(sp.ControllingClient.SessionId, sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
344 SetLastLocation(sp.UUID, sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
345 }
346
347 private void NewClientHandler(IClientAPI client)
348 {
349 client.OnConnectionClosed += LogoutHandler;
350 }
351
352 private void SignificantClientMovementHandler(IClientAPI client)
353 {
354 ScenePresence sp;
355 if (client.Scene is Scene && ((Scene)client.Scene).TryGetScenePresence(client.AgentId, out sp))
356 ReportAgent(sp.ControllingClient.SessionId, sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
357 }
358
359 private void LogoutHandler(IClientAPI client)
360 {
361 if (client.IsLoggingOut)
362 {
363 client.OnConnectionClosed -= LogoutHandler;
364
365 object obj;
366 if (client.Scene.TryGetScenePresence(client.AgentId, out obj) && obj is ScenePresence)
367 {
368 // The avatar is still in the scene, we can get the exact logout position
369 ScenePresence sp = (ScenePresence)obj;
370 SetLastLocation(client.AgentId, client.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
371 }
372 else
373 {
374 // The avatar was already removed from the scene, store LastLocation using the most recent session data
375 m_log.Warn("[PRESENCE]: " + client.Name + " has already been removed from the scene, storing approximate LastLocation");
376 SetLastLocation(client.SessionId);
377 }
378
379 LogoutAgent(client.SessionId);
380 }
381 }
382
383 #endregion Presence Detection
384
385 #region Helpers 331 #region Helpers
386 332
387 private OSDMap GetUserData(UUID userID) 333 private OSDMap GetUserData(UUID userID)
@@ -453,57 +399,60 @@ namespace OpenSim.Services.Connectors.SimianGrid
453 return presences; 399 return presences;
454 } 400 }
455 401
456 /// <summary> 402 private bool UpdateSession(UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
457 /// Fetch the last known avatar location with GetSession and persist it
458 /// as user data with AddUserData
459 /// </summary>
460 private bool SetLastLocation(UUID sessionID)
461 { 403 {
404 // Save our current location as session data
462 NameValueCollection requestArgs = new NameValueCollection 405 NameValueCollection requestArgs = new NameValueCollection
463 { 406 {
464 { "RequestMethod", "GetSession" }, 407 { "RequestMethod", "UpdateSession" },
465 { "SessionID", sessionID.ToString() } 408 { "SessionID", sessionID.ToString() },
409 { "SceneID", regionID.ToString() },
410 { "ScenePosition", lastPosition.ToString() },
411 { "SceneLookAt", lastLookAt.ToString() }
466 }; 412 };
467 413
468 OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs); 414 OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
469 bool success = response["Success"].AsBoolean(); 415 bool success = response["Success"].AsBoolean();
470 416
471 if (success)
472 {
473 UUID userID = response["UserID"].AsUUID();
474 UUID sceneID = response["SceneID"].AsUUID();
475 Vector3 position = response["ScenePosition"].AsVector3();
476 Vector3 lookAt = response["SceneLookAt"].AsVector3();
477
478 return SetLastLocation(userID, sceneID, position, lookAt);
479 }
480 else
481 {
482 m_log.Warn("[SIMIAN PRESENCE CONNECTOR]: Failed to retrieve presence information for session " + sessionID +
483 " while saving last location: " + response["Message"].AsString());
484 }
485
486 return success;
487 }
488
489 private bool SetLastLocation(UUID userID, UUID sceneID, Vector3 position, Vector3 lookAt)
490 {
491 NameValueCollection requestArgs = new NameValueCollection
492 {
493 { "RequestMethod", "AddUserData" },
494 { "UserID", userID.ToString() },
495 { "LastLocation", SerializeLocation(sceneID, position, lookAt) }
496 };
497
498 OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
499 bool success = response["Success"].AsBoolean();
500
501 if (!success) 417 if (!success)
502 m_log.Warn("[SIMIAN PRESENCE CONNECTOR]: Failed to set last location for " + userID + ": " + response["Message"].AsString()); 418 m_log.Warn("[SIMIAN PRESENCE CONNECTOR]: Failed to update agent session " + sessionID + ": " + response["Message"].AsString());
503 419
504 return success; 420 return success;
505 } 421 }
506 422
423 ///// <summary>
424 ///// Fetch the last known avatar location with GetSession and persist it
425 ///// as user data with AddUserData
426 ///// </summary>
427 //private bool SetLastLocation(UUID sessionID)
428 //{
429 // NameValueCollection requestArgs = new NameValueCollection
430 // {
431 // { "RequestMethod", "GetSession" },
432 // { "SessionID", sessionID.ToString() }
433 // };
434
435 // OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
436 // bool success = response["Success"].AsBoolean();
437
438 // if (success)
439 // {
440 // UUID userID = response["UserID"].AsUUID();
441 // UUID sceneID = response["SceneID"].AsUUID();
442 // Vector3 position = response["ScenePosition"].AsVector3();
443 // Vector3 lookAt = response["SceneLookAt"].AsVector3();
444
445 // return SetLastLocation(userID, sceneID, position, lookAt);
446 // }
447 // else
448 // {
449 // m_log.Warn("[SIMIAN PRESENCE CONNECTOR]: Failed to retrieve presence information for session " + sessionID +
450 // " while saving last location: " + response["Message"].AsString());
451 // }
452
453 // return success;
454 //}
455
507 private PresenceInfo ResponseToPresenceInfo(OSDMap sessionResponse, OSDMap userResponse) 456 private PresenceInfo ResponseToPresenceInfo(OSDMap sessionResponse, OSDMap userResponse)
508 { 457 {
509 if (sessionResponse == null) 458 if (sessionResponse == null)