示例#1
0
        public string Execute(string[] parameters)
        {
            SortedDictionary <string, string> dict = new SortedDictionary <string, string>();

            foreach (string key in register.Keys)
            {
                IGameConsoleInternCommand command = register[key] as IGameConsoleInternCommand;
                if (command != null)
                {
                    dict.Add(key, command.Info);
                }
            }

            int size = "Command".Length;

            foreach (string key in dict.Keys)
            {
                if (size < key.Length)
                {
                    size = key.Length;
                }
            }

            size += 3;

            string result =
                "\n" +
                "Command".PadRight(size) + "Function\n" +
                "-----------------------------------------------\n";

            foreach (string key in dict.Keys)
            {
                result += key.PadRight(size) + dict[key] + "\n";
            }


            result += "\n" +
                      "Type \"<Command> -?\" for further information.";
            return(result);
        }
示例#2
0
        /// <summary>
        /// Executes the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <returns></returns>
        public string Execute(string command)
        {
            List <string> parameters = new List <string>();

            string[] quotes = command.Split('"');
            if (quotes.Length % 2 == 0)
            {
                return("ERROR: odd number of quotes are not allowed.");
            }

            for (int i = 0; i < quotes.Length; i++)
            {
                if (i % 2 == 0)
                {
                    if (!string.IsNullOrEmpty(quotes[i]))
                    {
                        parameters.AddRange(quotes[i].Trim().Split(' '));
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(quotes[i]))
                    {
                        parameters.Add(quotes[i]);
                    }
                }
            }

            if (parameters.Count == 0)
            {
                return("");
            }

            string commandObject = parameters[0];

            parameters.Remove(parameters[0]);

            string objectName   = "";
            string functionName = "";

            string[] commandObjectParts = commandObject.Split('.');
            if (commandObjectParts.Length > 0)
            {
                objectName = commandObjectParts[0];
            }
            if (commandObjectParts.Length > 1)
            {
                functionName = commandObjectParts[1];
            }

            if (!this.caseSensitive)
            {
                objectName   = objectName.ToUpper();
                functionName = functionName.ToUpper();
            }


            // console objects
            if (register.ContainsKey(objectName))
            {
                GameConsoleObject consoleObject = register[objectName] as GameConsoleObject;
                if (consoleObject != null)
                {
                    return(consoleObject.Execute(functionName, parameters.ToArray()));
                }
            }

            // intern commands
            if (register.ContainsKey(objectName.ToUpper()))
            {
                IGameConsoleInternCommand consoleCommand = register[objectName.ToUpper()] as IGameConsoleInternCommand;
                if (consoleCommand != null)
                {
                    return(consoleCommand.Execute(parameters.ToArray()));
                }
            }
            return("\nERROR: Command not found. Type \"help\" for information.");
        }
示例#3
0
 /// <summary>
 /// Registers the command.
 /// </summary>
 /// <param name="commandName">Name of the command.</param>
 /// <param name="command">The command.</param>
 /// <returns></returns>
 private bool RegisterCommand(string commandName, IGameConsoleInternCommand command)
 {
     register.Add(commandName.ToUpper(), command);
     return(true);
 }