diff --git a/Programs/examples/TestClient/ClientManager.cs b/Programs/examples/TestClient/ClientManager.cs index 36a076bd..0a0aa6bf 100644 --- a/Programs/examples/TestClient/ClientManager.cs +++ b/Programs/examples/TestClient/ClientManager.cs @@ -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; }, diff --git a/Programs/examples/TestClient/Commands/Friends/FriendsCommand.cs b/Programs/examples/TestClient/Commands/Friends/FriendsCommand.cs index 9b2b857c..abc71319 100644 --- a/Programs/examples/TestClient/Commands/Friends/FriendsCommand.cs +++ b/Programs/examples/TestClient/Commands/Friends/FriendsCommand.cs @@ -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 diff --git a/Programs/examples/TestClient/Commands/Groups/ActivateGroupCommand.cs b/Programs/examples/TestClient/Commands/Groups/ActivateGroupCommand.cs index 78dd3bf9..8431689f 100644 --- a/Programs/examples/TestClient/Commands/Groups/ActivateGroupCommand.cs +++ b/Programs/examples/TestClient/Commands/Groups/ActivateGroupCommand.cs @@ -12,8 +12,7 @@ namespace OpenMetaverse.TestClient /// public class ActivateGroupCommand : Command { - ManualResetEvent GroupsEvent = new ManualResetEvent(false); - Dictionary groups = new Dictionary(); + 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 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) diff --git a/Programs/examples/TestClient/Commands/Groups/GroupMembersCommand.cs b/Programs/examples/TestClient/Commands/Groups/GroupMembersCommand.cs new file mode 100644 index 00000000..a0fa3605 --- /dev/null +++ b/Programs/examples/TestClient/Commands/Groups/GroupMembersCommand.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using OpenMetaverse; +using OpenMetaverse.Packets; +using System.Text; + +namespace OpenMetaverse.TestClient +{ + /// + /// dumps group members to console + /// + 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 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 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(); + } + } + } +} diff --git a/Programs/examples/TestClient/Commands/Groups/GroupRolesCommand.cs b/Programs/examples/TestClient/Commands/Groups/GroupRolesCommand.cs new file mode 100644 index 00000000..79d1e48a --- /dev/null +++ b/Programs/examples/TestClient/Commands/Groups/GroupRolesCommand.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using OpenMetaverse; +using OpenMetaverse.Packets; +using System.Text; + +namespace OpenMetaverse.TestClient +{ + /// + /// dumps group roles to console + /// + 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 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 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(); + } + } + } +} diff --git a/Programs/examples/TestClient/Commands/Groups/GroupsCommand.cs b/Programs/examples/TestClient/Commands/Groups/GroupsCommand.cs index 5b88586d..78ff5757 100644 --- a/Programs/examples/TestClient/Commands/Groups/GroupsCommand.cs +++ b/Programs/examples/TestClient/Commands/Groups/GroupsCommand.cs @@ -9,45 +9,30 @@ namespace OpenMetaverse.TestClient { public class GroupsCommand : Command { - ManualResetEvent GetCurrentGroupsEvent = new ManualResetEvent(false); - Dictionary groups = new Dictionary(); - 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 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); } diff --git a/Programs/examples/TestClient/Commands/Groups/InviteGroupCommand.cs b/Programs/examples/TestClient/Commands/Groups/InviteGroupCommand.cs new file mode 100644 index 00000000..302f30bd --- /dev/null +++ b/Programs/examples/TestClient/Commands/Groups/InviteGroupCommand.cs @@ -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 roles = new List(); + + 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; + } + } +} diff --git a/Programs/examples/TestClient/Commands/Groups/JoinGroupCommand.cs b/Programs/examples/TestClient/Commands/Groups/JoinGroupCommand.cs index e1f1b6c7..8eb0714e 100644 --- a/Programs/examples/TestClient/Commands/Groups/JoinGroupCommand.cs +++ b/Programs/examples/TestClient/Commands/Groups/JoinGroupCommand.cs @@ -75,6 +75,7 @@ namespace OpenMetaverse.TestClient Client.Groups.OnGroupJoined -= gcallback; GetGroupsSearchEvent.Reset(); + Client.ReloadGroupsCache(); if (joinedGroup) return "Joined the group " + resolvedGroupName; diff --git a/Programs/examples/TestClient/Commands/Groups/LeaveGroupCommand.cs b/Programs/examples/TestClient/Commands/Groups/LeaveGroupCommand.cs index 0dab1d38..a18006cb 100644 --- a/Programs/examples/TestClient/Commands/Groups/LeaveGroupCommand.cs +++ b/Programs/examples/TestClient/Commands/Groups/LeaveGroupCommand.cs @@ -10,7 +10,6 @@ namespace OpenMetaverse.TestClient public class LeaveGroupCommand : Command { ManualResetEvent GroupsEvent = new ManualResetEvent(false); - Dictionary groups = new Dictionary(); 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 cGroups) - { - groups = cGroups; - GroupsEvent.Set(); - } void Groups_OnGroupLeft(UUID groupID, bool success) { diff --git a/Programs/examples/TestClient/TestClient.cs b/Programs/examples/TestClient/TestClient.cs index 08d57c3a..c989f550 100644 --- a/Programs/examples/TestClient/TestClient.cs +++ b/Programs/examples/TestClient/TestClient.cs @@ -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 GroupsCache = null; + private ManualResetEvent GroupsEvent = new ManualResetEvent(false); /// /// @@ -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 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)