public async Task <string> AuthorizePlayerAsync(Guid gameId, string password, User user) { var game = await _gameStorage.GetByIdAsync(gameId); if (game is null) { return("GAME_NOT_FOUND"); } if (game.IsPrivate()) { if (string.IsNullOrEmpty(password)) { return("PASSWORD_REQUIRED"); } var passwordHash = MD5HashGenerator.GenerateHash(password); if (!game.Password.Equals(passwordHash)) { return("INCORRECT_PASSWORD"); } } game.AuthorizeUser(user.Id); await _gameStorage.EditAsync(game); return("OK"); }
public async Task <Game> CreateAsync(User user, string name, string password, GameOptions options) { if (!string.IsNullOrEmpty(password)) { password = MD5HashGenerator.GenerateHash(password); } var game = new Game(name, password, options); game.AuthorizeUser(user.Id); await _gameStorage.AddAsync(game); var player = Player.CreateAsAdmin(game.Id, user); await _playerStorage.AddAsync(player); return(game); }