diff options
Diffstat (limited to '')
-rw-r--r-- | tools/mass test client/Commands/System/PacketLogCommand.cs | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/tools/mass test client/Commands/System/PacketLogCommand.cs b/tools/mass test client/Commands/System/PacketLogCommand.cs new file mode 100644 index 0000000..694cee1 --- /dev/null +++ b/tools/mass test client/Commands/System/PacketLogCommand.cs | |||
@@ -0,0 +1,84 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Xml; | ||
4 | using libsecondlife; | ||
5 | using libsecondlife.Packets; | ||
6 | |||
7 | namespace libsecondlife.TestClient | ||
8 | { | ||
9 | public class PacketLogCommand : Command | ||
10 | { | ||
11 | List<Packet> Packets = new List<Packet>(); | ||
12 | bool Done = false; | ||
13 | int Count = 0; | ||
14 | int Total = 0; | ||
15 | |||
16 | public PacketLogCommand(TestClient testClient) | ||
17 | { | ||
18 | Name = "packetlog"; | ||
19 | Description = "Logs a given number of packets to an xml file. Usage: packetlog 10 tenpackets.xml"; | ||
20 | } | ||
21 | |||
22 | public override string Execute(string[] args, LLUUID fromAgentID) | ||
23 | { | ||
24 | if (args.Length != 2) | ||
25 | return "Usage: packetlog 10 tenpackets.xml"; | ||
26 | |||
27 | XmlWriter writer; | ||
28 | NetworkManager.PacketCallback callback = new NetworkManager.PacketCallback(OnPacket); | ||
29 | |||
30 | Packets.Clear(); | ||
31 | Done = false; | ||
32 | Count = 0; | ||
33 | |||
34 | try | ||
35 | { | ||
36 | Total = Int32.Parse(args[0]); | ||
37 | writer = XmlWriter.Create(args[1]); | ||
38 | |||
39 | Client.Network.RegisterCallback(PacketType.Default, callback); | ||
40 | } | ||
41 | catch (Exception e) | ||
42 | { | ||
43 | return "Usage: packetlog 10 tenpackets.xml (" + e + ")"; | ||
44 | } | ||
45 | |||
46 | while (!Done) | ||
47 | { | ||
48 | System.Threading.Thread.Sleep(100); | ||
49 | } | ||
50 | |||
51 | Client.Network.UnregisterCallback(PacketType.Default, callback); | ||
52 | |||
53 | try | ||
54 | { | ||
55 | Helpers.PacketListToXml(Packets, writer); | ||
56 | } | ||
57 | catch (Exception e) | ||
58 | { | ||
59 | return "Serialization failed: " + e.ToString(); | ||
60 | } | ||
61 | |||
62 | writer.Close(); | ||
63 | Packets.Clear(); | ||
64 | |||
65 | return "Exported " + Count + " packets to " + args[1]; | ||
66 | } | ||
67 | |||
68 | private void OnPacket(Packet packet, Simulator simulator) | ||
69 | { | ||
70 | lock (Packets) | ||
71 | { | ||
72 | if (Count >= Total) | ||
73 | { | ||
74 | Done = true; | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | Packets.Add(packet); | ||
79 | Count++; | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | } | ||
84 | } | ||