diff --git a/EOLib/Domain/Login/PlayerInfoRepository.cs b/EOLib/Domain/Login/PlayerInfoRepository.cs index 4b1fc547e..8b03b51d6 100644 --- a/EOLib/Domain/Login/PlayerInfoRepository.cs +++ b/EOLib/Domain/Login/PlayerInfoRepository.cs @@ -4,6 +4,8 @@ namespace EOLib.Domain.Login { public interface IPlayerInfoRepository { + int LoginAttempts { get; set; } + string LoggedInAccountName { get; set; } string PlayerPassword { get; set; } @@ -19,6 +21,8 @@ public interface IPlayerInfoRepository public interface IPlayerInfoProvider { + int LoginAttempts { get; } + string LoggedInAccountName { get; } string PlayerPassword { get; } @@ -35,6 +39,8 @@ public interface IPlayerInfoProvider [AutoMappedType(IsSingleton = true)] public sealed class PlayerInfoRepository : IPlayerInfoRepository, IPlayerInfoProvider, IResettable { + public int LoginAttempts { get; set; } + public string LoggedInAccountName { get; set; } public string PlayerPassword { get; set; } @@ -47,8 +53,11 @@ public sealed class PlayerInfoRepository : IPlayerInfoRepository, IPlayerInfoPro public bool PlayerHasAdminCharacter { get; set; } + public PlayerInfoRepository() => ResetState(); + public void ResetState() { + LoginAttempts = 0; LoggedInAccountName = ""; PlayerPassword = ""; PlayerID = 0; diff --git a/EndlessClient/Controllers/LoginController.cs b/EndlessClient/Controllers/LoginController.cs index 00139d7ca..d46fcc03f 100644 --- a/EndlessClient/Controllers/LoginController.cs +++ b/EndlessClient/Controllers/LoginController.cs @@ -27,7 +27,7 @@ namespace EndlessClient.Controllers { - [MappedType(BaseType = typeof(ILoginController))] + [AutoMappedType] public class LoginController : ILoginController { private readonly ILoginActions _loginActions; @@ -42,6 +42,7 @@ public class LoginController : ILoginController private readonly IUserInputTimeRepository _userInputTimeRepository; private readonly IClientWindowSizeRepository _clientWindowSizeRepository; private readonly IConfigurationProvider _configurationProvider; + private readonly IPlayerInfoRepository _playerInfoRepository; private readonly IErrorDialogDisplayAction _errorDisplayAction; private readonly ISafeNetworkOperationFactory _networkOperationFactory; private readonly IGameLoadingDialogFactory _gameLoadingDialogFactory; @@ -66,7 +67,8 @@ public LoginController(ILoginActions loginActions, INewsProvider newsProvider, IUserInputTimeRepository userInputTimeRepository, IClientWindowSizeRepository clientWindowSizeRepository, - IConfigurationProvider configurationProvider) + IConfigurationProvider configurationProvider, + IPlayerInfoRepository playerInfoRepository) { _loginActions = loginActions; _mapFileLoadActions = mapFileLoadActions; @@ -86,6 +88,7 @@ public LoginController(ILoginActions loginActions, _userInputTimeRepository = userInputTimeRepository; _clientWindowSizeRepository = clientWindowSizeRepository; _configurationProvider = configurationProvider; + _playerInfoRepository = playerInfoRepository; } public async Task LoginToAccount(ILoginParameters loginParameters) @@ -107,8 +110,18 @@ public async Task LoginToAccount(ILoginParameters loginParameters) } else { + if (reply == LoginReply.WrongUser || reply == LoginReply.WrongUserPassword) + _playerInfoRepository.LoginAttempts++; + else + _playerInfoRepository.LoginAttempts = 3; + _errorDisplayAction.ShowLoginError(reply); - _gameStateActions.ChangeToState(GameStates.Initial); + + if (_playerInfoRepository.LoginAttempts >= 3) + { + _gameStateActions.ChangeToState(GameStates.Initial); + _playerInfoRepository.LoginAttempts = 0; + } } }