Exemple #1
0
 private bool logIn(CommandLogin cmd)
 {
     try
     {
         Console.WriteLine("CH *new*: logging in...");
         Console.WriteLine("CH *new*: Login: {0} Pass: {1}", cmd.User, cmd.Pass);
         if (authenticate(cmd.User, cmd.Pass))
         {
             ID = cmd.User;
             Console.WriteLine("CH " + ID + ": Login successful");
             Command ctmp = new CommandAccept();
             ToSend.Add(ctmp);
             return(true);
         }
         else
         {
             Console.WriteLine("CH *new*: Invalid login or password. Login failed");
             Command ctmp = new CommandError(402);
             ToSend.Add(ctmp);
             Thread.Sleep(3000);
             cts.Cancel();
             return(false);
         }
     }
     catch (Exception)
     {
         Console.WriteLine("CH *new*: Login failed");
         cts.Cancel();
         return(false);
     }
 }
Exemple #2
0
        private bool logIn()
        {
            string  user = "******";
            string  pass = "******";
            Command tcmd = new CommandLogin(user, pass);

            cmdTrans.sendCmd(tcmd);
            tcmd = cmdTrans.getCmd();
            if (tcmd.GetType().Equals(typeof(CommandAccept)))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public Command InterpretRequest(string command)
        {
            Command interpretation;

            if (command.Equals(TextCommands.REGISTER, StringComparison.InvariantCultureIgnoreCase))
            {
                interpretation = new CommandRegister();
            }
            else if (command.Equals(TextCommands.LOGIN, StringComparison.InvariantCultureIgnoreCase))
            {
                interpretation = new CommandLogin();
            }
            else if (command.Equals(TextCommands.LOGOUT, StringComparison.InvariantCultureIgnoreCase))
            {
                interpretation = new CommandLogOut();
            }
            else if (command.Equals(TextCommands.JOINMATCH, StringComparison.InvariantCultureIgnoreCase))
            {
                interpretation = new CommandJoin();
            }
            else if (command.Equals(TextCommands.SELECTCHARACTER, StringComparison.InvariantCultureIgnoreCase))
            {
                interpretation = new CommandSelect();
            }
            else if (command.Equals(TextCommands.MOVE, StringComparison.InvariantCultureIgnoreCase))
            {
                interpretation = new CommandMove();
            }
            else if (command.Equals(TextCommands.ATTACK, StringComparison.InvariantCultureIgnoreCase))
            {
                interpretation = new CommandAttack();
            }
            else if (command.Equals(TextCommands.EXIT, StringComparison.InvariantCultureIgnoreCase))
            {
                interpretation = new CommandExit();
            }
            else
            {
                interpretation = new CommandUnknown();
            }
            return(interpretation);
        }