2007-04-28 20:54:02 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
2008-07-21 21:12:59 +00:00
|
|
|
using OpenMetaverse;
|
|
|
|
|
using OpenMetaverse.Packets;
|
2007-04-28 20:54:02 +00:00
|
|
|
|
2008-07-21 21:12:59 +00:00
|
|
|
namespace OpenMetaverse.TestClient
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
|
|
|
|
public class CloneProfileCommand : Command
|
|
|
|
|
{
|
|
|
|
|
Avatar.AvatarProperties Properties;
|
|
|
|
|
Avatar.Interests Interests;
|
2008-07-25 05:15:05 +00:00
|
|
|
List<UUID> Groups = new List<UUID>();
|
2007-04-28 20:54:02 +00:00
|
|
|
bool ReceivedProperties = false;
|
|
|
|
|
bool ReceivedInterests = false;
|
|
|
|
|
bool ReceivedGroups = false;
|
|
|
|
|
ManualResetEvent ReceivedProfileEvent = new ManualResetEvent(false);
|
|
|
|
|
|
|
|
|
|
public CloneProfileCommand(TestClient testClient)
|
|
|
|
|
{
|
|
|
|
|
testClient.Avatars.OnAvatarInterests += new AvatarManager.AvatarInterestsCallback(Avatars_OnAvatarInterests);
|
|
|
|
|
testClient.Avatars.OnAvatarProperties += new AvatarManager.AvatarPropertiesCallback(Avatars_OnAvatarProperties);
|
|
|
|
|
testClient.Avatars.OnAvatarGroups += new AvatarManager.AvatarGroupsCallback(Avatars_OnAvatarGroups);
|
2009-10-20 20:18:03 +00:00
|
|
|
testClient.Groups.GroupJoinedReply += new EventHandler<GroupOperationEventArgs>(Groups_OnGroupJoined);
|
|
|
|
|
|
2008-11-10 01:26:10 +00:00
|
|
|
testClient.Avatars.OnAvatarPicks += new AvatarManager.AvatarPicksCallback(Avatars_OnAvatarPicks);
|
|
|
|
|
testClient.Avatars.OnPickInfo += new AvatarManager.PickInfoCallback(Avatars_OnPickInfo);
|
2007-04-28 20:54:02 +00:00
|
|
|
|
|
|
|
|
Name = "cloneprofile";
|
|
|
|
|
Description = "Clones another avatars profile as closely as possible. WARNING: This command will " +
|
|
|
|
|
"destroy your existing profile! Usage: cloneprofile [targetuuid]";
|
2008-07-25 08:55:36 +00:00
|
|
|
Category = CommandCategory.Other;
|
2009-10-20 20:18:03 +00:00
|
|
|
}
|
2007-04-28 20:54:02 +00:00
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
public override string Execute(string[] args, UUID fromAgentID)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
|
|
|
|
if (args.Length != 1)
|
|
|
|
|
return Description;
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
UUID targetID;
|
2007-04-28 20:54:02 +00:00
|
|
|
ReceivedProperties = false;
|
|
|
|
|
ReceivedInterests = false;
|
|
|
|
|
ReceivedGroups = false;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2008-07-25 05:15:05 +00:00
|
|
|
targetID = new UUID(args[0]);
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
return Description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Request all of the packets that make up an avatar profile
|
|
|
|
|
Client.Avatars.RequestAvatarProperties(targetID);
|
|
|
|
|
|
2008-11-10 01:26:10 +00:00
|
|
|
//Request all of the avatars pics
|
|
|
|
|
Client.Avatars.RequestAvatarPicks(Client.Self.AgentID);
|
|
|
|
|
Client.Avatars.RequestAvatarPicks(targetID);
|
|
|
|
|
|
2007-04-28 20:54:02 +00:00
|
|
|
// Wait for all the packets to arrive
|
|
|
|
|
ReceivedProfileEvent.Reset();
|
|
|
|
|
ReceivedProfileEvent.WaitOne(5000, false);
|
|
|
|
|
|
|
|
|
|
// Check if everything showed up
|
|
|
|
|
if (!ReceivedInterests || !ReceivedProperties || !ReceivedGroups)
|
|
|
|
|
return "Failed to retrieve a complete profile for that UUID";
|
|
|
|
|
|
|
|
|
|
// Synchronize our profile
|
2007-11-06 09:26:10 +00:00
|
|
|
Client.Self.UpdateInterests(Interests);
|
|
|
|
|
Client.Self.UpdateProfile(Properties);
|
2007-04-28 20:54:02 +00:00
|
|
|
|
|
|
|
|
// TODO: Leave all the groups we're currently a member of? This could
|
|
|
|
|
// break TestClient connectivity that might be relying on group authentication
|
|
|
|
|
|
|
|
|
|
// Attempt to join all the groups
|
2008-07-25 05:15:05 +00:00
|
|
|
foreach (UUID groupID in Groups)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2007-11-06 09:26:10 +00:00
|
|
|
Client.Groups.RequestJoinGroup(groupID);
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
2007-11-30 13:15:31 +00:00
|
|
|
return "Synchronized our profile to the profile of " + targetID.ToString();
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
2008-11-10 01:26:10 +00:00
|
|
|
void Avatars_OnAvatarPicks(UUID avatarid, Dictionary<UUID, string> picks)
|
|
|
|
|
{
|
|
|
|
|
foreach (KeyValuePair<UUID, string> kvp in picks)
|
|
|
|
|
{
|
|
|
|
|
if (avatarid == Client.Self.AgentID)
|
|
|
|
|
{
|
|
|
|
|
Client.Self.PickDelete(kvp.Key);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Client.Avatars.RequestPickInfo(avatarid, kvp.Key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Avatars_OnPickInfo(UUID pickid, ProfilePick pick)
|
|
|
|
|
{
|
|
|
|
|
Client.Self.PickInfoUpdate(pickid, pick.TopPick, pick.ParcelID, pick.Name, pick.PosGlobal, pick.SnapshotID, pick.Desc);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
void Avatars_OnAvatarProperties(UUID avatarID, Avatar.AvatarProperties properties)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
|
|
|
|
lock (ReceivedProfileEvent)
|
|
|
|
|
{
|
|
|
|
|
Properties = properties;
|
|
|
|
|
ReceivedProperties = true;
|
|
|
|
|
|
|
|
|
|
if (ReceivedInterests && ReceivedProperties && ReceivedGroups)
|
|
|
|
|
ReceivedProfileEvent.Set();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
void Avatars_OnAvatarInterests(UUID avatarID, Avatar.Interests interests)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
|
|
|
|
lock (ReceivedProfileEvent)
|
|
|
|
|
{
|
|
|
|
|
Interests = interests;
|
|
|
|
|
ReceivedInterests = true;
|
|
|
|
|
|
|
|
|
|
if (ReceivedInterests && ReceivedProperties && ReceivedGroups)
|
|
|
|
|
ReceivedProfileEvent.Set();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
void Avatars_OnAvatarGroups(UUID avatarID, List<AvatarGroup> groups)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
|
|
|
|
lock (ReceivedProfileEvent)
|
|
|
|
|
{
|
2008-04-10 01:45:00 +00:00
|
|
|
foreach (AvatarGroup group in groups)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2008-04-10 01:45:00 +00:00
|
|
|
Groups.Add(group.GroupID);
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReceivedGroups = true;
|
|
|
|
|
|
|
|
|
|
if (ReceivedInterests && ReceivedProperties && ReceivedGroups)
|
|
|
|
|
ReceivedProfileEvent.Set();
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-11-10 01:26:10 +00:00
|
|
|
|
2009-10-20 20:18:03 +00:00
|
|
|
void Groups_OnGroupJoined(object sender, GroupOperationEventArgs e)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2009-10-20 20:18:03 +00:00
|
|
|
Console.WriteLine(Client.ToString() + (e.Success ? " joined " : " failed to join ") +
|
|
|
|
|
e.GroupID.ToString());
|
2007-04-28 20:54:02 +00:00
|
|
|
|
2009-10-20 20:18:03 +00:00
|
|
|
if (e.Success)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2009-10-20 20:18:03 +00:00
|
|
|
Console.WriteLine(Client.ToString() + " setting " + e.GroupID.ToString() +
|
2007-04-28 20:54:02 +00:00
|
|
|
" as the active group");
|
2009-10-20 20:18:03 +00:00
|
|
|
Client.Groups.ActivateGroup(e.GroupID);
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|