コード例 #1
0
 public void ChangeUsername(string username, string password, string newUsername)
 {
     if (string.IsNullOrWhiteSpace(username) | string.IsNullOrWhiteSpace(password) | string.IsNullOrWhiteSpace(newUsername))
     {
         SendCallbackMessage("Некоторые поля не заполнены!");
     }
     else
     {
         using (var context = new ChessDb.Context())
         {
             if (context.HasUser(newUsername))
             {
                 SendCallbackMessage("Такой пользователь уже существует!");
             }
             else
             if (context.HasUser(username, password))
             {
                 context.Users.SingleOrDefault(item => item.Username == username).Username = newUsername;
                 context.SaveChanges();
                 try
                 {
                     var callback = OperationContext.Current.GetCallbackChannel <IGameSessionEstablishmentCallback>();
                     callback.UsernameChanged(newUsername);
                 }
                 catch (Exception) { }
             }
             else
             {
                 SendCallbackMessage("Неверный пароль!");
             }
         }
     }
 }
コード例 #2
0
 public void LoginUser(string username, string password)
 {
     if (string.IsNullOrWhiteSpace(username) | string.IsNullOrWhiteSpace(password))
     {
         SendCallbackMessage("Некоторые поля не заполнены!");
     }
     else
     {
         using (var context = new ChessDb.Context())
         {
             if (context.HasUser(username, password))
             {
                 try
                 {
                     var callback = OperationContext.Current.GetCallbackChannel <IGameSessionEstablishmentCallback>();
                     var rating   = context.GetTotalScore(username);
                     callback.SuccesfullAuthentificate(username, password, rating);
                 }
                 catch (Exception) { }
             }
             else
             {
                 SendCallbackMessage("Такого пользователя не существует!");
             }
         }
     }
 }
コード例 #3
0
 public void SignupUser(string username, string password, string confirmedPassword)
 {
     if (string.IsNullOrWhiteSpace(username) | string.IsNullOrWhiteSpace(password) | string.IsNullOrWhiteSpace(confirmedPassword))
     {
         SendCallbackMessage("Некоторые поля не заполнены!");
     }
     else
     if (password != confirmedPassword)
     {
         SendCallbackMessage("Пароли не совподают!");
     }
     else
     {
         using (var context = new ChessDb.Context())
         {
             if (context.HasUser(username))
             {
                 SendCallbackMessage("Такой пользователь уже существует!");
             }
             else
             {
                 context.CreateUser(username, password);
                 try
                 {
                     var callback = OperationContext.Current.GetCallbackChannel <IGameSessionEstablishmentCallback>();
                     callback.SuccesfullAuthentificate(username, password, 2000);
                 }
                 catch (Exception) { }
             }
         }
     }
 }
コード例 #4
0
        private bool TryCreatePlayer(string username, string password)
        {
            bool playerIsConnected  = false;
            bool isExistPlayer      = _players.Exists(item => item.Name == username);
            bool inputDataIsNotNull = !string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password);

            if (CurrentPlayer == null && inputDataIsNotNull && !isExistPlayer)
            {
                using (var context = new ChessDb.Context())
                {
                    if (context.HasUser(username, password))
                    {
                        var callback = OperationContext.Current.GetCallbackChannel <IGameSessionEstablishmentCallback>();
                        CurrentPlayer = new Player(username, context.GetTotalScore(username), callback);
                        _players.Add(CurrentPlayer);
                        playerIsConnected = true;
                    }
                }
            }
            return(playerIsConnected);
        }