Exemplo n.º 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;
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        private void EvaluateCommandState(InputCommandResult commandResult)
        {
            if (commandResult == null || commandResult.IsCommandCompleted)
            {
                return;
            }

            this.currentlyExecutingCommands.Push(commandResult.CommandExecuted);
        }
Exemplo n.º 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));
            }
        }
Exemplo n.º 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;
 }
Exemplo n.º 7
0
        private void EvaluateCommandState(InputCommandResult commandResult)
        {
            if (commandResult == null || commandResult.IsCommandCompleted)
            {
                return;
            }

            this.currentlyExecutingCommands.Push(commandResult.CommandExecuted);
        }
Exemplo n.º 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));
            }
        }
Exemplo n.º 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;
            }
Exemplo n.º 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;
 }
Exemplo n.º 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;
            }