diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs | 103 |
1 files changed, 68 insertions, 35 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 21cd924..4879d20 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs | |||
@@ -69,7 +69,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 | ||
72 | private static readonly FriendInfo[] EMPTY_FRIENDS = new FriendInfo[0]; | 72 | protected static readonly FriendInfo[] EMPTY_FRIENDS = new FriendInfo[0]; |
73 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 73 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
74 | 74 | ||
75 | protected List<Scene> m_Scenes = new List<Scene>(); | 75 | protected List<Scene> m_Scenes = new List<Scene>(); |
@@ -187,6 +187,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
187 | { | 187 | { |
188 | if (!m_Enabled) | 188 | if (!m_Enabled) |
189 | return; | 189 | return; |
190 | m_log.DebugFormat("[FRIENDS MODULE]: AddRegion on {0}", Name); | ||
190 | 191 | ||
191 | m_Scenes.Add(scene); | 192 | m_Scenes.Add(scene); |
192 | scene.RegisterModuleInterface<IFriendsModule>(this); | 193 | scene.RegisterModuleInterface<IFriendsModule>(this); |
@@ -221,13 +222,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
221 | 222 | ||
222 | #endregion | 223 | #endregion |
223 | 224 | ||
224 | public uint GetFriendPerms(UUID principalID, UUID friendID) | 225 | public virtual uint GetFriendPerms(UUID principalID, UUID friendID) |
225 | { | 226 | { |
226 | FriendInfo[] friends = GetFriends(principalID); | 227 | FriendInfo[] friends = GetFriends(principalID); |
227 | foreach (FriendInfo fi in friends) | 228 | FriendInfo finfo = GetFriend(friends, friendID); |
229 | if (finfo != null) | ||
228 | { | 230 | { |
229 | if (fi.Friend == friendID.ToString()) | 231 | return (uint)finfo.TheirFlags; |
230 | return (uint)fi.TheirFlags; | ||
231 | } | 232 | } |
232 | 233 | ||
233 | return 0; | 234 | return 0; |
@@ -241,14 +242,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
241 | client.OnTerminateFriendship += OnTerminateFriendship; | 242 | client.OnTerminateFriendship += OnTerminateFriendship; |
242 | client.OnGrantUserRights += OnGrantUserRights; | 243 | client.OnGrantUserRights += OnGrantUserRights; |
243 | 244 | ||
244 | Util.FireAndForget(delegate { FetchFriendslist(client.AgentId); }); | 245 | Util.FireAndForget(delegate { FetchFriendslist(client); }); |
245 | } | 246 | } |
246 | 247 | ||
247 | /// Fetch the friends list or increment the refcount for the existing | 248 | /// Fetch the friends list or increment the refcount for the existing |
248 | /// friends list | 249 | /// friends list |
249 | /// Returns true if the list was fetched, false if it wasn't | 250 | /// Returns true if the list was fetched, false if it wasn't |
250 | protected virtual bool FetchFriendslist(UUID agentID) | 251 | protected virtual bool FetchFriendslist(IClientAPI client) |
251 | { | 252 | { |
253 | UUID agentID = client.AgentId; | ||
252 | lock (m_Friends) | 254 | lock (m_Friends) |
253 | { | 255 | { |
254 | UserFriendData friendsData; | 256 | UserFriendData friendsData; |
@@ -261,7 +263,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
261 | { | 263 | { |
262 | friendsData = new UserFriendData(); | 264 | friendsData = new UserFriendData(); |
263 | friendsData.PrincipalID = agentID; | 265 | friendsData.PrincipalID = agentID; |
264 | friendsData.Friends = FriendsService.GetFriends(agentID); | 266 | friendsData.Friends = GetFriendsFromService(client); |
265 | friendsData.Refcount = 1; | 267 | friendsData.Refcount = 1; |
266 | 268 | ||
267 | m_Friends[agentID] = friendsData; | 269 | m_Friends[agentID] = friendsData; |
@@ -270,6 +272,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
270 | } | 272 | } |
271 | } | 273 | } |
272 | 274 | ||
275 | protected virtual FriendInfo[] GetFriendsFromService(IClientAPI client) | ||
276 | { | ||
277 | return FriendsService.GetFriends(client.AgentId); | ||
278 | } | ||
279 | |||
273 | private void OnClientClosed(UUID agentID, Scene scene) | 280 | private void OnClientClosed(UUID agentID, Scene scene) |
274 | { | 281 | { |
275 | ScenePresence sp = scene.GetScenePresence(agentID); | 282 | ScenePresence sp = scene.GetScenePresence(agentID); |
@@ -293,8 +300,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
293 | 300 | ||
294 | private void OnMakeRootAgent(ScenePresence sp) | 301 | private void OnMakeRootAgent(ScenePresence sp) |
295 | { | 302 | { |
296 | UUID agentID = sp.ControllingClient.AgentId; | 303 | UpdateFriendsCache(sp.ControllingClient); |
297 | UpdateFriendsCache(agentID); | ||
298 | } | 304 | } |
299 | 305 | ||
300 | private void OnClientLogin(IClientAPI client) | 306 | private void OnClientLogin(IClientAPI client) |
@@ -309,7 +315,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
309 | m_NeedsListOfFriends.Add(agentID); | 315 | m_NeedsListOfFriends.Add(agentID); |
310 | } | 316 | } |
311 | 317 | ||
312 | public void SendFriendsOnlineIfNeeded(IClientAPI client) | 318 | public virtual bool SendFriendsOnlineIfNeeded(IClientAPI client) |
313 | { | 319 | { |
314 | UUID agentID = client.AgentId; | 320 | UUID agentID = client.AgentId; |
315 | 321 | ||
@@ -317,7 +323,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
317 | lock (m_NeedsListOfFriends) | 323 | lock (m_NeedsListOfFriends) |
318 | { | 324 | { |
319 | if (!m_NeedsListOfFriends.Remove(agentID)) | 325 | if (!m_NeedsListOfFriends.Remove(agentID)) |
320 | return; | 326 | return false; |
321 | } | 327 | } |
322 | 328 | ||
323 | // Send the friends online | 329 | // Send the friends online |
@@ -366,6 +372,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
366 | // Finally | 372 | // Finally |
367 | LocalFriendshipOffered(agentID, im); | 373 | LocalFriendshipOffered(agentID, im); |
368 | } | 374 | } |
375 | |||
376 | return true; | ||
369 | } | 377 | } |
370 | 378 | ||
371 | protected virtual string FriendshipMessage(string friendID) | 379 | protected virtual string FriendshipMessage(string friendID) |
@@ -579,7 +587,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
579 | StoreFriendships(agentID, friendID); | 587 | StoreFriendships(agentID, friendID); |
580 | 588 | ||
581 | // Update the local cache | 589 | // Update the local cache |
582 | UpdateFriendsCache(agentID); | 590 | UpdateFriendsCache(client); |
583 | 591 | ||
584 | // | 592 | // |
585 | // Notify the friend | 593 | // Notify the friend |
@@ -647,7 +655,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
647 | DeleteFriendship(agentID, exfriendID); | 655 | DeleteFriendship(agentID, exfriendID); |
648 | 656 | ||
649 | // Update local cache | 657 | // Update local cache |
650 | UpdateFriendsCache(agentID); | 658 | UpdateFriendsCache(client); |
651 | 659 | ||
652 | client.SendTerminateFriend(exfriendID); | 660 | client.SendTerminateFriend(exfriendID); |
653 | 661 | ||
@@ -679,23 +687,26 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
679 | 687 | ||
680 | private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights) | 688 | private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights) |
681 | { | 689 | { |
690 | m_log.DebugFormat("[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}", requester, rights, target); | ||
691 | |||
682 | FriendInfo[] friends = GetFriends(remoteClient.AgentId); | 692 | FriendInfo[] friends = GetFriends(remoteClient.AgentId); |
683 | if (friends.Length == 0) | 693 | if (friends.Length == 0) |
694 | { | ||
695 | m_log.DebugFormat("[XXX]: agent {0} has no friends", requester); | ||
684 | return; | 696 | return; |
697 | } | ||
685 | 698 | ||
686 | m_log.DebugFormat("[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}", requester, rights, target); | ||
687 | // Let's find the friend in this user's friend list | 699 | // Let's find the friend in this user's friend list |
688 | FriendInfo friend = null; | 700 | FriendInfo friend = GetFriend(friends, target); |
689 | foreach (FriendInfo fi in friends) | ||
690 | { | ||
691 | if (fi.Friend == target.ToString()) | ||
692 | friend = fi; | ||
693 | } | ||
694 | 701 | ||
695 | if (friend != null) // Found it | 702 | if (friend != null) // Found it |
696 | { | 703 | { |
697 | // Store it on the DB | 704 | // Store it on the DB |
698 | FriendsService.StoreFriend(requester.ToString(), target.ToString(), rights); | 705 | if (!SimpleStore(requester, target, rights)) |
706 | { | ||
707 | remoteClient.SendAlertMessage("Unable to grant rights."); | ||
708 | return; | ||
709 | } | ||
699 | 710 | ||
700 | // Store it in the local cache | 711 | // Store it in the local cache |
701 | int myFlags = friend.MyFlags; | 712 | int myFlags = friend.MyFlags; |
@@ -725,6 +736,24 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
725 | } | 736 | } |
726 | } | 737 | } |
727 | } | 738 | } |
739 | else | ||
740 | m_log.DebugFormat("[FRIENDS MODULE]: friend {0} not found for {1}", target, requester); | ||
741 | } | ||
742 | |||
743 | protected virtual bool SimpleStore(UUID agentID, UUID friendID, int rights) | ||
744 | { | ||
745 | FriendsService.StoreFriend(agentID.ToString(), friendID.ToString(), rights); | ||
746 | return true; | ||
747 | } | ||
748 | |||
749 | protected virtual FriendInfo GetFriend(FriendInfo[] friends, UUID friendID) | ||
750 | { | ||
751 | foreach (FriendInfo fi in friends) | ||
752 | { | ||
753 | if (fi.Friend == friendID.ToString()) | ||
754 | return fi; | ||
755 | } | ||
756 | return null; | ||
728 | } | 757 | } |
729 | 758 | ||
730 | #region Local | 759 | #region Local |
@@ -753,7 +782,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
753 | friendClient.SendInstantMessage(im); | 782 | friendClient.SendInstantMessage(im); |
754 | 783 | ||
755 | // Update the local cache | 784 | // Update the local cache |
756 | UpdateFriendsCache(friendID); | 785 | UpdateFriendsCache(friendClient); |
757 | 786 | ||
758 | // we're done | 787 | // we're done |
759 | return true; | 788 | return true; |
@@ -786,7 +815,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
786 | // the friend in this sim as root agent | 815 | // the friend in this sim as root agent |
787 | friendClient.SendTerminateFriend(exfriendID); | 816 | friendClient.SendTerminateFriend(exfriendID); |
788 | // update local cache | 817 | // update local cache |
789 | UpdateFriendsCache(exfriendID); | 818 | UpdateFriendsCache(friendClient); |
790 | // we're done | 819 | // we're done |
791 | return true; | 820 | return true; |
792 | } | 821 | } |
@@ -816,15 +845,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
816 | } | 845 | } |
817 | 846 | ||
818 | // Update local cache | 847 | // Update local cache |
819 | lock (m_Friends) | 848 | UpdateLocalCache(userID, friendID, rights); |
820 | { | ||
821 | FriendInfo[] friends = GetFriends(friendID); | ||
822 | foreach (FriendInfo finfo in friends) | ||
823 | { | ||
824 | if (finfo.Friend == userID.ToString()) | ||
825 | finfo.TheirFlags = rights; | ||
826 | } | ||
827 | } | ||
828 | 849 | ||
829 | return true; | 850 | return true; |
830 | } | 851 | } |
@@ -866,13 +887,25 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
866 | return EMPTY_FRIENDS; | 887 | return EMPTY_FRIENDS; |
867 | } | 888 | } |
868 | 889 | ||
869 | private void UpdateFriendsCache(UUID agentID) | 890 | private void UpdateFriendsCache(IClientAPI client) |
870 | { | 891 | { |
892 | UUID agentID = client.AgentId; | ||
871 | lock (m_Friends) | 893 | lock (m_Friends) |
872 | { | 894 | { |
873 | UserFriendData friendsData; | 895 | UserFriendData friendsData; |
874 | if (m_Friends.TryGetValue(agentID, out friendsData)) | 896 | if (m_Friends.TryGetValue(agentID, out friendsData)) |
875 | friendsData.Friends = FriendsService.GetFriends(agentID); | 897 | friendsData.Friends = GetFriendsFromService(client); |
898 | } | ||
899 | } | ||
900 | |||
901 | protected void UpdateLocalCache(UUID userID, UUID friendID, int rights) | ||
902 | { | ||
903 | // Update local cache | ||
904 | lock (m_Friends) | ||
905 | { | ||
906 | FriendInfo[] friends = GetFriends(friendID); | ||
907 | FriendInfo finfo = GetFriend(friends, userID); | ||
908 | finfo.TheirFlags = rights; | ||
876 | } | 909 | } |
877 | } | 910 | } |
878 | } | 911 | } |