aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules
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
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')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs98
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs14
2 files changed, 19 insertions, 93 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}
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
index b666dae..d3a3ee4 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
@@ -163,7 +163,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
163 UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID, client.AgentId); 163 UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID, client.AgentId);
164 if (account == null) // foreign 164 if (account == null) // foreign
165 { 165 {
166 FriendInfo[] friends = GetFriends(client.AgentId); 166 FriendInfo[] friends = GetFriendsFromCache(client.AgentId);
167 foreach (FriendInfo f in friends) 167 foreach (FriendInfo f in friends)
168 { 168 {
169 client.SendChangeUserRights(new UUID(f.Friend), client.AgentId, f.TheirFlags); 169 client.SendChangeUserRights(new UUID(f.Friend), client.AgentId, f.TheirFlags);
@@ -346,7 +346,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
346 346
347 if (agentIsLocal) // agent is local, friend is foreigner 347 if (agentIsLocal) // agent is local, friend is foreigner
348 { 348 {
349 FriendInfo[] finfos = GetFriends(agentID); 349 FriendInfo[] finfos = GetFriendsFromCache(agentID);
350 FriendInfo finfo = GetFriend(finfos, friendID); 350 FriendInfo finfo = GetFriend(finfos, friendID);
351 if (finfo != null) 351 if (finfo != null)
352 { 352 {
@@ -453,7 +453,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
453 bool confirming = false; 453 bool confirming = false;
454 if (friendUUI == string.Empty) 454 if (friendUUI == string.Empty)
455 { 455 {
456 finfos = GetFriends(agentID); 456 finfos = GetFriendsFromCache(agentID);
457 foreach (FriendInfo finfo in finfos) 457 foreach (FriendInfo finfo in finfos)
458 { 458 {
459 if (finfo.TheirFlags == -1) 459 if (finfo.TheirFlags == -1)
@@ -546,7 +546,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
546 // Delete any previous friendship relations 546 // Delete any previous friendship relations
547 FriendInfo[] finfos = null; 547 FriendInfo[] finfos = null;
548 FriendInfo f = null; 548 FriendInfo f = null;
549 finfos = GetFriends(a1); 549 finfos = GetFriendsFromCache(a1);
550 if (finfos != null) 550 if (finfos != null)
551 { 551 {
552 f = GetFriend(finfos, a2); 552 f = GetFriend(finfos, a2);
@@ -558,7 +558,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
558 } 558 }
559 } 559 }
560 560
561 finfos = GetFriends(a2); 561 finfos = GetFriendsFromCache(a2);
562 if (finfos != null) 562 if (finfos != null)
563 { 563 {
564 f = GetFriend(finfos, a1); 564 f = GetFriend(finfos, a1);
@@ -595,7 +595,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
595 if (agentIsLocal) // agent is local, 'friend' is foreigner 595 if (agentIsLocal) // agent is local, 'friend' is foreigner
596 { 596 {
597 // We need to look for its information in the friends list itself 597 // We need to look for its information in the friends list itself
598 FriendInfo[] finfos = GetFriends(agentID); 598 FriendInfo[] finfos = GetFriendsFromCache(agentID);
599 FriendInfo finfo = GetFriend(finfos, exfriendID); 599 FriendInfo finfo = GetFriend(finfos, exfriendID);
600 if (finfo != null) 600 if (finfo != null)
601 { 601 {
@@ -639,7 +639,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
639 private string GetUUI(UUID localUser, UUID foreignUser) 639 private string GetUUI(UUID localUser, UUID foreignUser)
640 { 640 {
641 // Let's see if the user is here by any chance 641 // Let's see if the user is here by any chance
642 FriendInfo[] finfos = GetFriends(localUser); 642 FriendInfo[] finfos = GetFriendsFromCache(localUser);
643 if (finfos != EMPTY_FRIENDS) // friend is here, cool 643 if (finfos != EMPTY_FRIENDS) // friend is here, cool
644 { 644 {
645 FriendInfo finfo = GetFriend(finfos, foreignUser); 645 FriendInfo finfo = GetFriend(finfos, foreignUser);