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
|
|
|
{
|
2008-05-01 20:58:20 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Changes Avatars currently active group
|
|
|
|
|
/// </summary>
|
2008-01-05 23:30:50 +00:00
|
|
|
public class ActivateGroupCommand : Command
|
|
|
|
|
{
|
2009-07-15 23:23:11 +00:00
|
|
|
private ManualResetEvent GroupsEvent = new ManualResetEvent(false);
|
2008-01-05 23:30:50 +00:00
|
|
|
string activeGroup;
|
|
|
|
|
|
|
|
|
|
public ActivateGroupCommand(TestClient testClient)
|
|
|
|
|
{
|
|
|
|
|
Name = "activategroup";
|
|
|
|
|
Description = "Set a group as active. Usage: activategroup 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;
|
|
|
|
|
|
|
|
|
|
activeGroup = string.Empty;
|
|
|
|
|
|
|
|
|
|
string groupName = String.Empty;
|
|
|
|
|
for (int i = 0; i < args.Length; i++)
|
|
|
|
|
groupName += args[i] + " ";
|
|
|
|
|
groupName = groupName.Trim();
|
|
|
|
|
|
2009-07-15 23:23:11 +00:00
|
|
|
UUID groupUUID = Client.GroupName2UUID(groupName);
|
|
|
|
|
if (UUID.Zero != groupUUID) {
|
|
|
|
|
NetworkManager.PacketCallback pcallback = new NetworkManager.PacketCallback(AgentDataUpdateHandler);
|
|
|
|
|
Client.Network.RegisterCallback(PacketType.AgentDataUpdate, pcallback);
|
2008-01-05 23:30:50 +00:00
|
|
|
|
2009-07-15 23:23:11 +00:00
|
|
|
Console.WriteLine("setting " + groupName + " as active group");
|
|
|
|
|
Client.Groups.ActivateGroup(groupUUID);
|
|
|
|
|
GroupsEvent.WaitOne(30000, false);
|
2008-01-05 23:30:50 +00:00
|
|
|
|
2009-07-15 23:23:11 +00:00
|
|
|
Client.Network.UnregisterCallback(PacketType.AgentDataUpdate, pcallback);
|
|
|
|
|
GroupsEvent.Reset();
|
2008-01-05 23:30:50 +00:00
|
|
|
|
2009-07-15 23:23:11 +00:00
|
|
|
/* A.Biondi
|
|
|
|
|
* TODO: Handle titles choosing.
|
|
|
|
|
*/
|
2008-01-05 23:30:50 +00:00
|
|
|
|
2009-07-15 23:23:11 +00:00
|
|
|
if (String.IsNullOrEmpty(activeGroup))
|
|
|
|
|
return Client.ToString() + " failed to activate the group " + groupName;
|
2008-01-05 23:30:50 +00:00
|
|
|
|
2009-07-15 23:23:11 +00:00
|
|
|
return "Active group is now " + activeGroup;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AgentDataUpdateHandler(Packet packet, Simulator sim)
|
|
|
|
|
{
|
|
|
|
|
AgentDataUpdatePacket p = (AgentDataUpdatePacket)packet;
|
|
|
|
|
if (p.AgentData.AgentID == Client.Self.AgentID)
|
|
|
|
|
{
|
2008-08-12 22:38:02 +00:00
|
|
|
activeGroup = Utils.BytesToString(p.AgentData.GroupName) + " ( " + Utils.BytesToString(p.AgentData.GroupTitle) + " )";
|
2008-01-05 23:30:50 +00:00
|
|
|
GroupsEvent.Set();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|