corrade-vassal – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | using System; |
2 | using System.Collections.Generic; |
||
3 | using System.Threading; |
||
4 | using OpenMetaverse; |
||
5 | using OpenMetaverse.Packets; |
||
6 | |||
7 | namespace OpenMetaverse.TestClient |
||
8 | { |
||
9 | public class ImCommand : Command |
||
10 | { |
||
11 | string ToAvatarName = String.Empty; |
||
12 | ManualResetEvent NameSearchEvent = new ManualResetEvent(false); |
||
13 | Dictionary<string, UUID> Name2Key = new Dictionary<string, UUID>(); |
||
14 | |||
15 | public ImCommand(TestClient testClient) |
||
16 | { |
||
17 | testClient.Avatars.AvatarPickerReply += Avatars_AvatarPickerReply; |
||
18 | |||
19 | Name = "im"; |
||
20 | Description = "Instant message someone. Usage: im [firstname] [lastname] [message]"; |
||
21 | Category = CommandCategory.Communication; |
||
22 | } |
||
23 | |||
24 | public override string Execute(string[] args, UUID fromAgentID) |
||
25 | { |
||
26 | if (args.Length < 3) |
||
27 | return "Usage: im [firstname] [lastname] [message]"; |
||
28 | |||
29 | ToAvatarName = args[0] + " " + args[1]; |
||
30 | |||
31 | // Build the message |
||
32 | string message = String.Empty; |
||
33 | for (int ct = 2; ct < args.Length; ct++) |
||
34 | message += args[ct] + " "; |
||
35 | message = message.TrimEnd(); |
||
36 | if (message.Length > 1023) message = message.Remove(1023); |
||
37 | |||
38 | if (!Name2Key.ContainsKey(ToAvatarName.ToLower())) |
||
39 | { |
||
40 | // Send the Query |
||
41 | Client.Avatars.RequestAvatarNameSearch(ToAvatarName, UUID.Random()); |
||
42 | |||
43 | NameSearchEvent.WaitOne(6000, false); |
||
44 | } |
||
45 | |||
46 | if (Name2Key.ContainsKey(ToAvatarName.ToLower())) |
||
47 | { |
||
48 | UUID id = Name2Key[ToAvatarName.ToLower()]; |
||
49 | |||
50 | Client.Self.InstantMessage(id, message); |
||
51 | return "Instant Messaged " + id.ToString() + " with message: " + message; |
||
52 | } |
||
53 | else |
||
54 | { |
||
55 | return "Name lookup for " + ToAvatarName + " failed"; |
||
56 | } |
||
57 | } |
||
58 | |||
59 | void Avatars_AvatarPickerReply(object sender, AvatarPickerReplyEventArgs e) |
||
60 | { |
||
61 | foreach (KeyValuePair<UUID, string> kvp in e.Avatars) |
||
62 | { |
||
63 | if (kvp.Value.ToLower() == ToAvatarName.ToLower()) |
||
64 | { |
||
65 | Name2Key[ToAvatarName.ToLower()] = kvp.Key; |
||
66 | NameSearchEvent.Set(); |
||
67 | return; |
||
68 | } |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | } |