From e93869c7a785a4f375685ffa33c913033ed1c85a Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Thu, 21 Jun 2007 17:08:21 +0000 Subject: * Importing Ming's mass test client --- .../Commands/Communication/IMCommand.cs | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tools/mass test client/Commands/Communication/IMCommand.cs (limited to 'tools/mass test client/Commands/Communication/IMCommand.cs') diff --git a/tools/mass test client/Commands/Communication/IMCommand.cs b/tools/mass test client/Commands/Communication/IMCommand.cs new file mode 100644 index 0000000..d847291 --- /dev/null +++ b/tools/mass test client/Commands/Communication/IMCommand.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using libsecondlife; +using libsecondlife.Packets; + +namespace libsecondlife.TestClient +{ + public class ImCommand : Command + { + string ToAvatarName = String.Empty; + ManualResetEvent NameSearchEvent = new ManualResetEvent(false); + Dictionary Name2Key = new Dictionary(); + + 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()]; + + Client.Self.InstantMessage(id, message, id); + return "Instant Messaged " + id.ToStringHyphenated() + " with message: " + message; + } + else + { + return "Name lookup for " + ToAvatarName + " failed"; + } + } + + void Avatars_OnAvatarNameSearch(LLUUID queryID, Dictionary avatars) + { + foreach (KeyValuePair kvp in avatars) + { + if (kvp.Value.ToLower() == ToAvatarName.ToLower()) + { + Name2Key[ToAvatarName.ToLower()] = kvp.Key; + NameSearchEvent.Set(); + return; + } + } + } + } +} -- cgit v1.1