示例#1
0
        public void RegisterCommand(AbstractConsoleCommand command)
        {
            if (_commands.Any(c => c.CommandName.Trim().ToLower().Equals(command.CommandName.Trim().ToLower())))
            {
                LogUtils.LogError("Command: " + command.CommandName + " is already registered");
                return;
            }

            _commands.Add(command);
        }
示例#2
0
        private void UnregisterCommand(string cmd)
        {
            AbstractConsoleCommand command =
                _commands.FirstOrDefault(c => c.CommandName.ToLower().Trim().Equals(cmd.Trim().ToLower()));

            if (command == null)
            {
                return;
            }
            _commands.Remove(command);
        }
示例#3
0
        public void Eval(string commandLine)
        {
            string cmd = Regex.Split(commandLine, " ").ToArray()[0];

            string[] args = Regex.Split(commandLine, " ").Skip(1).ToArray();

            AbstractConsoleCommand command = _commands.FirstOrDefault(c => c.CommandName.ToLower() == cmd.ToLower());

            if (command != null && command.CommandRuntime != ConsoleCommandRuntime.NONE)
            {
                switch (command.CommandRuntime)
                {
                case ConsoleCommandRuntime.CLIENT:
                    if (!Connection.IsClient())
                    {
                        command = null;
                    }
                    break;

                case ConsoleCommandRuntime.SERVER:
                    if (!Connection.IsServer())
                    {
                        command = null;
                    }
                    break;

                case ConsoleCommandRuntime.BOTH:
                    if (Connection.CurrentConnection == null)
                    {
                        command = null;
                    }
                    break;
                }
            }
            if (command == null)
            {
                Print("Command \"" + cmd + "\" not found");
                return;
            }
            command.Execute(args);
        }