2008-01-05 23:30:50 +00:00
|
|
|
using System;
|
2021-07-25 11:10:52 -05:00
|
|
|
using System.Linq;
|
2008-01-05 23:30:50 +00:00
|
|
|
using System.Threading;
|
|
|
|
|
|
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);
|
|
|
|
|
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;
|
|
|
|
|
|
2021-07-25 11:10:52 -05:00
|
|
|
string groupName = args.Aggregate(String.Empty, (current, t) => current + (t + " "));
|
2008-01-05 23:30:50 +00:00
|
|
|
groupName = groupName.Trim();
|
|
|
|
|
|
2009-07-15 23:23:11 +00:00
|
|
|
UUID groupUUID = Client.GroupName2UUID(groupName);
|
2009-10-20 20:18:03 +00:00
|
|
|
if (UUID.Zero != groupUUID) {
|
|
|
|
|
Client.Groups.GroupLeaveReply += Groups_GroupLeft;
|
2009-07-15 23:23:11 +00:00
|
|
|
Client.Groups.LeaveGroup(groupUUID);
|
2008-01-05 23:30:50 +00:00
|
|
|
|
2009-07-15 23:23:11 +00:00
|
|
|
GroupsEvent.WaitOne(30000, false);
|
2009-10-20 20:18:03 +00:00
|
|
|
Client.Groups.GroupLeaveReply -= Groups_GroupLeft;
|
2008-01-05 23:30:50 +00:00
|
|
|
|
2009-07-15 23:23:11 +00:00
|
|
|
GroupsEvent.Reset();
|
|
|
|
|
Client.ReloadGroupsCache();
|
2008-01-05 23:30:50 +00:00
|
|
|
|
2009-07-15 23:23:11 +00:00
|
|
|
if (leftGroup)
|
|
|
|
|
return Client.ToString() + " has left the group " + groupName;
|
|
|
|
|
return "failed to leave the group " + groupName;
|
2008-01-05 23:30:50 +00:00
|
|
|
}
|
2009-07-15 23:23:11 +00:00
|
|
|
return Client.ToString() + " doesn't seem to be member of the group " + groupName;
|
2008-01-05 23:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
2009-10-20 20:18:03 +00:00
|
|
|
void Groups_GroupLeft(object sender, GroupOperationEventArgs e)
|
2008-01-05 23:30:50 +00:00
|
|
|
{
|
2009-10-20 20:18:03 +00:00
|
|
|
Console.WriteLine(Client.ToString() + (e.Success ? " has left group " : " failed to left group ") + e.GroupID.ToString());
|
2008-01-05 23:30:50 +00:00
|
|
|
|
2009-10-20 20:18:03 +00:00
|
|
|
leftGroup = e.Success;
|
2008-01-05 23:30:50 +00:00
|
|
|
GroupsEvent.Set();
|
|
|
|
|
}
|
2009-10-20 20:18:03 +00:00
|
|
|
|
2008-01-05 23:30:50 +00:00
|
|
|
}
|
|
|
|
|
}
|