예제 #1
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("Такого пользователя не существует!");
             }
         }
     }
 }
예제 #2
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);
        }