diff options
author | Adam Frisby | 2007-06-21 17:08:21 +0000 |
---|---|---|
committer | Adam Frisby | 2007-06-21 17:08:21 +0000 |
commit | e93869c7a785a4f375685ffa33c913033ed1c85a (patch) | |
tree | abb5e2c58f8750a1bc05acf58716b6b025da4d15 /tools/mass test client/Commands/Communication/IMCommand.cs | |
parent | Fixed the struct and null compare bug. (diff) | |
download | opensim-SC_OLD-e93869c7a785a4f375685ffa33c913033ed1c85a.zip opensim-SC_OLD-e93869c7a785a4f375685ffa33c913033ed1c85a.tar.gz opensim-SC_OLD-e93869c7a785a4f375685ffa33c913033ed1c85a.tar.bz2 opensim-SC_OLD-e93869c7a785a4f375685ffa33c913033ed1c85a.tar.xz |
* Importing Ming's mass test client
Diffstat (limited to 'tools/mass test client/Commands/Communication/IMCommand.cs')
-rw-r--r-- | tools/mass test client/Commands/Communication/IMCommand.cs | 71 |
1 files changed, 71 insertions, 0 deletions
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 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Threading; | ||
4 | using libsecondlife; | ||
5 | using libsecondlife.Packets; | ||
6 | |||
7 | namespace libsecondlife.TestClient | ||
8 | { | ||
9 | public class ImCommand : Command | ||
10 | { | ||
11 | string ToAvatarName = String.Empty; | ||
12 | ManualResetEvent NameSearchEvent = new ManualResetEvent(false); | ||
13 | Dictionary<string, LLUUID> Name2Key = new Dictionary<string, LLUUID>(); | ||
14 | |||
15 | public ImCommand(TestClient testClient) | ||
16 | { | ||
17 | testClient.Avatars.OnAvatarNameSearch += new AvatarManager.AvatarNameSearchCallback(Avatars_OnAvatarNameSearch); | ||
18 | |||
19 | Name = "im"; | ||
20 | Description = "Instant message someone. Usage: im [firstname] [lastname] [message]"; | ||
21 | } | ||
22 | |||
23 | public override string Execute(string[] args, LLUUID fromAgentID) | ||
24 | { | ||
25 | if (args.Length < 3) | ||
26 | return "Usage: im [firstname] [lastname] [message]"; | ||
27 | |||
28 | ToAvatarName = args[0] + " " + args[1]; | ||
29 | |||
30 | // Build the message | ||
31 | string message = String.Empty; | ||
32 | for (int ct = 2; ct < args.Length; ct++) | ||
33 | message += args[ct] + " "; | ||
34 | message = message.TrimEnd(); | ||
35 | if (message.Length > 1023) message = message.Remove(1023); | ||
36 | |||
37 | if (!Name2Key.ContainsKey(ToAvatarName.ToLower())) | ||
38 | { | ||
39 | // Send the Query | ||
40 | Client.Avatars.RequestAvatarNameSearch(ToAvatarName, LLUUID.Random()); | ||
41 | |||
42 | NameSearchEvent.WaitOne(6000, false); | ||
43 | } | ||
44 | |||
45 | if (Name2Key.ContainsKey(ToAvatarName.ToLower())) | ||
46 | { | ||
47 | LLUUID id = Name2Key[ToAvatarName.ToLower()]; | ||
48 | |||
49 | Client.Self.InstantMessage(id, message, id); | ||
50 | return "Instant Messaged " + id.ToStringHyphenated() + " with message: " + message; | ||
51 | } | ||
52 | else | ||
53 | { | ||
54 | return "Name lookup for " + ToAvatarName + " failed"; | ||
55 | } | ||
56 | } | ||
57 | |||
58 | void Avatars_OnAvatarNameSearch(LLUUID queryID, Dictionary<LLUUID, string> avatars) | ||
59 | { | ||
60 | foreach (KeyValuePair<LLUUID, string> kvp in avatars) | ||
61 | { | ||
62 | if (kvp.Value.ToLower() == ToAvatarName.ToLower()) | ||
63 | { | ||
64 | Name2Key[ToAvatarName.ToLower()] = kvp.Key; | ||
65 | NameSearchEvent.Set(); | ||
66 | return; | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | } | ||