corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using OpenMetaverse;
5 using OpenMetaverse.Packets;
6  
7 namespace OpenMetaverse.TestClient
8 {
9 public class HelpCommand: Command
10 {
11 public HelpCommand(TestClient testClient)
12 {
13 Name = "help";
14 Description = "Lists available commands. usage: help [command] to display information on commands";
15 Category = CommandCategory.TestClient;
16 }
17  
18 public override string Execute(string[] args, UUID fromAgentID)
19 {
20 if (args.Length > 0)
21 {
22 if (Client.Commands.ContainsKey(args[0]))
23 return Client.Commands[args[0]].Description;
24 else
25 return "Command " + args[0] + " Does not exist. \"help\" to display all available commands.";
26 }
27 StringBuilder result = new StringBuilder();
28 SortedDictionary<CommandCategory, List<Command>> CommandTree = new SortedDictionary<CommandCategory, List<Command>>();
29  
30 CommandCategory cc;
31 foreach (Command c in Client.Commands.Values)
32 {
33 if (c.Category.Equals(null))
34 cc = CommandCategory.Unknown;
35 else
36 cc = c.Category;
37  
38 if (CommandTree.ContainsKey(cc))
39 CommandTree[cc].Add(c);
40 else
41 {
42 List<Command> l = new List<Command>();
43 l.Add(c);
44 CommandTree.Add(cc, l);
45 }
46 }
47  
48 foreach (KeyValuePair<CommandCategory, List<Command>> kvp in CommandTree)
49 {
50 result.AppendFormat(System.Environment.NewLine + "* {0} Related Commands:" + System.Environment.NewLine, kvp.Key.ToString());
51 int colMax = 0;
52 for (int i = 0; i < kvp.Value.Count; i++)
53 {
54 if (colMax >= 120)
55 {
56 result.AppendLine();
57 colMax = 0;
58 }
59  
60 result.AppendFormat(" {0,-15}", kvp.Value[i].Name);
61 colMax += 15;
62 }
63 result.AppendLine();
64 }
65 result.AppendLine(System.Environment.NewLine + "Help [command] for usage/information");
66  
67 return result.ToString();
68 }
69 }
70 }