2007-11-30 23:19:05 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-07-25 11:10:52 -05:00
|
|
|
using System.Linq;
|
2022-11-17 12:10:18 -06:00
|
|
|
using LibreMetaverse;
|
2008-07-21 21:12:59 +00:00
|
|
|
using OpenMetaverse.Packets;
|
2007-11-30 23:19:05 +00:00
|
|
|
|
2008-07-21 21:12:59 +00:00
|
|
|
namespace OpenMetaverse.TestClient
|
2007-11-30 23:19:05 +00:00
|
|
|
{
|
|
|
|
|
public class CloneCommand : Command
|
|
|
|
|
{
|
2022-11-17 12:10:18 -06:00
|
|
|
uint _serialNum = 2;
|
|
|
|
|
readonly CacheDictionary<UUID, AvatarAppearancePacket> Appearances = new(100, new LruRemovalStrategy<UUID>());
|
2007-11-30 23:19:05 +00:00
|
|
|
|
|
|
|
|
public CloneCommand(TestClient testClient)
|
|
|
|
|
{
|
|
|
|
|
Name = "clone";
|
|
|
|
|
Description = "Clone the appearance of a nearby avatar. Usage: clone [name]";
|
2008-07-25 08:55:36 +00:00
|
|
|
Category = CommandCategory.Appearance;
|
2022-11-17 12:10:18 -06:00
|
|
|
|
|
|
|
|
testClient.Network.RegisterCallback(PacketType.AvatarAppearance, AvatarAppearanceHandler);
|
2007-11-30 23:19:05 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
public override string Execute(string[] args, UUID fromAgentID)
|
2007-11-30 23:19:05 +00:00
|
|
|
{
|
2022-02-25 19:38:11 -06:00
|
|
|
string targetName = string.Empty;
|
2007-11-30 23:19:05 +00:00
|
|
|
List<DirectoryManager.AgentSearchData> matches;
|
|
|
|
|
|
2021-07-25 11:10:52 -05:00
|
|
|
targetName = args.Aggregate(targetName, (current, t) => current + t + " ");
|
2007-11-30 23:19:05 +00:00
|
|
|
targetName = targetName.TrimEnd();
|
|
|
|
|
|
|
|
|
|
if (targetName.Length == 0)
|
|
|
|
|
return "Usage: clone [name]";
|
|
|
|
|
|
2019-06-08 16:49:47 -05:00
|
|
|
#pragma warning disable CS0618 // Type or member is obsolete
|
2007-11-30 23:19:05 +00:00
|
|
|
if (Client.Directory.PeopleSearch(DirectoryManager.DirFindFlags.People, targetName, 0, 1000 * 10,
|
|
|
|
|
out matches) && matches.Count > 0)
|
2019-06-08 16:49:47 -05:00
|
|
|
#pragma warning restore CS0618 // Type or member is obsolete
|
2007-11-30 23:19:05 +00:00
|
|
|
{
|
2008-07-25 05:15:05 +00:00
|
|
|
UUID target = matches[0].AgentID;
|
2022-02-25 19:38:11 -06:00
|
|
|
targetName += $" ({target})";
|
2007-11-30 23:19:05 +00:00
|
|
|
|
2022-11-17 12:10:18 -06:00
|
|
|
if (Appearances.ContainsKey(target))
|
2007-11-30 23:19:05 +00:00
|
|
|
{
|
|
|
|
|
#region AvatarAppearance to AgentSetAppearance
|
|
|
|
|
|
2022-11-17 12:10:18 -06:00
|
|
|
AvatarAppearancePacket appearance = Appearances[target];
|
2007-11-30 23:19:05 +00:00
|
|
|
|
2022-02-25 19:38:11 -06:00
|
|
|
AgentSetAppearancePacket set = new AgentSetAppearancePacket
|
|
|
|
|
{
|
|
|
|
|
AgentData =
|
|
|
|
|
{
|
|
|
|
|
AgentID = Client.Self.AgentID,
|
|
|
|
|
SessionID = Client.Self.SessionID,
|
2022-11-17 12:10:18 -06:00
|
|
|
SerialNum = _serialNum++,
|
2022-02-25 19:38:11 -06:00
|
|
|
Size = new Vector3(2f, 2f, 2f) // HACK
|
|
|
|
|
},
|
|
|
|
|
WearableData = Array.Empty<AgentSetAppearancePacket.WearableDataBlock>(),
|
|
|
|
|
VisualParam = new AgentSetAppearancePacket.VisualParamBlock[appearance.VisualParam.Length]
|
|
|
|
|
};
|
2007-11-30 23:19:05 +00:00
|
|
|
|
2022-11-17 12:10:18 -06:00
|
|
|
for (var i = 0; i < appearance.VisualParam.Length; ++i)
|
2007-11-30 23:19:05 +00:00
|
|
|
{
|
2022-02-25 19:38:11 -06:00
|
|
|
set.VisualParam[i] = new AgentSetAppearancePacket.VisualParamBlock
|
|
|
|
|
{
|
|
|
|
|
ParamValue = appearance.VisualParam[i].ParamValue
|
|
|
|
|
};
|
2007-11-30 23:19:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set.ObjectData.TextureEntry = appearance.ObjectData.TextureEntry;
|
|
|
|
|
|
|
|
|
|
#endregion AvatarAppearance to AgentSetAppearance
|
|
|
|
|
|
|
|
|
|
// Detach everything we are currently wearing
|
2009-07-31 19:12:11 +00:00
|
|
|
Client.Appearance.AddAttachments(new List<InventoryItem>(), true);
|
2007-11-30 23:19:05 +00:00
|
|
|
|
|
|
|
|
// Send the new appearance packet
|
|
|
|
|
Client.Network.SendPacket(set);
|
|
|
|
|
|
2022-11-17 12:10:18 -06:00
|
|
|
return $"Cloned {targetName}";
|
2007-11-30 23:19:05 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-11-17 12:10:18 -06:00
|
|
|
return $"Don't have an appearance cached for {targetName}";
|
2007-11-30 23:19:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-11-17 12:10:18 -06:00
|
|
|
return $"Could not find {targetName}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AvatarAppearanceHandler(object sender, PacketReceivedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AvatarAppearancePacket appearance = (AvatarAppearancePacket)e.Packet;
|
|
|
|
|
|
|
|
|
|
lock (Appearances)
|
|
|
|
|
{
|
|
|
|
|
Appearances[appearance.Sender.ID] = appearance;
|
2007-11-30 23:19:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|