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
|
|
|
using OpenMetaverse.Packets;
|
2008-01-05 23:30:50 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2022-02-25 19:38:11 -06: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);
|
|
|
|
|
if (UUID.Zero != groupUUID) {
|
2009-10-28 08:01:52 +00:00
|
|
|
EventHandler<PacketReceivedEventArgs> pcallback = AgentDataUpdateHandler;
|
2009-07-15 23:23:11 +00:00
|
|
|
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);
|
2025-01-13 07:44:05 -06:00
|
|
|
GroupsEvent.WaitOne(TimeSpan.FromSeconds(30), 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
|
|
|
|
2022-02-25 19:38:11 -06:00
|
|
|
if (string.IsNullOrEmpty(activeGroup))
|
|
|
|
|
return Client + " 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
|
|
|
}
|
2022-02-25 19:38:11 -06:00
|
|
|
return Client + " doesn't seem to be member of the group " + groupName;
|
2008-01-05 23:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
2009-10-28 08:01:52 +00:00
|
|
|
private void AgentDataUpdateHandler(object sender, PacketReceivedEventArgs e)
|
2008-01-05 23:30:50 +00:00
|
|
|
{
|
2009-10-28 08:01:52 +00:00
|
|
|
AgentDataUpdatePacket p = (AgentDataUpdatePacket)e.Packet;
|
2008-01-05 23:30:50 +00:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|