diff options
Diffstat (limited to 'OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs')
-rw-r--r-- | OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs | 187 |
1 files changed, 65 insertions, 122 deletions
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs index b86c45c..ec9cf67 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,9 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
304 | return success; | 293 | return success; |
305 | } | 294 | } |
306 | 295 | ||
307 | public bool SetLastPosition(string userID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt) | 296 | public bool SetLastPosition(string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt) |
308 | { | 297 | { |
309 | // Not needed for simian grid, presence detection is doing it | 298 | return UpdateSession(sessionID, regionID, lastPosition, lastLookAt); |
310 | return true; | ||
311 | } | 299 | } |
312 | 300 | ||
313 | public GridUserInfo GetGridUserInfo(string user) | 301 | public GridUserInfo GetGridUserInfo(string user) |
@@ -334,54 +322,6 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
334 | 322 | ||
335 | #endregion | 323 | #endregion |
336 | 324 | ||
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 | 325 | #region Helpers |
386 | 326 | ||
387 | private OSDMap GetUserData(UUID userID) | 327 | private OSDMap GetUserData(UUID userID) |
@@ -453,57 +393,60 @@ namespace OpenSim.Services.Connectors.SimianGrid | |||
453 | return presences; | 393 | return presences; |
454 | } | 394 | } |
455 | 395 | ||
456 | /// <summary> | 396 | 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 | { | 397 | { |
398 | // Save our current location as session data | ||
462 | NameValueCollection requestArgs = new NameValueCollection | 399 | NameValueCollection requestArgs = new NameValueCollection |
463 | { | 400 | { |
464 | { "RequestMethod", "GetSession" }, | 401 | { "RequestMethod", "UpdateSession" }, |
465 | { "SessionID", sessionID.ToString() } | 402 | { "SessionID", sessionID.ToString() }, |
403 | { "SceneID", regionID.ToString() }, | ||
404 | { "ScenePosition", lastPosition.ToString() }, | ||
405 | { "SceneLookAt", lastLookAt.ToString() } | ||
466 | }; | 406 | }; |
467 | 407 | ||
468 | OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs); | 408 | OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs); |
469 | bool success = response["Success"].AsBoolean(); | 409 | bool success = response["Success"].AsBoolean(); |
470 | 410 | ||
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) | 411 | if (!success) |
502 | m_log.Warn("[SIMIAN PRESENCE CONNECTOR]: Failed to set last location for " + userID + ": " + response["Message"].AsString()); | 412 | m_log.Warn("[SIMIAN PRESENCE CONNECTOR]: Failed to update agent session " + sessionID + ": " + response["Message"].AsString()); |
503 | 413 | ||
504 | return success; | 414 | return success; |
505 | } | 415 | } |
506 | 416 | ||
417 | ///// <summary> | ||
418 | ///// Fetch the last known avatar location with GetSession and persist it | ||
419 | ///// as user data with AddUserData | ||
420 | ///// </summary> | ||
421 | //private bool SetLastLocation(UUID sessionID) | ||
422 | //{ | ||
423 | // NameValueCollection requestArgs = new NameValueCollection | ||
424 | // { | ||
425 | // { "RequestMethod", "GetSession" }, | ||
426 | // { "SessionID", sessionID.ToString() } | ||
427 | // }; | ||
428 | |||
429 | // OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs); | ||
430 | // bool success = response["Success"].AsBoolean(); | ||
431 | |||
432 | // if (success) | ||
433 | // { | ||
434 | // UUID userID = response["UserID"].AsUUID(); | ||
435 | // UUID sceneID = response["SceneID"].AsUUID(); | ||
436 | // Vector3 position = response["ScenePosition"].AsVector3(); | ||
437 | // Vector3 lookAt = response["SceneLookAt"].AsVector3(); | ||
438 | |||
439 | // return SetLastLocation(userID, sceneID, position, lookAt); | ||
440 | // } | ||
441 | // else | ||
442 | // { | ||
443 | // m_log.Warn("[SIMIAN PRESENCE CONNECTOR]: Failed to retrieve presence information for session " + sessionID + | ||
444 | // " while saving last location: " + response["Message"].AsString()); | ||
445 | // } | ||
446 | |||
447 | // return success; | ||
448 | //} | ||
449 | |||
507 | private PresenceInfo ResponseToPresenceInfo(OSDMap sessionResponse, OSDMap userResponse) | 450 | private PresenceInfo ResponseToPresenceInfo(OSDMap sessionResponse, OSDMap userResponse) |
508 | { | 451 | { |
509 | if (sessionResponse == null) | 452 | if (sessionResponse == null) |