2008-01-05 23:30:50 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
2008-07-21 21:12:59 +00:00
|
|
|
using OpenMetaverse;
|
|
|
|
|
using OpenMetaverse.Packets;
|
2008-01-05 23:30:50 +00:00
|
|
|
using System.Text;
|
|
|
|
|
|
2008-07-21 21:12:59 +00:00
|
|
|
namespace OpenMetaverse.TestClient
|
2008-01-05 23:30:50 +00:00
|
|
|
{
|
|
|
|
|
public class LeaveGroupCommand : Command
|
|
|
|
|
{
|
|
|
|
|
ManualResetEvent GroupsEvent = new ManualResetEvent(false);
|
2008-07-25 05:15:05 +00:00
|
|
|
Dictionary<UUID, Group> groups = new Dictionary<UUID, Group>();
|
2008-01-05 23:30:50 +00:00
|
|
|
private bool leftGroup;
|
|
|
|
|
|
|
|
|
|
public LeaveGroupCommand(TestClient testClient)
|
|
|
|
|
{
|
|
|
|
|
Name = "leavegroup";
|
|
|
|
|
Description = "Leave a group. Usage: leavegroup GroupName";
|
2008-07-25 08:55:36 +00:00
|
|
|
Category = CommandCategory.Groups;
|
2008-01-05 23:30:50 +00:00
|
|
|
}
|
2008-07-25 05:15:05 +00:00
|
|
|
public override string Execute(string[] args, UUID fromAgentID)
|
2008-01-05 23:30:50 +00:00
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
GroupsEvent.WaitOne(30000, false);
|
|
|
|
|
|
|
|
|
|
Client.Groups.OnCurrentGroups -= callback;
|
|
|
|
|
GroupsEvent.Reset();
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Client.ToString() + " doesn't seem member of any group";
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
void Groups_OnCurrentGroups(Dictionary<UUID, Group> cGroups)
|
2008-01-05 23:30:50 +00:00
|
|
|
{
|
|
|
|
|
groups = cGroups;
|
|
|
|
|
GroupsEvent.Set();
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
void Groups_OnGroupLeft(UUID groupID, bool success)
|
2008-01-05 23:30:50 +00:00
|
|
|
{
|
|
|
|
|
Console.WriteLine(Client.ToString() + (success ? " has left group " : " failed to left group ") + groupID.ToString());
|
|
|
|
|
|
|
|
|
|
leftGroup = success;
|
|
|
|
|
GroupsEvent.Set();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|