From dd36e23a627e43985ee10563f74c60a61b05faa6 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 30 Mar 2012 01:57:38 +0100 Subject: [PATCH] Make default "show friends" console command show friends fetched from the friends service. There is no a --cache option which will show friends from the local cache if available. --- .../Avatar/Friends/FriendsModule.cs | 4 +- .../Avatar/Friends/HGFriendsModule.cs | 3 +- .../Avatar/Friends/FriendsCommandsModule.cs | 87 ++++++++++++++++++- prebuild.xml | 1 + 4 files changed, 87 insertions(+), 8 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 99d1c2a692..bbe8ca1d17 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs @@ -110,7 +110,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } } - protected IFriendsService FriendsService + public IFriendsService FriendsService { get { @@ -937,7 +937,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } } - protected virtual FriendInfo[] GetFriendsFromService(IClientAPI client) + public virtual FriendInfo[] GetFriendsFromService(IClientAPI client) { return FriendsService.GetFriends(client.AgentId); } diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs index 539e656992..47f71ac4e1 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs @@ -384,8 +384,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends return null; } - - protected override FriendInfo[] GetFriendsFromService(IClientAPI client) + public override FriendInfo[] GetFriendsFromService(IClientAPI client) { // m_log.DebugFormat("[HGFRIENDS MODULE]: Entering GetFriendsFromService for {0}", client.Name); Boolean agentIsLocal = true; diff --git a/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs b/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs index 2bcb8a736c..fe737705ea 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs @@ -32,14 +32,17 @@ using System.Reflection; using System.Text; using log4net; using Mono.Addins; +using NDesk.Options; using Nini.Config; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Framework.Console; using OpenSim.Framework.Statistics; using OpenSim.Region.ClientStack.LindenUDP; +using OpenSim.Region.CoreModules.Avatar.Friends; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; namespace OpenSim.Region.OptionalModules.Avatar.Friends @@ -100,10 +103,11 @@ namespace OpenSim.Region.OptionalModules.Avatar.Friends if (m_friendsModule != null && m_userManagementModule != null) { m_scene.AddCommand( - "Friends", this, "friends show cache", - "friends show cache [ ]", - "Show the friends cache for the given user", - HandleFriendsShowCacheCommand); + "Friends", this, "friends show", + "friends show [--cache] ", + "Show the friends for the given user if they exist.\n", + "The --cache option will show locally cached information for that user.", + HandleFriendsShowCommand); } } @@ -161,5 +165,80 @@ namespace OpenSim.Region.OptionalModules.Avatar.Friends MainConsole.Instance.OutputFormat("{0} {1} {2}", friendName, friend.MyFlags, friend.TheirFlags); } } + + protected void HandleFriendsShowCommand(string module, string[] cmd) + { + Dictionary options = new Dictionary(); + OptionSet optionSet = new OptionSet().Add("c|cache", delegate (string v) { options["cache"] = v != null; }); + + List mainParams = optionSet.Parse(cmd); + + if (mainParams.Count != 4) + { + MainConsole.Instance.OutputFormat("Usage: friends show [--cache] "); + return; + } + + string firstName = mainParams[2]; + string lastName = mainParams[3]; + + UUID userId = m_userManagementModule.GetUserIdByName(firstName, lastName); + +// UserAccount ua +// = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, firstName, lastName); + + if (userId == UUID.Zero) + { + MainConsole.Instance.OutputFormat("No such user as {0} {1}", firstName, lastName); + return; + } + + FriendInfo[] friends; + + if (options.ContainsKey("cache")) + { + if (!m_friendsModule.AreFriendsCached(userId)) + { + MainConsole.Instance.OutputFormat("No friends cached on this simulator for {0} {1}", firstName, lastName); + return; + } + else + { + friends = m_friendsModule.GetFriendsFromCache(userId); + } + } + else + { + // FIXME: We're forced to do this right now because IFriendsService has no region connectors. We can't + // just expose FriendsModule.GetFriendsFromService() because it forces an IClientAPI requirement that + // can't currently be changed because of HGFriendsModule code that takes the scene from the client. + friends = ((FriendsModule)m_friendsModule).FriendsService.GetFriends(userId); + } + + MainConsole.Instance.OutputFormat("Friends for {0} {1} {2}:", firstName, lastName, userId); + + MainConsole.Instance.OutputFormat("UUID, Name, MyFlags, TheirFlags"); + + foreach (FriendInfo friend in friends) + { +// MainConsole.Instance.OutputFormat(friend.PrincipalID.ToString()); + +// string friendFirstName, friendLastName; +// +// UserAccount friendUa +// = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, friend.PrincipalID); + + UUID friendId; + string friendName; + + if (UUID.TryParse(friend.Friend, out friendId)) + friendName = m_userManagementModule.GetUserName(friendId); + else + friendName = friend.Friend; + + MainConsole.Instance.OutputFormat( + "{0} {1} {2} {3}", friend.Friend, friendName, friend.MyFlags, friend.TheirFlags); + } + } } } \ No newline at end of file diff --git a/prebuild.xml b/prebuild.xml index 70a3fa21d4..4383ca5b97 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -1669,6 +1669,7 @@ +