aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-03-30 01:05:29 +0100
committerJustin Clark-Casey (justincc)2012-03-30 01:05:29 +0100
commitbce7964ac2b0e67ff8c8e5ab00bb45b93da219ad (patch)
tree3a34b9280aa700c69ce3ceece1926b5a9304e027 /OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
parentAdd simple login test with online friends. Add IFriendsModule.GrantRights() ... (diff)
downloadopensim-SC_OLD-bce7964ac2b0e67ff8c8e5ab00bb45b93da219ad.zip
opensim-SC_OLD-bce7964ac2b0e67ff8c8e5ab00bb45b93da219ad.tar.gz
opensim-SC_OLD-bce7964ac2b0e67ff8c8e5ab00bb45b93da219ad.tar.bz2
opensim-SC_OLD-bce7964ac2b0e67ff8c8e5ab00bb45b93da219ad.tar.xz
refactor: Move "friends show cache" console command out into separate FriendsCommandsModule.
Expose required methods on IFriendsModule. Rename GetFriends() -> GetFriendsFromCache() for self-documentation
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs98
1 files changed, 12 insertions, 86 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
index 9d7012e..37e6600 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
@@ -213,14 +213,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
213 scene.EventManager.OnClientLogin += OnClientLogin; 213 scene.EventManager.OnClientLogin += OnClientLogin;
214 } 214 }
215 215
216 public virtual void RegionLoaded(Scene scene) 216 public virtual void RegionLoaded(Scene scene) {}
217 {
218 scene.AddCommand(
219 "Friends", this, "friends show cache",
220 "friends show cache [<first-name> <last-name>]",
221 "Show the friends cache for the given user",
222 HandleFriendsShowCacheCommand);
223 }
224 217
225 public void RemoveRegion(Scene scene) 218 public void RemoveRegion(Scene scene)
226 { 219 {
@@ -244,7 +237,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
244 237
245 public virtual int GetRightsGrantedByFriend(UUID principalID, UUID friendID) 238 public virtual int GetRightsGrantedByFriend(UUID principalID, UUID friendID)
246 { 239 {
247 FriendInfo[] friends = GetFriends(principalID); 240 FriendInfo[] friends = GetFriendsFromCache(principalID);
248 FriendInfo finfo = GetFriend(friends, friendID); 241 FriendInfo finfo = GetFriend(friends, friendID);
249 if (finfo != null) 242 if (finfo != null)
250 { 243 {
@@ -362,7 +355,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
362 355
363 // Send outstanding friendship offers 356 // Send outstanding friendship offers
364 List<string> outstanding = new List<string>(); 357 List<string> outstanding = new List<string>();
365 FriendInfo[] friends = GetFriends(agentID); 358 FriendInfo[] friends = GetFriendsFromCache(agentID);
366 foreach (FriendInfo fi in friends) 359 foreach (FriendInfo fi in friends)
367 { 360 {
368 if (fi.TheirFlags == -1) 361 if (fi.TheirFlags == -1)
@@ -419,7 +412,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
419 { 412 {
420 List<string> friendList = new List<string>(); 413 List<string> friendList = new List<string>();
421 414
422 FriendInfo[] friends = GetFriends(userID); 415 FriendInfo[] friends = GetFriendsFromCache(userID);
423 foreach (FriendInfo fi in friends) 416 foreach (FriendInfo fi in friends)
424 { 417 {
425 if (((fi.TheirFlags & (int)FriendRights.CanSeeOnline) != 0) && (fi.TheirFlags != -1)) 418 if (((fi.TheirFlags & (int)FriendRights.CanSeeOnline) != 0) && (fi.TheirFlags != -1))
@@ -492,7 +485,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
492 /// <param name="online"></param> 485 /// <param name="online"></param>
493 private void StatusChange(UUID agentID, bool online) 486 private void StatusChange(UUID agentID, bool online)
494 { 487 {
495 FriendInfo[] friends = GetFriends(agentID); 488 FriendInfo[] friends = GetFriendsFromCache(agentID);
496 if (friends.Length > 0) 489 if (friends.Length > 0)
497 { 490 {
498 List<FriendInfo> friendList = new List<FriendInfo>(); 491 List<FriendInfo> friendList = new List<FriendInfo>();
@@ -564,7 +557,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
564 m_log.DebugFormat("[FRIENDS]: {0} ({1}) offered friendship to {2} ({3})", principalID, client.FirstName + client.LastName, friendID, im.fromAgentName); 557 m_log.DebugFormat("[FRIENDS]: {0} ({1}) offered friendship to {2} ({3})", principalID, client.FirstName + client.LastName, friendID, im.fromAgentName);
565 558
566 // Check that the friendship doesn't exist yet 559 // Check that the friendship doesn't exist yet
567 FriendInfo[] finfos = GetFriends(principalID); 560 FriendInfo[] finfos = GetFriendsFromCache(principalID);
568 if (finfos != null) 561 if (finfos != null)
569 { 562 {
570 FriendInfo f = GetFriend(finfos, friendID); 563 FriendInfo f = GetFriend(finfos, friendID);
@@ -729,7 +722,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
729 "[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}", 722 "[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}",
730 requester, rights, friendID); 723 requester, rights, friendID);
731 724
732 FriendInfo[] friends = GetFriends(requester); 725 FriendInfo[] friends = GetFriendsFromCache(requester);
733 if (friends.Length == 0) 726 if (friends.Length == 0)
734 { 727 {
735 return; 728 return;
@@ -915,20 +908,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
915 #endregion 908 #endregion
916 909
917 #region Get / Set friends in several flavours 910 #region Get / Set friends in several flavours
918 /// <summary> 911
919 /// Get friends from local cache only 912 public FriendInfo[] GetFriendsFromCache(UUID userID)
920 /// </summary>
921 /// <param name="agentID"></param>
922 /// <returns>
923 /// An empty array if the user has no friends or friends have not been cached.
924 /// </returns>
925 protected FriendInfo[] GetFriends(UUID agentID)
926 { 913 {
927 UserFriendData friendsData; 914 UserFriendData friendsData;
928 915
929 lock (m_Friends) 916 lock (m_Friends)
930 { 917 {
931 if (m_Friends.TryGetValue(agentID, out friendsData)) 918 if (m_Friends.TryGetValue(userID, out friendsData))
932 return friendsData.Friends; 919 return friendsData.Friends;
933 } 920 }
934 921
@@ -946,7 +933,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
946 // Update local cache 933 // Update local cache
947 lock (m_Friends) 934 lock (m_Friends)
948 { 935 {
949 FriendInfo[] friends = GetFriends(friendID); 936 FriendInfo[] friends = GetFriendsFromCache(friendID);
950 FriendInfo finfo = GetFriend(friends, userID); 937 FriendInfo finfo = GetFriend(friends, userID);
951 finfo.TheirFlags = rights; 938 finfo.TheirFlags = rights;
952 } 939 }
@@ -970,12 +957,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
970 } 957 }
971 } 958 }
972 959
973 /// <summary> 960 public bool AreFriendsCached(UUID userID)
974 /// Are friends cached on this simulator for a particular user?
975 /// </summary>
976 /// <param name="userID"></param>
977 /// <returns></returns>
978 protected bool AreFriendsCached(UUID userID)
979 { 961 {
980 lock (m_Friends) 962 lock (m_Friends)
981 return m_Friends.ContainsKey(userID); 963 return m_Friends.ContainsKey(userID);
@@ -1006,61 +988,5 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
1006 } 988 }
1007 989
1008 #endregion 990 #endregion
1009
1010 protected void HandleFriendsShowCacheCommand(string module, string[] cmd)
1011 {
1012 if (cmd.Length != 5)
1013 {
1014 MainConsole.Instance.OutputFormat("Usage: friends show cache [<first-name> <last-name>]");
1015 return;
1016 }
1017
1018 string firstName = cmd[3];
1019 string lastName = cmd[4];
1020
1021 IUserManagement umModule = m_Scenes[0].RequestModuleInterface<IUserManagement>();
1022 UUID userId = umModule.GetUserIdByName(firstName, lastName);
1023
1024// UserAccount ua
1025// = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, firstName, lastName);
1026
1027 if (userId == UUID.Zero)
1028 {
1029 MainConsole.Instance.OutputFormat("No such user as {0} {1}", firstName, lastName);
1030 return;
1031 }
1032
1033 if (!AreFriendsCached(userId))
1034 {
1035 MainConsole.Instance.OutputFormat("No friends cached on this simulator for {0} {1}", firstName, lastName);
1036 return;
1037 }
1038
1039 MainConsole.Instance.OutputFormat("Cached friends for {0} {1}:", firstName, lastName);
1040
1041 MainConsole.Instance.OutputFormat("UUID\n");
1042
1043 FriendInfo[] friends = GetFriends(userId);
1044
1045 foreach (FriendInfo friend in friends)
1046 {
1047// MainConsole.Instance.OutputFormat(friend.PrincipalID.ToString());
1048
1049// string friendFirstName, friendLastName;
1050//
1051// UserAccount friendUa
1052// = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, friend.PrincipalID);
1053
1054 UUID friendId;
1055 string friendName;
1056
1057 if (UUID.TryParse(friend.Friend, out friendId))
1058 friendName = umModule.GetUserName(friendId);
1059 else
1060 friendName = friend.Friend;
1061
1062 MainConsole.Instance.OutputFormat("{0} {1} {2}", friendName, friend.MyFlags, friend.TheirFlags);
1063 }
1064 }
1065 } 991 }
1066} 992}