diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs | 185 |
1 files changed, 129 insertions, 56 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 7e7d9e9..cc3a3ee 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs | |||
@@ -115,6 +115,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
115 | } | 115 | } |
116 | } | 116 | } |
117 | 117 | ||
118 | public IScene Scene | ||
119 | { | ||
120 | get | ||
121 | { | ||
122 | if (m_Scenes.Count > 0) | ||
123 | return m_Scenes[0]; | ||
124 | else | ||
125 | return null; | ||
126 | } | ||
127 | } | ||
128 | |||
118 | public void Initialise(IConfigSource config) | 129 | public void Initialise(IConfigSource config) |
119 | { | 130 | { |
120 | IConfig friendsConfig = config.Configs["Friends"]; | 131 | IConfig friendsConfig = config.Configs["Friends"]; |
@@ -276,6 +287,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
276 | 287 | ||
277 | private void SendPresence(UUID agentID) | 288 | private void SendPresence(UUID agentID) |
278 | { | 289 | { |
290 | // Inform the friends that this user is online | ||
291 | StatusChange(agentID, true); | ||
292 | |||
293 | // Now send the list of online friends to this user | ||
279 | if (!m_Friends.ContainsKey(agentID)) | 294 | if (!m_Friends.ContainsKey(agentID)) |
280 | { | 295 | { |
281 | m_log.DebugFormat("[FRIENDS MODULE]: agent {0} not found in local cache", agentID); | 296 | m_log.DebugFormat("[FRIENDS MODULE]: agent {0} not found in local cache", agentID); |
@@ -291,11 +306,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
291 | 306 | ||
292 | List<UUID> online = GetOnlineFriends(agentID); | 307 | List<UUID> online = GetOnlineFriends(agentID); |
293 | 308 | ||
294 | m_log.DebugFormat("[FRIENDS]: User {0} has {1} friends online", agentID, online.Count); | 309 | m_log.DebugFormat("[FRIENDS]: User {0} in region {1} has {2} friends online", client.AgentId, client.Scene.RegionInfo.RegionName, online.Count); |
295 | client.SendAgentOnline(online.ToArray()); | 310 | client.SendAgentOnline(online.ToArray()); |
296 | 311 | ||
297 | // Now inform the friends that this user is online | ||
298 | StatusChange(agentID, true); | ||
299 | } | 312 | } |
300 | 313 | ||
301 | List<UUID> GetOnlineFriends(UUID userID) | 314 | List<UUID> GetOnlineFriends(UUID userID) |
@@ -315,7 +328,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
315 | foreach (PresenceInfo pi in presence) | 328 | foreach (PresenceInfo pi in presence) |
316 | { | 329 | { |
317 | if (pi.Online) | 330 | if (pi.Online) |
331 | { | ||
318 | online.Add(new UUID(pi.UserID)); | 332 | online.Add(new UUID(pi.UserID)); |
333 | //m_log.DebugFormat("[XXX] {0} friend online {1}", userID, pi.UserID); | ||
334 | } | ||
319 | } | 335 | } |
320 | 336 | ||
321 | return online; | 337 | return online; |
@@ -324,13 +340,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
324 | // | 340 | // |
325 | // Find the client for a ID | 341 | // Find the client for a ID |
326 | // | 342 | // |
327 | private IClientAPI LocateClientObject(UUID agentID) | 343 | public IClientAPI LocateClientObject(UUID agentID) |
328 | { | 344 | { |
329 | Scene scene=GetClientScene(agentID); | 345 | Scene scene = GetClientScene(agentID); |
330 | if(scene == null) | 346 | if(scene == null) |
331 | return null; | 347 | return null; |
332 | 348 | ||
333 | ScenePresence presence=scene.GetScenePresence(agentID); | 349 | ScenePresence presence = scene.GetScenePresence(agentID); |
334 | if(presence == null) | 350 | if(presence == null) |
335 | return null; | 351 | return null; |
336 | 352 | ||
@@ -386,19 +402,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
386 | 402 | ||
387 | if (UUID.TryParse(friend.Friend, out friendID)) | 403 | if (UUID.TryParse(friend.Friend, out friendID)) |
388 | { | 404 | { |
389 | IClientAPI friendClient = LocateClientObject(friendID); | 405 | // Try local |
390 | if (friendClient != null) | 406 | if (LocalStatusNotification(userID, friendID, online)) |
391 | { | ||
392 | //m_log.DebugFormat("[FRIENDS]: Notify {0} that user {1} is {2}", friend.Friend, userID, online); | ||
393 | // the friend in this sim as root agent | ||
394 | if (online) | ||
395 | friendClient.SendAgentOnline(new UUID[] { userID }); | ||
396 | else | ||
397 | friendClient.SendAgentOffline(new UUID[] { userID }); | ||
398 | // we're done | ||
399 | return; | 407 | return; |
400 | } | 408 | |
401 | |||
402 | // The friend is not here [as root]. Let's forward. | 409 | // The friend is not here [as root]. Let's forward. |
403 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); | 410 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); |
404 | PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); | 411 | PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); |
@@ -438,14 +445,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
438 | // We stick this agent's ID as imSession, so that it's directly available on the receiving end | 445 | // We stick this agent's ID as imSession, so that it's directly available on the receiving end |
439 | im.imSessionID = im.fromAgentID; | 446 | im.imSessionID = im.fromAgentID; |
440 | 447 | ||
441 | IClientAPI friendClient = LocateClientObject(friendID); | 448 | // Try the local sim |
442 | if (friendClient != null) | 449 | if (LocalFriendshipOffered(friendID, im)) |
443 | { | 450 | return; |
444 | // the prospective friend in this sim as root agent | ||
445 | friendClient.SendInstantMessage(im); | ||
446 | // we're done | ||
447 | return ; | ||
448 | } | ||
449 | 451 | ||
450 | // The prospective friend is not here [as root]. Let's forward. | 452 | // The prospective friend is not here [as root]. Let's forward. |
451 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); | 453 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); |
@@ -471,26 +473,20 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
471 | // Notify the friend | 473 | // Notify the friend |
472 | // | 474 | // |
473 | 475 | ||
474 | IClientAPI friendClient = LocateClientObject(friendID); | 476 | // Try Local |
475 | if (friendClient != null) | 477 | if (LocalFriendshipApproved(agentID, client.Name, friendID)) |
476 | { | 478 | { |
477 | // the prospective friend in this sim as root agent | ||
478 | GridInstantMessage im = new GridInstantMessage(client.Scene, client.AgentId, client.Name, friendID, | ||
479 | (byte)OpenMetaverse.InstantMessageDialog.FriendshipAccepted, client.AgentId.ToString(), false, Vector3.Zero); | ||
480 | friendClient.SendInstantMessage(im); | ||
481 | client.SendAgentOnline(new UUID[] { friendID }); | 479 | client.SendAgentOnline(new UUID[] { friendID }); |
482 | // update the local cache | ||
483 | m_Friends[friendID].Friends = FriendsService.GetFriends(friendID); | ||
484 | // we're done | ||
485 | return; | 480 | return; |
486 | } | 481 | } |
487 | 482 | ||
483 | // The friend is not here | ||
488 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); | 484 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); |
489 | PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); | 485 | PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); |
490 | if (friendSession != null) | 486 | if (friendSession != null) |
491 | { | 487 | { |
492 | GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); | 488 | GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); |
493 | m_FriendsSimConnector.FriendshipApproved(region, agentID, friendID); | 489 | m_FriendsSimConnector.FriendshipApproved(region, agentID, client.Name, friendID); |
494 | client.SendAgentOnline(new UUID[] { friendID }); | 490 | client.SendAgentOnline(new UUID[] { friendID }); |
495 | } | 491 | } |
496 | 492 | ||
@@ -507,24 +503,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
507 | // Notify the friend | 503 | // Notify the friend |
508 | // | 504 | // |
509 | 505 | ||
510 | IClientAPI friendClient = LocateClientObject(friendID); | 506 | // Try local |
511 | if (friendClient != null) | 507 | if (LocalFriendshipDenied(agentID, client.Name, friendID)) |
512 | { | ||
513 | // the prospective friend in this sim as root agent | ||
514 | |||
515 | GridInstantMessage im = new GridInstantMessage(client.Scene, client.AgentId, client.Name, friendID, | ||
516 | (byte)OpenMetaverse.InstantMessageDialog.FriendshipDeclined, client.AgentId.ToString(), false, Vector3.Zero); | ||
517 | friendClient.SendInstantMessage(im); | ||
518 | // we're done | ||
519 | return; | 508 | return; |
520 | } | ||
521 | 509 | ||
522 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); | 510 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); |
523 | PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); | 511 | PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); |
524 | if (friendSession != null) | 512 | if (friendSession != null) |
525 | { | 513 | { |
526 | GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); | 514 | GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); |
527 | m_FriendsSimConnector.FriendshipDenied(region, agentID, friendID); | 515 | m_FriendsSimConnector.FriendshipDenied(region, agentID, client.Name, friendID); |
528 | } | 516 | } |
529 | } | 517 | } |
530 | 518 | ||
@@ -542,16 +530,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
542 | // Notify the friend | 530 | // Notify the friend |
543 | // | 531 | // |
544 | 532 | ||
545 | IClientAPI friendClient = LocateClientObject(exfriendID); | 533 | // Try local |
546 | if (friendClient != null) | 534 | if (LocalFriendshipTerminated(exfriendID)) |
547 | { | ||
548 | // the friend in this sim as root agent | ||
549 | friendClient.SendTerminateFriend(exfriendID); | ||
550 | // update local cache | ||
551 | m_Friends[exfriendID].Friends = FriendsService.GetFriends(exfriendID); | ||
552 | // we're done | ||
553 | return; | 535 | return; |
554 | } | ||
555 | 536 | ||
556 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { exfriendID.ToString() }); | 537 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { exfriendID.ToString() }); |
557 | PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); | 538 | PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); |
@@ -587,5 +568,97 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
587 | m_FriendsSimConnector.GrantRights(region, requester, target); | 568 | m_FriendsSimConnector.GrantRights(region, requester, target); |
588 | } | 569 | } |
589 | } | 570 | } |
571 | |||
572 | #region Local | ||
573 | |||
574 | public bool LocalFriendshipOffered(UUID toID, GridInstantMessage im) | ||
575 | { | ||
576 | IClientAPI friendClient = LocateClientObject(toID); | ||
577 | if (friendClient != null) | ||
578 | { | ||
579 | // the prospective friend in this sim as root agent | ||
580 | friendClient.SendInstantMessage(im); | ||
581 | // we're done | ||
582 | return true; | ||
583 | } | ||
584 | return false; | ||
585 | } | ||
586 | |||
587 | public bool LocalFriendshipApproved(UUID userID, string userName, UUID friendID) | ||
588 | { | ||
589 | IClientAPI friendClient = LocateClientObject(friendID); | ||
590 | if (friendClient != null) | ||
591 | { | ||
592 | // the prospective friend in this sim as root agent | ||
593 | GridInstantMessage im = new GridInstantMessage(Scene, userID, userName, friendID, | ||
594 | (byte)OpenMetaverse.InstantMessageDialog.FriendshipAccepted, userID.ToString(), false, Vector3.Zero); | ||
595 | friendClient.SendInstantMessage(im); | ||
596 | // update the local cache | ||
597 | m_Friends[friendID].Friends = FriendsService.GetFriends(friendID); | ||
598 | // we're done | ||
599 | return true; | ||
600 | } | ||
601 | |||
602 | return false; | ||
603 | } | ||
604 | |||
605 | public bool LocalFriendshipDenied(UUID userID, string userName, UUID friendID) | ||
606 | { | ||
607 | IClientAPI friendClient = LocateClientObject(friendID); | ||
608 | if (friendClient != null) | ||
609 | { | ||
610 | // the prospective friend in this sim as root agent | ||
611 | |||
612 | GridInstantMessage im = new GridInstantMessage(Scene, userID, userName, friendID, | ||
613 | (byte)OpenMetaverse.InstantMessageDialog.FriendshipDeclined, userID.ToString(), false, Vector3.Zero); | ||
614 | friendClient.SendInstantMessage(im); | ||
615 | // we're done | ||
616 | return true; | ||
617 | } | ||
618 | |||
619 | return false; | ||
620 | } | ||
621 | |||
622 | public bool LocalFriendshipTerminated(UUID exfriendID) | ||
623 | { | ||
624 | IClientAPI friendClient = LocateClientObject(exfriendID); | ||
625 | if (friendClient != null) | ||
626 | { | ||
627 | // the friend in this sim as root agent | ||
628 | friendClient.SendTerminateFriend(exfriendID); | ||
629 | // update local cache | ||
630 | m_Friends[exfriendID].Friends = FriendsService.GetFriends(exfriendID); | ||
631 | // we're done | ||
632 | return true; | ||
633 | } | ||
634 | |||
635 | return false; | ||
636 | } | ||
637 | |||
638 | public bool LocalGrantRights() | ||
639 | { | ||
640 | // TODO | ||
641 | return true; | ||
642 | } | ||
643 | |||
644 | public bool LocalStatusNotification(UUID userID, UUID friendID, bool online) | ||
645 | { | ||
646 | IClientAPI friendClient = LocateClientObject(friendID); | ||
647 | if (friendClient != null) | ||
648 | { | ||
649 | //m_log.DebugFormat("[FRIENDS]: Notify {0} that user {1} is {2}", friend.Friend, userID, online); | ||
650 | // the friend in this sim as root agent | ||
651 | if (online) | ||
652 | friendClient.SendAgentOnline(new UUID[] { userID }); | ||
653 | else | ||
654 | friendClient.SendAgentOffline(new UUID[] { userID }); | ||
655 | // we're done | ||
656 | return true; | ||
657 | } | ||
658 | |||
659 | return false; | ||
660 | } | ||
661 | #endregion | ||
662 | |||
590 | } | 663 | } |
591 | } | 664 | } |