LIBOMV-630: TestClient improvements (patch by Kephra Nurmi)

Improved TestClient:
added '@' as a command prefix to target one avatar only and to check, if a named avatar is logged in.

Improved TestClient to add new commands:

groupmembers GroupnameOrUUID - shows groupmembers UUIDs
grouproles GroupnameOrUUID - shows grouproles UUID and Names
invitegroup AvatarUUID GroupUUID RoleUUID* - invites an avatar into a group (without querying groupmembers first !-)

added public Dictionary<UUID, Group> GroupsCache = null; to TestClient.cs to refactor copy and paste code of group commands.
added friend.UUID to output of FriendsCommand.cs
swapped output of UUID and name in GroupsCommand.cs



git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@2989 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
Latif Khalifa
2009-07-15 23:23:11 +00:00
parent 31d313cdd4
commit 64417a208a
10 changed files with 295 additions and 115 deletions

View File

@@ -49,6 +49,7 @@ namespace OpenMetaverse.TestClient
public bool Running = true;
public bool GetTextures = false;
public volatile int PendingLogins = 0;
public string onlyAvatar = String.Empty;
ClientManager()
{
@@ -247,6 +248,28 @@ namespace OpenMetaverse.TestClient
// Allow for comments when cmdline begins with ';' or '#'
if (firstToken[0] == ';' || firstToken[0] == '#')
return;
if ('@' == firstToken[0]) {
onlyAvatar = String.Empty;
if (tokens.Length == 3) {
bool found = false;
onlyAvatar = tokens[1]+" "+tokens[2];
foreach (TestClient client in Clients.Values) {
if (client.ToString() == onlyAvatar) {
found = true;
break;
}
}
if (found) {
Logger.Log("Commanding only "+onlyAvatar+" now", Helpers.LogLevel.Info);
} else {
Logger.Log("Commanding nobody now. Avatar "+onlyAvatar+" is offline", Helpers.LogLevel.Info);
}
} else {
Logger.Log("Commanding all avatars now", Helpers.LogLevel.Info);
}
return;
}
string[] args = new string[tokens.Length - 1];
if (args.Length > 0)
@@ -308,11 +331,13 @@ namespace OpenMetaverse.TestClient
delegate(object state)
{
TestClient testClient = (TestClient)state;
if (testClient.Commands.ContainsKey(firstToken))
Logger.Log(testClient.Commands[firstToken].Execute(args, fromAgentID),
Helpers.LogLevel.Info, testClient);
else
Logger.Log("Unknown command " + firstToken, Helpers.LogLevel.Warning);
if ((String.Empty == onlyAvatar) || (testClient.ToString() == onlyAvatar)) {
if (testClient.Commands.ContainsKey(firstToken))
Logger.Log(testClient.Commands[firstToken].Execute(args, fromAgentID),
Helpers.LogLevel.Info, testClient);
else
Logger.Log("Unknown command " + firstToken, Helpers.LogLevel.Warning);
}
++completed;
},

View File

@@ -43,10 +43,11 @@ namespace OpenMetaverse.TestClient
{
// iterate over the InternalDictionary using a delegate to populate
// our StringBuilder output string
sb.AppendFormat("has {0} friends:", Client.Friends.FriendList.Count).AppendLine();
Client.Friends.FriendList.ForEach(delegate(FriendInfo friend)
{
// append the name of the friend to our output
sb.AppendLine(friend.Name);
sb.AppendFormat("{0}, {1}", friend.UUID, friend.Name).AppendLine();
});
}
else

View File

@@ -12,8 +12,7 @@ namespace OpenMetaverse.TestClient
/// </summary>
public class ActivateGroupCommand : Command
{
ManualResetEvent GroupsEvent = new ManualResetEvent(false);
Dictionary<UUID, Group> groups = new Dictionary<UUID, Group>();
private ManualResetEvent GroupsEvent = new ManualResetEvent(false);
string activeGroup;
public ActivateGroupCommand(TestClient testClient)
@@ -27,7 +26,6 @@ namespace OpenMetaverse.TestClient
if (args.Length < 1)
return Description;
groups.Clear();
activeGroup = string.Empty;
string groupName = String.Empty;
@@ -35,49 +33,28 @@ namespace OpenMetaverse.TestClient
groupName += args[i] + " ";
groupName = groupName.Trim();
GroupManager.CurrentGroupsCallback callback = new GroupManager.CurrentGroupsCallback(Groups_OnCurrentGroups);
Client.Groups.OnCurrentGroups += callback;
Client.Groups.RequestCurrentGroups();
UUID groupUUID = Client.GroupName2UUID(groupName);
if (UUID.Zero != groupUUID) {
NetworkManager.PacketCallback pcallback = new NetworkManager.PacketCallback(AgentDataUpdateHandler);
Client.Network.RegisterCallback(PacketType.AgentDataUpdate, pcallback);
GroupsEvent.WaitOne(30000, false);
Console.WriteLine("setting " + groupName + " as active group");
Client.Groups.ActivateGroup(groupUUID);
GroupsEvent.WaitOne(30000, false);
Client.Groups.OnCurrentGroups -= callback;
GroupsEvent.Reset();
Client.Network.UnregisterCallback(PacketType.AgentDataUpdate, pcallback);
GroupsEvent.Reset();
if (groups.Count > 0)
{
foreach (Group currentGroup in groups.Values)
if (currentGroup.Name.ToLower() == groupName.ToLower())
{
NetworkManager.PacketCallback pcallback = new NetworkManager.PacketCallback(AgentDataUpdateHandler);
Client.Network.RegisterCallback(PacketType.AgentDataUpdate, pcallback);
/* A.Biondi
* TODO: Handle titles choosing.
*/
Console.WriteLine("setting " + currentGroup.Name + " as active group");
Client.Groups.ActivateGroup(currentGroup.ID);
GroupsEvent.WaitOne(30000, false);
if (String.IsNullOrEmpty(activeGroup))
return Client.ToString() + " failed to activate the group " + groupName;
Client.Network.UnregisterCallback(PacketType.AgentDataUpdate, pcallback);
GroupsEvent.Reset();
/* A.Biondi
* TODO: Handle titles choosing.
*/
if (String.IsNullOrEmpty(activeGroup))
return Client.ToString() + " failed to activate the group " + groupName;
return "Active group is now " + activeGroup;
}
return Client.ToString() + " doesn't seem to be member of the group " + groupName;
return "Active group is now " + activeGroup;
}
return Client.ToString() + " doesn't seem member of any group";
}
void Groups_OnCurrentGroups(Dictionary<UUID, Group> cGroups)
{
groups = cGroups;
GroupsEvent.Set();
return Client.ToString() + " doesn't seem to be member of the group " + groupName;
}
private void AgentDataUpdateHandler(Packet packet, Simulator sim)

View File

@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Packets;
using System.Text;
namespace OpenMetaverse.TestClient
{
/// <summary>
/// dumps group members to console
/// </summary>
public class GroupMembersCommand : Command
{
private ManualResetEvent GroupsEvent = new ManualResetEvent(false);
private string GroupName;
private UUID GroupUUID;
private UUID GroupRequestID;
public GroupMembersCommand(TestClient testClient)
{
Name = "groupmembers";
Description = "Dump group members to console. Usage: groupmembers GroupName";
Category = CommandCategory.Groups;
}
public override string Execute(string[] args, UUID fromAgentID)
{
if (args.Length < 1)
return Description;
GroupName = String.Empty;
for (int i = 0; i < args.Length; i++)
GroupName += args[i] + " ";
GroupName = GroupName.Trim();
GroupUUID = Client.GroupName2UUID(GroupName);
if (UUID.Zero != GroupUUID) {
GroupManager.GroupMembersCallback callback =
new GroupManager.GroupMembersCallback(GroupMembersHandler);
Client.Groups.OnGroupMembers += callback;
GroupRequestID = Client.Groups.RequestGroupMembers(GroupUUID);
GroupsEvent.WaitOne(30000, false);
GroupsEvent.Reset();
Client.Groups.OnGroupMembers -= callback;
return Client.ToString() + " got group members";
}
return Client.ToString() + " doesn't seem to be member of the group " + GroupName;
}
private void GroupMembersHandler(UUID requestID, UUID groupID, Dictionary<UUID, GroupMember> members)
{
if (requestID == GroupRequestID) {
StringBuilder sb = new StringBuilder();
sb.AppendLine();
sb.AppendFormat("GroupMembers: RequestID {0}", requestID).AppendLine();
sb.AppendFormat("GroupMembers: GroupUUID {0}", GroupUUID).AppendLine();
sb.AppendFormat("GroupMembers: GroupName {0}", GroupName).AppendLine();
if (members.Count > 0)
foreach (KeyValuePair<UUID, GroupMember> member in members)
sb.AppendFormat("GroupMembers: MemberUUID {0}", member.Key.ToString()).AppendLine();
sb.AppendFormat("GroupMembers: MemberCount {0}", members.Count).AppendLine();
Console.WriteLine(sb.ToString());
GroupsEvent.Set();
}
}
}
}

View File

@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Packets;
using System.Text;
namespace OpenMetaverse.TestClient
{
/// <summary>
/// dumps group roles to console
/// </summary>
public class GroupRolesCommand : Command
{
private ManualResetEvent GroupsEvent = new ManualResetEvent(false);
private string GroupName;
private UUID GroupUUID;
private UUID GroupRequestID;
public GroupRolesCommand(TestClient testClient)
{
Name = "grouproles";
Description = "Dump group roles to console. Usage: grouproles GroupName";
Category = CommandCategory.Groups;
}
public override string Execute(string[] args, UUID fromAgentID)
{
if (args.Length < 1)
return Description;
GroupName = String.Empty;
for (int i = 0; i < args.Length; i++)
GroupName += args[i] + " ";
GroupName = GroupName.Trim();
GroupUUID = Client.GroupName2UUID(GroupName);
if (UUID.Zero != GroupUUID) {
GroupManager.GroupRolesCallback callback =
new GroupManager.GroupRolesCallback(GroupRolesHandler);
Client.Groups.OnGroupRoles += callback;
GroupRequestID = Client.Groups.RequestGroupRoles(GroupUUID);
GroupsEvent.WaitOne(30000, false);
GroupsEvent.Reset();
Client.Groups.OnGroupRoles -= callback;
return Client.ToString() + " got group roles";
}
return Client.ToString() + " doesn't seem to have any roles in the group " + GroupName;
}
private void GroupRolesHandler(UUID requestID, UUID groupID, Dictionary<UUID, GroupRole> roles)
{
if (requestID == GroupRequestID) {
StringBuilder sb = new StringBuilder();
sb.AppendLine();
sb.AppendFormat("GroupRole: RequestID {0}", requestID).AppendLine();
sb.AppendFormat("GroupRole: GroupUUID {0}", GroupUUID).AppendLine();
sb.AppendFormat("GroupRole: GroupName {0}", GroupName).AppendLine();
if (roles.Count > 0)
foreach (KeyValuePair<UUID, GroupRole> role in roles)
sb.AppendFormat("GroupRole: Role {0} {1}|{2}", role.Value.ID, role.Value.Name, role.Value.Title).AppendLine();
sb.AppendFormat("GroupRole: RoleCount {0}", roles.Count).AppendLine();
Console.WriteLine(sb.ToString());
GroupsEvent.Set();
}
}
}
}

View File

@@ -9,45 +9,30 @@ namespace OpenMetaverse.TestClient
{
public class GroupsCommand : Command
{
ManualResetEvent GetCurrentGroupsEvent = new ManualResetEvent(false);
Dictionary<UUID, Group> groups = new Dictionary<UUID, Group>();
public GroupsCommand(TestClient testClient)
{
testClient.Groups.OnCurrentGroups += new GroupManager.CurrentGroupsCallback(Groups_OnCurrentGroups);
Name = "groups";
Description = "List avatar groups. Usage: groups";
Category = CommandCategory.Groups;
}
public override string Execute(string[] args, UUID fromAgentID)
{
if (groups.Count == 0)
{
Client.Groups.RequestCurrentGroups();
GetCurrentGroupsEvent.WaitOne(10000, false);
}
if (groups.Count > 0)
{
return getGroupsString();
}
else
{
return "No groups";
}
Client.ReloadGroupsCache();
return getGroupsString();
}
void Groups_OnCurrentGroups(Dictionary<UUID, Group> pGroups)
{
groups = pGroups;
GetCurrentGroupsEvent.Set();
}
string getGroupsString()
{
if (null == Client.GroupsCache)
return "Groups cache failed.";
if (0 == Client.GroupsCache.Count)
return "No groups";
StringBuilder sb = new StringBuilder();
foreach (Group group in groups.Values)
sb.AppendLine("got "+Client.GroupsCache.Count +" groups:");
foreach (Group group in Client.GroupsCache.Values)
{
sb.AppendLine(group.Name + " " + group.ID);
sb.AppendLine(group.ID + ", " + group.Name);
}

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Packets;
using System.Text;
namespace OpenMetaverse.TestClient
{
public class InviteGroupCommand : Command
{
public InviteGroupCommand(TestClient testClient)
{
Name = "invitegroup";
Description = "invite an avatar into a group. Usage: invitegroup AvatarUUID GroupUUID RoleUUID*";
Category = CommandCategory.Groups;
}
public override string Execute(string[] args, UUID fromAgentID)
{
if (args.Length < 2)
return Description;
UUID avatar = UUID.Zero;
UUID group = UUID.Zero;
UUID role = UUID.Zero;
List<UUID> roles = new List<UUID>();
if (!UUID.TryParse(args[0], out avatar))
return "parse error avatar UUID";
if (!UUID.TryParse(args[1], out group))
return "parse error group UUID";
for (int i = 2; i < args.Length; i++)
if (UUID.TryParse(args[i], out role))
roles.Add(role);
Client.Groups.Invite(group, roles, avatar);
return "invited "+avatar+" to "+group;
}
}
}

View File

@@ -75,6 +75,7 @@ namespace OpenMetaverse.TestClient
Client.Groups.OnGroupJoined -= gcallback;
GetGroupsSearchEvent.Reset();
Client.ReloadGroupsCache();
if (joinedGroup)
return "Joined the group " + resolvedGroupName;

View File

@@ -10,7 +10,6 @@ namespace OpenMetaverse.TestClient
public class LeaveGroupCommand : Command
{
ManualResetEvent GroupsEvent = new ManualResetEvent(false);
Dictionary<UUID, Group> groups = new Dictionary<UUID, Group>();
private bool leftGroup;
public LeaveGroupCommand(TestClient testClient)
@@ -24,60 +23,30 @@ namespace OpenMetaverse.TestClient
if (args.Length < 1)
return Description;
groups.Clear();
string groupName = String.Empty;
for (int i = 0; i < args.Length; i++)
groupName += args[i] + " ";
groupName = groupName.Trim();
GroupManager.CurrentGroupsCallback callback = new GroupManager.CurrentGroupsCallback(Groups_OnCurrentGroups);
Client.Groups.OnCurrentGroups += callback;
Client.Groups.RequestCurrentGroups();
UUID groupUUID = Client.GroupName2UUID(groupName);
if (UUID.Zero != groupUUID) {
GroupManager.GroupLeftCallback lcallback = new GroupManager.GroupLeftCallback(Groups_OnGroupLeft);
Client.Groups.OnGroupLeft += lcallback;
Client.Groups.LeaveGroup(groupUUID);
GroupsEvent.WaitOne(30000, false);
GroupsEvent.WaitOne(30000, false);
Client.Groups.OnCurrentGroups -= callback;
GroupsEvent.Reset();
Client.Groups.OnGroupLeft -= lcallback;
GroupsEvent.Reset();
Client.ReloadGroupsCache();
if (groups.Count > 0)
{
foreach (Group currentGroup in groups.Values)
if (currentGroup.Name.ToLower() == groupName.ToLower())
{
GroupManager.GroupLeftCallback lcallback = new GroupManager.GroupLeftCallback(Groups_OnGroupLeft);
Client.Groups.OnGroupLeft += lcallback;
Client.Groups.LeaveGroup(currentGroup.ID);
/* A.Biondi
* TODO: modify GroupsCommand.cs
* GroupsCommand.cs doesn't refresh the groups list until a new
* CurrentGroupsCallback occurs, so if you'd issue the command
* 'Groups' right after have left a group, it'll display still yet
* the group you just left (unless you have 0 groups, because it
* would force the refresh with Client.Groups.RequestCurrentGroups).
*/
GroupsEvent.WaitOne(30000, false);
Client.Groups.OnGroupLeft -= lcallback;
GroupsEvent.Reset();
if (leftGroup)
return Client.ToString() + " has left the group " + groupName;
return "failed to left the group " + groupName;
}
return Client.ToString() + " doesn't seem to be member of the group " + groupName;
if (leftGroup)
return Client.ToString() + " has left the group " + groupName;
return "failed to leave the group " + groupName;
}
return Client.ToString() + " doesn't seem member of any group";
return Client.ToString() + " doesn't seem to be member of the group " + groupName;
}
void Groups_OnCurrentGroups(Dictionary<UUID, Group> cGroups)
{
groups = cGroups;
GroupsEvent.Set();
}
void Groups_OnGroupLeft(UUID groupID, bool success)
{

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Reflection;
using System.Xml;
using OpenMetaverse;
@@ -26,6 +27,8 @@ namespace OpenMetaverse.TestClient
private System.Timers.Timer updateTimer;
private UUID GroupMembersRequestID;
public Dictionary<UUID, Group> GroupsCache = null;
private ManualResetEvent GroupsEvent = new ManualResetEvent(false);
/// <summary>
///
@@ -104,6 +107,47 @@ namespace OpenMetaverse.TestClient
}
}
public void ReloadGroupsCache()
{
GroupManager.CurrentGroupsCallback callback =
new GroupManager.CurrentGroupsCallback(Groups_OnCurrentGroups);
Groups.OnCurrentGroups += callback;
Groups.RequestCurrentGroups();
GroupsEvent.WaitOne(10000, false);
Groups.OnCurrentGroups -= callback;
GroupsEvent.Reset();
}
public UUID GroupName2UUID(String groupName)
{
UUID tryUUID;
if (UUID.TryParse(groupName,out tryUUID))
return tryUUID;
if (null == GroupsCache) {
ReloadGroupsCache();
if (null == GroupsCache)
return UUID.Zero;
}
lock(GroupsCache) {
if (GroupsCache.Count > 0) {
foreach (Group currentGroup in GroupsCache.Values)
if (currentGroup.Name.ToLower() == groupName.ToLower())
return currentGroup.ID;
}
}
return UUID.Zero;
}
private void Groups_OnCurrentGroups(Dictionary<UUID, Group> pGroups)
{
if (null == GroupsCache)
GroupsCache = pGroups;
else
lock(GroupsCache) { GroupsCache = pGroups; }
GroupsEvent.Set();
}
private void updateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
foreach (Command c in Commands.Values)