Пример #1
0
 public CommandCompletionArgs(string command, ICharacter owner, IEnumerable<string> args, InputCommandResult result)
 {
     this.Command = command;
     this.Arguments = args;
     this.Owner = owner;
     this.CommandResult = result;
 }
Пример #2
0
        private async Task ExecuteCharacterCommand(IInputCommand currentCommand, string[] args)
        {
            if (this.Owner == null)
            {
                this.ResetOwner();
            }

            InputCommandResult commandResult = null;

            // Only enumerate over this collection once.
            bool hasCurrentlyExecutingCommands = this.currentlyExecutingCommands.Any();

            if (currentCommand == null && !hasCurrentlyExecutingCommands)
            {
                // No command was found and we have no state, so tell the user they've entered something invalid.
                commandResult = new InputCommandResult("Unknown Command.\r\n", true, null, this.Owner);
                this.CompleteProcessing(commandResult);
            }
            else if (currentCommand == null && hasCurrentlyExecutingCommands || hasCurrentlyExecutingCommands && this.currentlyExecutingCommands.Peek().ExclusiveCommand)
            {
                // If we have a command already being processed, we continue to process it
                currentCommand = this.currentlyExecutingCommands.Pop();
            }

            InputCommandResult result = await currentCommand.ExecuteAsync(this.Owner, args);

            this.CompleteProcessing(result);
        }
Пример #3
0
        private async Task ExecuteCharacterCommand(IInputCommand currentCommand, string[] args)
        {
            if (this.Owner == null)
            {
                this.ResetOwner();
            }

            InputCommandResult commandResult = null;

            // Only enumerate over this collection once.
            bool hasCurrentlyExecutingCommands = this.currentlyExecutingCommands.Any();

            if (currentCommand == null && !hasCurrentlyExecutingCommands)
            {
                // No command was found and we have no state, so tell the user they've entered something invalid.
                commandResult = new InputCommandResult("Unknown Command.\r\n", true, null, this.Owner);
                this.CompleteProcessing(commandResult);
            }
            else if (currentCommand == null && hasCurrentlyExecutingCommands || hasCurrentlyExecutingCommands && this.currentlyExecutingCommands.Peek().ExclusiveCommand)
            {
                // If we have a command already being processed, we continue to process it
                currentCommand = this.currentlyExecutingCommands.Pop();
            }
            
            InputCommandResult result = await currentCommand.ExecuteAsync(this.Owner, args);
            this.CompleteProcessing(result);
        }
Пример #4
0
        private void EvaluateCommandState(InputCommandResult commandResult)
        {
            if (commandResult == null || commandResult.IsCommandCompleted)
            {
                return;
            }

            this.currentlyExecutingCommands.Push(commandResult.CommandExecuted);
        }
Пример #5
0
        private void CompleteProcessing(InputCommandResult result)
        {
            if (result == null)
            {
                throw new NullReferenceException($"{result.CommandExecuted.GetType().Name} returned a null InputCommandResult when it shouldn't have!");
            }

            this.EvaluateCommandState(result);
            this.notificationCenter.Publish(new InformationMessage(result.Result, this.Owner));
            if (result.IsCommandCompleted)
            {
                this.notificationCenter.Publish(new InformationMessage(">>:", this.Owner));
            }
        }
Пример #6
0
 public CommandCompletionArgs(string command, ICharacter owner, IEnumerable <string> args, InputCommandResult result)
 {
     this.Command       = command;
     this.Arguments     = args;
     this.Owner         = owner;
     this.CommandResult = result;
 }
Пример #7
0
        private void EvaluateCommandState(InputCommandResult commandResult)
        {
            if (commandResult == null || commandResult.IsCommandCompleted)
            {
                return;
            }

            this.currentlyExecutingCommands.Push(commandResult.CommandExecuted);
        }
Пример #8
0
        private void CompleteProcessing(InputCommandResult result)
        {
            if (result == null)
            {
                throw new NullReferenceException($"{result.CommandExecuted.GetType().Name} returned a null InputCommandResult when it shouldn't have!");
            }

            this.EvaluateCommandState(result);
            this.notificationCenter.Publish(new InformationMessage(result.Result, this.Owner));
            if (result.IsCommandCompleted)
            {
                this.notificationCenter.Publish(new InformationMessage(">>:", this.Owner));
            }
        }
Пример #9
0
            public override bool Process(ICharacter owner, IInputCommand command, string[] args, out InputCommandResult result)
            {
                if (args.Length == 0)
                {
                    result = new InputCommandResult("Invalid password\r\n name: ", false, command, owner);
                    return false;
                }

                result = new InputCommandResult("Login Successful\r\n", this.GetNextProcessor() != null, command, owner);
                return true;
            }
Пример #10
0
 public override bool Process(ICharacter owner, IInputCommand command, string[] args, out InputCommandResult result)
 {
     this.notificationCenter.Publish(new InformationMessage("Please enter your character name: ", owner));
     result = new InputCommandResult(false, command, owner);
     return true;
 }
Пример #11
0
            public override bool Process(ICharacter owner, IInputCommand command, string[] args, out InputCommandResult result)
            {
                if (args.Length == 0 || string.IsNullOrWhiteSpace(args[0]))
                {
                    result = new InputCommandResult("You must enter a character name.", false, command, owner);
                    return false;
                }

                this.notificationManager.Publish(new InformationMessage("Please enter your character's password: ", owner));
                result = new InputCommandResult(false, command, owner);
                return true;
            }