2007-04-28 20:54:02 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using libsecondlife;
|
|
|
|
|
using libsecondlife.Packets;
|
|
|
|
|
|
|
|
|
|
namespace libsecondlife.TestClient
|
|
|
|
|
{
|
|
|
|
|
public class SetMasterCommand: Command
|
|
|
|
|
{
|
|
|
|
|
public DateTime Created = DateTime.Now;
|
|
|
|
|
private LLUUID resolvedMasterKey = LLUUID.Zero;
|
|
|
|
|
private ManualResetEvent keyResolution = new ManualResetEvent(false);
|
|
|
|
|
private LLUUID query = LLUUID.Zero;
|
|
|
|
|
|
|
|
|
|
public SetMasterCommand(TestClient testClient)
|
|
|
|
|
{
|
2007-08-20 09:26:21 +00:00
|
|
|
Name = "setmaster";
|
|
|
|
|
Description = "Sets the user name of the master user. The master user can IM to run commands. Usage: setmaster name";
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Execute(string[] args, LLUUID fromAgentID)
|
|
|
|
|
{
|
|
|
|
|
string masterName = String.Empty;
|
|
|
|
|
for (int ct = 0; ct < args.Length;ct++)
|
|
|
|
|
masterName = masterName + args[ct] + " ";
|
|
|
|
|
masterName = masterName.TrimEnd();
|
|
|
|
|
|
|
|
|
|
if (masterName.Length == 0)
|
2007-08-20 09:26:21 +00:00
|
|
|
return "Usage: setmaster name";
|
2007-04-28 20:54:02 +00:00
|
|
|
|
|
|
|
|
DirectoryManager.DirPeopleReplyCallback callback = new DirectoryManager.DirPeopleReplyCallback(KeyResolvHandler);
|
|
|
|
|
Client.Directory.OnDirPeopleReply += callback;
|
2007-08-20 09:26:21 +00:00
|
|
|
|
2007-05-14 10:18:54 +00:00
|
|
|
query = Client.Directory.StartPeopleSearch(DirectoryManager.DirFindFlags.People, masterName, 0);
|
2007-08-20 09:26:21 +00:00
|
|
|
|
2007-04-28 20:54:02 +00:00
|
|
|
if (keyResolution.WaitOne(TimeSpan.FromMinutes(1), false))
|
|
|
|
|
{
|
|
|
|
|
Client.MasterKey = resolvedMasterKey;
|
|
|
|
|
keyResolution.Reset();
|
|
|
|
|
Client.Directory.OnDirPeopleReply -= callback;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
keyResolution.Reset();
|
|
|
|
|
Client.Directory.OnDirPeopleReply -= callback;
|
|
|
|
|
return "Unable to obtain UUID for \"" + masterName + "\". Master unchanged.";
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-20 09:26:21 +00:00
|
|
|
// If we see this avatar standing around, IM them. Otherwise don't bother
|
|
|
|
|
// because they may be offline
|
|
|
|
|
lock (Client.Network.Simulators)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < Client.Network.Simulators.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
lock (Client.Network.Simulators[i].Objects.Avatars)
|
|
|
|
|
{
|
|
|
|
|
foreach (Avatar avatar in Client.Network.Simulators[i].Objects.Avatars.Values)
|
|
|
|
|
{
|
|
|
|
|
if (avatar.ID == Client.MasterKey)
|
|
|
|
|
{
|
|
|
|
|
Client.Self.InstantMessage(avatar.ID,
|
|
|
|
|
"You are now my master. IM me with \"help\" for a command list.");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-04-28 20:54:02 +00:00
|
|
|
|
2007-08-20 09:26:21 +00:00
|
|
|
return String.Format("Master set to {0} ({1})", masterName, Client.MasterKey.ToStringHyphenated());
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void KeyResolvHandler(LLUUID queryid, List<DirectoryManager.AgentSearchData> matches)
|
|
|
|
|
{
|
|
|
|
|
if (query != queryid)
|
|
|
|
|
return;
|
|
|
|
|
// We can't handle ambiguities here as nicely as we can in ClientManager.
|
|
|
|
|
resolvedMasterKey = matches[0].AgentID;
|
|
|
|
|
keyResolution.Set();
|
|
|
|
|
query = LLUUID.Zero;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|