public CommandCompletionArgs(string command, ICharacter owner, IEnumerable<string> args, InputCommandResult result) { this.Command = command; this.Arguments = args; this.Owner = owner; this.CommandResult = result; }
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); }
private void EvaluateCommandState(InputCommandResult commandResult) { if (commandResult == null || commandResult.IsCommandCompleted) { return; } this.currentlyExecutingCommands.Push(commandResult.CommandExecuted); }
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)); } }
public CommandCompletionArgs(string command, ICharacter owner, IEnumerable <string> args, InputCommandResult result) { this.Command = command; this.Arguments = args; this.Owner = owner; this.CommandResult = result; }
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; }
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; }
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; }