diff options
author | onefang | 2019-05-19 21:24:15 +1000 |
---|---|---|
committer | onefang | 2019-05-19 21:24:15 +1000 |
commit | 5e4d6cab00cb29cd088ab7b62ab13aff103b64cb (patch) | |
tree | a9fbc62df9eb2d1d9ba2698d8552eae71eca20d8 /OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs | |
parent | Add a build script. (diff) | |
download | opensim-SC-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.zip opensim-SC-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.gz opensim-SC-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.bz2 opensim-SC-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.xz |
Dump OpenSim 0.9.0.1 into it's own branch.
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs | 169 |
1 files changed, 122 insertions, 47 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 08e7dd2..772485c 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs | |||
@@ -167,7 +167,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
167 | m_Enabled = true; | 167 | m_Enabled = true; |
168 | m_log.DebugFormat("[FRIENDS MODULE]: {0} enabled.", Name); | 168 | m_log.DebugFormat("[FRIENDS MODULE]: {0} enabled.", Name); |
169 | } | 169 | } |
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | ||
173 | protected virtual void InitModule(IConfigSource config) | 173 | protected virtual void InitModule(IConfigSource config) |
@@ -247,14 +247,30 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
247 | { | 247 | { |
248 | FriendInfo[] friends = GetFriendsFromCache(principalID); | 248 | FriendInfo[] friends = GetFriendsFromCache(principalID); |
249 | FriendInfo finfo = GetFriend(friends, friendID); | 249 | FriendInfo finfo = GetFriend(friends, friendID); |
250 | if (finfo != null) | 250 | if (finfo != null && finfo.TheirFlags != -1) |
251 | { | 251 | { |
252 | return finfo.TheirFlags; | 252 | return finfo.TheirFlags; |
253 | } | 253 | } |
254 | |||
255 | return 0; | 254 | return 0; |
256 | } | 255 | } |
257 | 256 | ||
257 | private void OnMakeRootAgent(ScenePresence sp) | ||
258 | { | ||
259 | if(sp.gotCrossUpdate) | ||
260 | return; | ||
261 | |||
262 | RecacheFriends(sp.ControllingClient); | ||
263 | |||
264 | lock (m_NeedsToNotifyStatus) | ||
265 | { | ||
266 | if (m_NeedsToNotifyStatus.Remove(sp.UUID)) | ||
267 | { | ||
268 | // Inform the friends that this user is online. This can only be done once the client is a Root Agent. | ||
269 | StatusChange(sp.UUID, true); | ||
270 | } | ||
271 | } | ||
272 | } | ||
273 | |||
258 | private void OnNewClient(IClientAPI client) | 274 | private void OnNewClient(IClientAPI client) |
259 | { | 275 | { |
260 | client.OnInstantMessage += OnInstantMessage; | 276 | client.OnInstantMessage += OnInstantMessage; |
@@ -262,6 +278,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
262 | client.OnDenyFriendRequest += OnDenyFriendRequest; | 278 | client.OnDenyFriendRequest += OnDenyFriendRequest; |
263 | client.OnTerminateFriendship += RemoveFriendship; | 279 | client.OnTerminateFriendship += RemoveFriendship; |
264 | client.OnGrantUserRights += GrantRights; | 280 | client.OnGrantUserRights += GrantRights; |
281 | client.OnFindAgent += FindFriend; | ||
265 | 282 | ||
266 | // We need to cache information for child agents as well as root agents so that friend edit/move/delete | 283 | // We need to cache information for child agents as well as root agents so that friend edit/move/delete |
267 | // permissions will work across borders where both regions are on different simulators. | 284 | // permissions will work across borders where both regions are on different simulators. |
@@ -326,20 +343,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
326 | } | 343 | } |
327 | } | 344 | } |
328 | 345 | ||
329 | private void OnMakeRootAgent(ScenePresence sp) | ||
330 | { | ||
331 | RecacheFriends(sp.ControllingClient); | ||
332 | |||
333 | lock (m_NeedsToNotifyStatus) | ||
334 | { | ||
335 | if (m_NeedsToNotifyStatus.Remove(sp.UUID)) | ||
336 | { | ||
337 | // Inform the friends that this user is online. This can only be done once the client is a Root Agent. | ||
338 | StatusChange(sp.UUID, true); | ||
339 | } | ||
340 | } | ||
341 | } | ||
342 | |||
343 | private void OnClientLogin(IClientAPI client) | 346 | private void OnClientLogin(IClientAPI client) |
344 | { | 347 | { |
345 | UUID agentID = client.AgentId; | 348 | UUID agentID = client.AgentId; |
@@ -358,8 +361,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
358 | m_NeedsListOfOnlineFriends.Add(agentID); | 361 | m_NeedsListOfOnlineFriends.Add(agentID); |
359 | } | 362 | } |
360 | 363 | ||
364 | public void IsNowRoot(ScenePresence sp) | ||
365 | { | ||
366 | OnMakeRootAgent(sp); | ||
367 | } | ||
368 | |||
361 | public virtual bool SendFriendsOnlineIfNeeded(IClientAPI client) | 369 | public virtual bool SendFriendsOnlineIfNeeded(IClientAPI client) |
362 | { | 370 | { |
371 | if (client == null) | ||
372 | return false; | ||
373 | |||
363 | UUID agentID = client.AgentId; | 374 | UUID agentID = client.AgentId; |
364 | 375 | ||
365 | // Check if the online friends list is needed | 376 | // Check if the online friends list is needed |
@@ -500,18 +511,20 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
500 | if (((fi.MyFlags & (int)FriendRights.CanSeeOnline) != 0) && (fi.TheirFlags != -1)) | 511 | if (((fi.MyFlags & (int)FriendRights.CanSeeOnline) != 0) && (fi.TheirFlags != -1)) |
501 | friendList.Add(fi); | 512 | friendList.Add(fi); |
502 | } | 513 | } |
503 | 514 | if(friendList.Count > 0) | |
504 | Util.FireAndForget( | 515 | { |
505 | delegate | 516 | Util.FireAndForget( |
506 | { | 517 | delegate |
507 | // m_log.DebugFormat( | 518 | { |
508 | // "[FRIENDS MODULE]: Notifying {0} friends of {1} of online status {2}", | 519 | // m_log.DebugFormat( |
509 | // friendList.Count, agentID, online); | 520 | // "[FRIENDS MODULE]: Notifying {0} friends of {1} of online status {2}", |
510 | 521 | // friendList.Count, agentID, online); | |
511 | // Notify about this user status | 522 | |
512 | StatusNotify(friendList, agentID, online); | 523 | // Notify about this user status |
513 | }, null, "FriendsModule.StatusChange" | 524 | StatusNotify(friendList, agentID, online); |
514 | ); | 525 | }, null, "FriendsModule.StatusChange" |
526 | ); | ||
527 | } | ||
515 | } | 528 | } |
516 | } | 529 | } |
517 | 530 | ||
@@ -540,6 +553,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
540 | // We do this regrouping so that we can efficiently send a single request rather than one for each | 553 | // We do this regrouping so that we can efficiently send a single request rather than one for each |
541 | // friend in what may be a very large friends list. | 554 | // friend in what may be a very large friends list. |
542 | PresenceInfo[] friendSessions = PresenceService.GetAgents(remoteFriendStringIds.ToArray()); | 555 | PresenceInfo[] friendSessions = PresenceService.GetAgents(remoteFriendStringIds.ToArray()); |
556 | if(friendSessions == null) | ||
557 | return; | ||
543 | 558 | ||
544 | foreach (PresenceInfo friendSession in friendSessions) | 559 | foreach (PresenceInfo friendSession in friendSessions) |
545 | { | 560 | { |
@@ -561,7 +576,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
561 | protected virtual void OnInstantMessage(IClientAPI client, GridInstantMessage im) | 576 | protected virtual void OnInstantMessage(IClientAPI client, GridInstantMessage im) |
562 | { | 577 | { |
563 | if ((InstantMessageDialog)im.dialog == InstantMessageDialog.FriendshipOffered) | 578 | if ((InstantMessageDialog)im.dialog == InstantMessageDialog.FriendshipOffered) |
564 | { | 579 | { |
565 | // we got a friendship offer | 580 | // we got a friendship offer |
566 | UUID principalID = new UUID(im.fromAgentID); | 581 | UUID principalID = new UUID(im.fromAgentID); |
567 | UUID friendID = new UUID(im.toAgentID); | 582 | UUID friendID = new UUID(im.toAgentID); |
@@ -596,7 +611,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
596 | im.imSessionID = im.fromAgentID; | 611 | im.imSessionID = im.fromAgentID; |
597 | im.fromAgentName = GetFriendshipRequesterName(agentID); | 612 | im.fromAgentName = GetFriendshipRequesterName(agentID); |
598 | 613 | ||
599 | // Try the local sim | 614 | // Try the local sim |
600 | if (LocalFriendshipOffered(friendID, im)) | 615 | if (LocalFriendshipOffered(friendID, im)) |
601 | return true; | 616 | return true; |
602 | 617 | ||
@@ -639,7 +654,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
639 | ccm.CreateCallingCard(client.AgentId, friendID, UUID.Zero); | 654 | ccm.CreateCallingCard(client.AgentId, friendID, UUID.Zero); |
640 | } | 655 | } |
641 | 656 | ||
642 | // Update the local cache. | 657 | // Update the local cache. |
643 | RecacheFriends(client); | 658 | RecacheFriends(client); |
644 | 659 | ||
645 | // | 660 | // |
@@ -695,7 +710,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
695 | } | 710 | } |
696 | } | 711 | } |
697 | } | 712 | } |
698 | 713 | ||
699 | public void RemoveFriendship(IClientAPI client, UUID exfriendID) | 714 | public void RemoveFriendship(IClientAPI client, UUID exfriendID) |
700 | { | 715 | { |
701 | if (!DeleteFriendship(client.AgentId, exfriendID)) | 716 | if (!DeleteFriendship(client.AgentId, exfriendID)) |
@@ -723,7 +738,65 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
723 | GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); | 738 | GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); |
724 | m_FriendsSimConnector.FriendshipTerminated(region, client.AgentId, exfriendID); | 739 | m_FriendsSimConnector.FriendshipTerminated(region, client.AgentId, exfriendID); |
725 | } | 740 | } |
726 | } | 741 | } |
742 | } | ||
743 | |||
744 | public void FindFriend(IClientAPI remoteClient,UUID HunterID ,UUID PreyID) | ||
745 | { | ||
746 | UUID requester = remoteClient.AgentId; | ||
747 | if(requester != HunterID) // only allow client agent to be the hunter (?) | ||
748 | return; | ||
749 | |||
750 | FriendInfo[] friends = GetFriendsFromCache(requester); | ||
751 | if (friends.Length == 0) | ||
752 | return; | ||
753 | |||
754 | FriendInfo friend = GetFriend(friends, PreyID); | ||
755 | if (friend == null) | ||
756 | return; | ||
757 | |||
758 | if(friend.TheirFlags == -1 || (friend.TheirFlags & (int)FriendRights.CanSeeOnMap) == 0) | ||
759 | return; | ||
760 | |||
761 | Scene hunterScene = (Scene)remoteClient.Scene; | ||
762 | |||
763 | if(hunterScene == null) | ||
764 | return; | ||
765 | |||
766 | // check local | ||
767 | ScenePresence sp; | ||
768 | double px; | ||
769 | double py; | ||
770 | if(hunterScene.TryGetScenePresence(PreyID, out sp)) | ||
771 | { | ||
772 | if(sp == null) | ||
773 | return; | ||
774 | px = hunterScene.RegionInfo.WorldLocX + sp.AbsolutePosition.X; | ||
775 | py = hunterScene.RegionInfo.WorldLocY + sp.AbsolutePosition.Y; | ||
776 | |||
777 | remoteClient.SendFindAgent(HunterID, PreyID, px, py); | ||
778 | return; | ||
779 | } | ||
780 | |||
781 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { PreyID.ToString() }); | ||
782 | |||
783 | if (friendSessions == null || friendSessions.Length == 0) | ||
784 | return; | ||
785 | |||
786 | PresenceInfo friendSession = friendSessions[0]; | ||
787 | if (friendSession == null) | ||
788 | return; | ||
789 | |||
790 | GridRegion region = GridService.GetRegionByUUID(hunterScene.RegionInfo.ScopeID, friendSession.RegionID); | ||
791 | |||
792 | if(region == null) | ||
793 | return; | ||
794 | |||
795 | // we don't have presence location so point to a standard region center for now | ||
796 | px = region.RegionLocX + 128.0; | ||
797 | py = region.RegionLocY + 128.0; | ||
798 | |||
799 | remoteClient.SendFindAgent(HunterID, PreyID, px, py); | ||
727 | } | 800 | } |
728 | 801 | ||
729 | public void GrantRights(IClientAPI remoteClient, UUID friendID, int rights) | 802 | public void GrantRights(IClientAPI remoteClient, UUID friendID, int rights) |
@@ -745,7 +818,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
745 | 818 | ||
746 | if (friend != null) // Found it | 819 | if (friend != null) // Found it |
747 | { | 820 | { |
748 | // Store it on the DB | 821 | // Store it on service |
749 | if (!StoreRights(requester, friendID, rights)) | 822 | if (!StoreRights(requester, friendID, rights)) |
750 | { | 823 | { |
751 | remoteClient.SendAlertMessage("Unable to grant rights."); | 824 | remoteClient.SendAlertMessage("Unable to grant rights."); |
@@ -869,28 +942,26 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
869 | return false; | 942 | return false; |
870 | } | 943 | } |
871 | 944 | ||
872 | public bool LocalGrantRights(UUID userID, UUID friendID, int userFlags, int rights) | 945 | public bool LocalGrantRights(UUID userID, UUID friendID, int oldRights, int newRights) |
873 | { | 946 | { |
874 | IClientAPI friendClient = LocateClientObject(friendID); | 947 | IClientAPI friendClient = LocateClientObject(friendID); |
875 | if (friendClient != null) | 948 | if (friendClient != null) |
876 | { | 949 | { |
877 | bool onlineBitChanged = ((rights ^ userFlags) & (int)FriendRights.CanSeeOnline) != 0; | 950 | int changedRights = newRights ^ oldRights; |
951 | bool onlineBitChanged = (changedRights & (int)FriendRights.CanSeeOnline) != 0; | ||
878 | if (onlineBitChanged) | 952 | if (onlineBitChanged) |
879 | { | 953 | { |
880 | if ((rights & (int)FriendRights.CanSeeOnline) == 1) | 954 | if ((newRights & (int)FriendRights.CanSeeOnline) == 1) |
881 | friendClient.SendAgentOnline(new UUID[] { userID }); | 955 | friendClient.SendAgentOnline(new UUID[] { userID }); |
882 | else | 956 | else |
883 | friendClient.SendAgentOffline(new UUID[] { userID }); | 957 | friendClient.SendAgentOffline(new UUID[] { userID }); |
884 | } | 958 | } |
885 | else | 959 | |
886 | { | 960 | if(changedRights != 0) |
887 | bool canEditObjectsChanged = ((rights ^ userFlags) & (int)FriendRights.CanModifyObjects) != 0; | 961 | friendClient.SendChangeUserRights(userID, friendID, newRights); |
888 | if (canEditObjectsChanged) | ||
889 | friendClient.SendChangeUserRights(userID, friendID, rights); | ||
890 | } | ||
891 | 962 | ||
892 | // Update local cache | 963 | // Update local cache |
893 | UpdateLocalCache(userID, friendID, rights); | 964 | UpdateLocalCache(userID, friendID, newRights); |
894 | 965 | ||
895 | return true; | 966 | return true; |
896 | } | 967 | } |
@@ -946,8 +1017,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
946 | lock (m_Friends) | 1017 | lock (m_Friends) |
947 | { | 1018 | { |
948 | FriendInfo[] friends = GetFriendsFromCache(friendID); | 1019 | FriendInfo[] friends = GetFriendsFromCache(friendID); |
949 | FriendInfo finfo = GetFriend(friends, userID); | 1020 | if(friends != EMPTY_FRIENDS) |
950 | finfo.TheirFlags = rights; | 1021 | { |
1022 | FriendInfo finfo = GetFriend(friends, userID); | ||
1023 | if(finfo!= null) | ||
1024 | finfo.TheirFlags = rights; | ||
1025 | } | ||
951 | } | 1026 | } |
952 | } | 1027 | } |
953 | 1028 | ||