* Completes Full documentation of DirectoryManager class * Cleaned up Search Methods in DirectoryManager to be more developer friendly * Adds Several TestClient commands related to DirectoryManager: searchgroups, searchland, searchpeople * Adds a StructToString method to helpers to simplify parsing and printing Structs for debugging purposes * Many other code cleanups * BREAKING - this is a major shift in the way events are internally handled, Take a look at the newly added TestClient commands for example code that implement this pattern. git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@3139 52acb1d6-8a22-11de-b505-999d5b087335
70 lines
2.3 KiB
C#
70 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using OpenMetaverse;
|
|
using OpenMetaverse.Packets;
|
|
|
|
namespace OpenMetaverse.TestClient
|
|
{
|
|
public class SetMasterCommand: Command
|
|
{
|
|
public DateTime Created = DateTime.Now;
|
|
private UUID resolvedMasterKey = UUID.Zero;
|
|
private ManualResetEvent keyResolution = new ManualResetEvent(false);
|
|
private UUID query = UUID.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]";
|
|
Category = CommandCategory.TestClient;
|
|
}
|
|
|
|
public override string Execute(string[] args, UUID 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]";
|
|
|
|
EventHandler<DirPeopleReplyEventArgs> callback = KeyResolvHandler;
|
|
Client.Directory.DirPeopleReply += callback;
|
|
|
|
query = Client.Directory.StartPeopleSearch(masterName, 0);
|
|
|
|
if (keyResolution.WaitOne(TimeSpan.FromMinutes(1), false))
|
|
{
|
|
Client.MasterKey = resolvedMasterKey;
|
|
keyResolution.Reset();
|
|
Client.Directory.DirPeopleReply -= callback;
|
|
}
|
|
else
|
|
{
|
|
keyResolution.Reset();
|
|
Client.Directory.DirPeopleReply -= callback;
|
|
return "Unable to obtain UUID for \"" + masterName + "\". Master unchanged.";
|
|
}
|
|
|
|
// Send an Online-only IM to the new master
|
|
Client.Self.InstantMessage(
|
|
Client.MasterKey, "You are now my master. IM me with \"help\" for a command list.");
|
|
|
|
return String.Format("Master set to {0} ({1})", masterName, Client.MasterKey.ToString());
|
|
}
|
|
|
|
private void KeyResolvHandler(object sender, DirPeopleReplyEventArgs e)
|
|
{
|
|
if (query != e.QueryID)
|
|
return;
|
|
|
|
resolvedMasterKey = e.MatchedPeople[0].AgentID;
|
|
keyResolution.Set();
|
|
query = UUID.Zero;
|
|
}
|
|
}
|
|
}
|