Files
libremetaverse/Programs/examples/TestClient/Commands/Groups/LeaveGroupCommand.cs
Jim Radford b0cb77e1e5 LIBOMV-686 Implements new event patterns based on the Microsoft Framework Design Guidelines in GroupManager
* BREAKING CHANGE * this is a major shift in the way events are internally handled.

git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@3162 52acb1d6-8a22-11de-b505-999d5b087335
2009-10-20 20:18:03 +00:00

59 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Packets;
using System.Text;
namespace OpenMetaverse.TestClient
{
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";
Category = CommandCategory.Groups;
}
public override string Execute(string[] args, UUID fromAgentID)
{
if (args.Length < 1)
return Description;
string groupName = String.Empty;
for (int i = 0; i < args.Length; i++)
groupName += args[i] + " ";
groupName = groupName.Trim();
UUID groupUUID = Client.GroupName2UUID(groupName);
if (UUID.Zero != groupUUID) {
Client.Groups.GroupLeaveReply += Groups_GroupLeft;
Client.Groups.LeaveGroup(groupUUID);
GroupsEvent.WaitOne(30000, false);
Client.Groups.GroupLeaveReply -= Groups_GroupLeft;
GroupsEvent.Reset();
Client.ReloadGroupsCache();
if (leftGroup)
return Client.ToString() + " has left the group " + groupName;
return "failed to leave the group " + groupName;
}
return Client.ToString() + " doesn't seem to be member of the group " + groupName;
}
void Groups_GroupLeft(object sender, GroupOperationEventArgs e)
{
Console.WriteLine(Client.ToString() + (e.Success ? " has left group " : " failed to left group ") + e.GroupID.ToString());
leftGroup = e.Success;
GroupsEvent.Set();
}
}
}