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.
0.7.3-extended
Justin Clark-Casey (justincc) 2012-03-30 01:57:38 +01:00
parent e2dade05d9
commit dd36e23a62
4 changed files with 87 additions and 8 deletions

View File

@ -110,7 +110,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
} }
} }
protected IFriendsService FriendsService public IFriendsService FriendsService
{ {
get 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); return FriendsService.GetFriends(client.AgentId);
} }

View File

@ -384,8 +384,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
return null; return null;
} }
public override FriendInfo[] GetFriendsFromService(IClientAPI client)
protected override FriendInfo[] GetFriendsFromService(IClientAPI client)
{ {
// m_log.DebugFormat("[HGFRIENDS MODULE]: Entering GetFriendsFromService for {0}", client.Name); // m_log.DebugFormat("[HGFRIENDS MODULE]: Entering GetFriendsFromService for {0}", client.Name);
Boolean agentIsLocal = true; Boolean agentIsLocal = true;

View File

@ -32,14 +32,17 @@ using System.Reflection;
using System.Text; using System.Text;
using log4net; using log4net;
using Mono.Addins; using Mono.Addins;
using NDesk.Options;
using Nini.Config; using Nini.Config;
using OpenMetaverse; using OpenMetaverse;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Console; using OpenSim.Framework.Console;
using OpenSim.Framework.Statistics; using OpenSim.Framework.Statistics;
using OpenSim.Region.ClientStack.LindenUDP; using OpenSim.Region.ClientStack.LindenUDP;
using OpenSim.Region.CoreModules.Avatar.Friends;
using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
namespace OpenSim.Region.OptionalModules.Avatar.Friends namespace OpenSim.Region.OptionalModules.Avatar.Friends
@ -100,10 +103,11 @@ namespace OpenSim.Region.OptionalModules.Avatar.Friends
if (m_friendsModule != null && m_userManagementModule != null) if (m_friendsModule != null && m_userManagementModule != null)
{ {
m_scene.AddCommand( m_scene.AddCommand(
"Friends", this, "friends show cache", "Friends", this, "friends show",
"friends show cache [<first-name> <last-name>]", "friends show [--cache] <first-name> <last-name>",
"Show the friends cache for the given user", "Show the friends for the given user if they exist.\n",
HandleFriendsShowCacheCommand); "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); MainConsole.Instance.OutputFormat("{0} {1} {2}", friendName, friend.MyFlags, friend.TheirFlags);
} }
} }
protected void HandleFriendsShowCommand(string module, string[] cmd)
{
Dictionary<string, object> options = new Dictionary<string, object>();
OptionSet optionSet = new OptionSet().Add("c|cache", delegate (string v) { options["cache"] = v != null; });
List<string> mainParams = optionSet.Parse(cmd);
if (mainParams.Count != 4)
{
MainConsole.Instance.OutputFormat("Usage: friends show [--cache] <first-name> <last-name>");
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);
}
}
} }
} }

View File

@ -1669,6 +1669,7 @@
<Reference name="System.Xml"/> <Reference name="System.Xml"/>
<Reference name="System.Drawing"/> <Reference name="System.Drawing"/>
<Reference name="System.Web"/> <Reference name="System.Web"/>
<Reference name="NDesk.Options" path="../../../bin/"/>
<Reference name="OpenMetaverseTypes" path="../../../bin/"/> <Reference name="OpenMetaverseTypes" path="../../../bin/"/>
<Reference name="OpenMetaverse.StructuredData" path="../../../bin/"/> <Reference name="OpenMetaverse.StructuredData" path="../../../bin/"/>
<Reference name="OpenMetaverse" path="../../../bin/"/> <Reference name="OpenMetaverse" path="../../../bin/"/>