Files
libremetaverse/libsecondlife/examples/TestClient/Commands/System/SetMasterCommand.cs
John Hurliman 3013742668 * Increased SIMULATOR_TIMEOUT to 30 seconds
* Converted all timers to System.Threading timers to fix problems running in services and the CF
* UDPBase now uses our own ReaderWriterLock that is more efficient, and CF compatible
* Login uses a hand-created LoginProxy object instead of dynamically building the class with reflection .Emit()
* Replaced ParameterizedThreadStart calls with class-wide variables for CF compat.
* Removed transfer timeout code (irrelevant now that uploads go through CAPS)
* Added several new Helpers methods to wrap desktop and CF conditional code
* Replaced Monitor calls with AutoResetEvent in BlockingQueue
* InventoryNodeDictionary uses generics now
* Removed final lingering piece of XML serialization
* Added CookComputing.XmlRpc.CF.dll for the CF

git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@1479 52acb1d6-8a22-11de-b505-999d5b087335
2007-11-06 09:26:10 +00:00

71 lines
2.7 KiB
C#

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)
{
Name = "setmaster";
Description = "Sets the user name of the master user. The master user can IM to run commands. Usage: setmaster name";
}
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)
return "Usage: setmaster name";
DirectoryManager.DirPeopleReplyCallback callback = new DirectoryManager.DirPeopleReplyCallback(KeyResolvHandler);
Client.Directory.OnDirPeopleReply += callback;
query = Client.Directory.StartPeopleSearch(DirectoryManager.DirFindFlags.People, masterName, 0);
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.";
}
// Send an Online-only IM to the new master
Client.Self.InstantMessage(Client.Self.Name, Client.MasterKey,
"You are now my master. IM me with \"help\" for a command list.", LLUUID.Random(),
InstantMessageDialog.MessageFromAgent, InstantMessageOnline.Online, Client.Self.SimPosition,
Client.Network.CurrentSim.ID, new byte[0]);
return String.Format("Master set to {0} ({1})", masterName, Client.MasterKey.ToStringHyphenated());
}
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;
}
}
}