Beispiel #1
0
        public void Render(IMob mob)
        {
            if (!(mob is IPlayer))
            {
                throw new NullReferenceException("ConnectState can only be used with a player object implementing IPlayer");
            }

            //Store a reference for the GetCommand() method to use.
            this.connectedPlayer = mob as IPlayer;
            var server = mob.Game as IServer;
            var game   = mob.Game as IGame;

            // It is not guaranteed that mob.Game will implement IServer. We are only guaranteed that it will implement IGame.
            if (server == null)
            {
                throw new NullReferenceException("LoginState can only be set to a player object that is part of a server.");
            }

            //Output the game information
            mob.Send(new InformationalMessage(game.Name));
            mob.Send(new InformationalMessage(game.Description));
            mob.Send(new InformationalMessage(string.Empty)); //blank line

            //Output the server MOTD information
            mob.Send(new InformationalMessage(string.Join("\n", server.MessageOfTheDay)));
            mob.Send(new InformationalMessage(string.Empty)); //blank line

            this.connectedPlayer.StateManager.SwitchState <LoginState>();
        }
Beispiel #2
0
        public void Render(IMob mob)
        {
            if (!(mob is IPlayer))
            {
                throw new NullReferenceException("ConnectState can only be used with a player object implementing IPlayer");
            }

            //Store a reference for the GetCommand() method to use.
            this.connectedPlayer = mob as IPlayer;
            var server = mob.Game as IServer;
            var game = mob.Game as IGame;

            // It is not guaranteed that mob.Game will implement IServer. We are only guaranteed that it will implement IGame.
            if (server == null)
            {
                throw new NullReferenceException("LoginState can only be set to a player object that is part of a server.");
            }

            //Output the game information
            mob.Send(new InformationalMessage(game.Name));
            mob.Send(new InformationalMessage(game.Description));
            mob.Send(new InformationalMessage(string.Empty)); //blank line

            //Output the server MOTD information
            mob.Send(new InformationalMessage(string.Join("\n", server.MessageOfTheDay)));
            mob.Send(new InformationalMessage(string.Empty)); //blank line

            this.connectedPlayer.StateManager.SwitchState<LoginState>();
        }
Beispiel #3
0
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="mob">The mob.</param>
 /// <param name="input">The input.</param>
 public void Execute(IMob mob, string input)
 {
     if (mob == null)
         return; // Can happen when the user connection is closed in the middle of a command or state executing
     else
         mob.Send(new InformationalMessage("Invalid command used!"));
 }
 public void Execute(IMob mob, string input)
 {
     if (!this.IsIncomplete)
     {
         mob.Send(new InformationalMessage(string.Format("You entered {0}. More info is required.", input)));
         this.CommandInput = input;
         this.IsIncomplete = true;
         mob.StateManager.SwitchState<ReceivingInputState>();
     }
     else
     {
         this.IsIncomplete = false;
         mob.Send(new InformationalMessage(string.Format("Your {0} data is associated with {1}", this.CommandInput, input)));
         mob.StateManager.SwitchState<TestState>();
     }
 }
Beispiel #5
0
 public void Execute(IMob mob, string input)
 {
     if (!this.IsIncomplete)
     {
         mob.Send(new InformationalMessage(string.Format("You entered {0}. More info is required.", input)));
         this.CommandInput = input;
         this.IsIncomplete = true;
         mob.StateManager.SwitchState <ReceivingInputState>();
     }
     else
     {
         this.IsIncomplete = false;
         mob.Send(new InformationalMessage(string.Format("Your {0} data is associated with {1}", this.CommandInput, input)));
         mob.StateManager.SwitchState <TestState>();
     }
 }
Beispiel #6
0
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="mob">The mob.</param>
 /// <param name="input">The input.</param>
 public void Execute(IMob mob, string input)
 {
     if (mob == null)
     {
         return; // Can happen when the user connection is closed in the middle of a command or state executing
     }
     else
     {
         mob.Send(new InformationalMessage("Invalid command used!"));
     }
 }
Beispiel #7
0
 public void Render(IMob mob)
 {
     mob.Send(new InformationalMessage("Message from TestState."));
 }
Beispiel #8
0
 public void Render(IMob mob)
 {
     mob.Send(new InformationalMessage("Message from TestState."));
 }