Exemplo n.º 1
0
        private bool ExecuteCommand(string line)
        {
            string        command;
            List <string> args = new List <string>();

            int a = line.IndexOf(' ');

            if (a == -1)
            {
                a = line.Length;
            }

            command = line.Substring(0, a);
            line    = line.Remove(0, a);

            if (command.Length <= 0)
            {
                return(false);
            }

            IConsoleHandler Handler = null;

            if (!Instance.m_consoleHandlers.ContainsKey(command))
            {
                return(false);
            }

            Handler = Instance.m_consoleHandlers[command];

            string[] Args = line.Split(' ');

            foreach (string str in Args)
            {
                if (str.Length > 1 || (str.Length == 1 && str[0] != ' '))
                {
                    args.Add(str);
                }
            }

            var consoleHandlerAttribs = (ConsoleHandlerAttribute[])Handler.GetType().GetCustomAttributes(typeof(ConsoleHandlerAttribute), true);

            if (consoleHandlerAttribs[0].ArgCount != 0 && consoleHandlerAttribs[0].ArgCount > args.Count)
            {
                Log.Error("ConsoleMgr", "Invalid parameter count : " + args.Count + " / " + consoleHandlerAttribs[0].ArgCount);
            }
            else
            {
                if (!Handler.HandleCommand(command, args))
                {
                    Log.Error("ConsoleMgr", "Invalid command parameter !");
                }
            }

            return(true);
        }