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 ImCommand : Command
|
|
|
|
|
{
|
|
|
|
|
string ToAvatarName = String.Empty;
|
|
|
|
|
ManualResetEvent NameSearchEvent = new ManualResetEvent(false);
|
|
|
|
|
Dictionary<string, LLUUID> Name2Key = new Dictionary<string, LLUUID>();
|
|
|
|
|
|
|
|
|
|
public ImCommand(TestClient testClient)
|
|
|
|
|
{
|
|
|
|
|
testClient.Avatars.OnAvatarNameSearch += new AvatarManager.AvatarNameSearchCallback(Avatars_OnAvatarNameSearch);
|
|
|
|
|
|
|
|
|
|
Name = "im";
|
|
|
|
|
Description = "Instant message someone. Usage: im [firstname] [lastname] [message]";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Execute(string[] args, LLUUID fromAgentID)
|
|
|
|
|
{
|
|
|
|
|
if (args.Length < 3)
|
|
|
|
|
return "Usage: im [firstname] [lastname] [message]";
|
|
|
|
|
|
|
|
|
|
ToAvatarName = args[0] + " " + args[1];
|
|
|
|
|
|
|
|
|
|
// Build the message
|
|
|
|
|
string message = String.Empty;
|
|
|
|
|
for (int ct = 2; ct < args.Length; ct++)
|
|
|
|
|
message += args[ct] + " ";
|
|
|
|
|
message = message.TrimEnd();
|
|
|
|
|
if (message.Length > 1023) message = message.Remove(1023);
|
|
|
|
|
|
|
|
|
|
if (!Name2Key.ContainsKey(ToAvatarName.ToLower()))
|
|
|
|
|
{
|
|
|
|
|
// Send the Query
|
|
|
|
|
Client.Avatars.RequestAvatarNameSearch(ToAvatarName, LLUUID.Random());
|
|
|
|
|
|
|
|
|
|
NameSearchEvent.WaitOne(6000, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Name2Key.ContainsKey(ToAvatarName.ToLower()))
|
|
|
|
|
{
|
|
|
|
|
LLUUID id = Name2Key[ToAvatarName.ToLower()];
|
|
|
|
|
|
2008-01-08 06:41:29 +00:00
|
|
|
Client.Self.InstantMessage(id, message);
|
2007-11-30 13:15:31 +00:00
|
|
|
return "Instant Messaged " + id.ToString() + " with message: " + message;
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return "Name lookup for " + ToAvatarName + " failed";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Avatars_OnAvatarNameSearch(LLUUID queryID, Dictionary<LLUUID, string> avatars)
|
|
|
|
|
{
|
|
|
|
|
foreach (KeyValuePair<LLUUID, string> kvp in avatars)
|
|
|
|
|
{
|
|
|
|
|
if (kvp.Value.ToLower() == ToAvatarName.ToLower())
|
|
|
|
|
{
|
|
|
|
|
Name2Key[ToAvatarName.ToLower()] = kvp.Key;
|
|
|
|
|
NameSearchEvent.Set();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|