private static void AddCommand(string CommandName, byte ArgumentCount, string CommandHelp, TCALLBACKCommandProc CommandProc) { if (!String.IsNullOrEmpty(CommandName)) { string[] CommandWithParameters = Tokenize(CommandName); CommandName = CommandWithParameters[0]; if (!Commands.ContainsKey(CommandName)) { CommandNode Node = new CommandNode(); Node.Name = CommandName; Node.ParamCount = ArgumentCount; Node.Help = CommandHelp; Node.CommandProc = CommandProc; Commands.Add(CommandName, Node); } } }
public static void ExecuteCommand(string CommandLine) { CommandLine = CommandStandardization(CommandLine); if (!String.IsNullOrEmpty(CommandLine)) { string[] CommandWithParameters = Tokenize(CommandLine); string CommandName = CommandWithParameters[0]; string[] Parameters = null; // If the command with its parameters presents if (CommandWithParameters.Length > 1) { Parameters = new string[CommandWithParameters.Length - 1]; for (ushort Counter = 1; Counter < CommandWithParameters.Length; Counter++) { Parameters[Counter - 1] = CommandWithParameters[Counter]; } } if (Commands.ContainsKey(CommandName)) { CommandNode Node = Commands[CommandName]; if (Node.CommandProc != null) { Node.CommandProc(Parameters); } else { ConsoleManager.WriteLine("Error! Command delegate not defined!"); } } else { ConsoleManager.WriteLine("Error! Invalid command!"); } } }