Skip to content

Commit

Permalink
Allow three login attempts before returning to initial state
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed May 28, 2024
1 parent 9c593dc commit 920c325
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
9 changes: 9 additions & 0 deletions EOLib/Domain/Login/PlayerInfoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace EOLib.Domain.Login
{
public interface IPlayerInfoRepository
{
int LoginAttempts { get; set; }

string LoggedInAccountName { get; set; }

string PlayerPassword { get; set; }
Expand All @@ -19,6 +21,8 @@ public interface IPlayerInfoRepository

public interface IPlayerInfoProvider
{
int LoginAttempts { get; }

string LoggedInAccountName { get; }

string PlayerPassword { get; }
Expand All @@ -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; }
Expand All @@ -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;
Expand Down
19 changes: 16 additions & 3 deletions EndlessClient/Controllers/LoginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace EndlessClient.Controllers
{
[MappedType(BaseType = typeof(ILoginController))]
[AutoMappedType]
public class LoginController : ILoginController
{
private readonly ILoginActions _loginActions;
Expand All @@ -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;
Expand All @@ -66,7 +67,8 @@ public LoginController(ILoginActions loginActions,
INewsProvider newsProvider,
IUserInputTimeRepository userInputTimeRepository,
IClientWindowSizeRepository clientWindowSizeRepository,
IConfigurationProvider configurationProvider)
IConfigurationProvider configurationProvider,
IPlayerInfoRepository playerInfoRepository)
{
_loginActions = loginActions;
_mapFileLoadActions = mapFileLoadActions;
Expand All @@ -86,6 +88,7 @@ public LoginController(ILoginActions loginActions,
_userInputTimeRepository = userInputTimeRepository;
_clientWindowSizeRepository = clientWindowSizeRepository;
_configurationProvider = configurationProvider;
_playerInfoRepository = playerInfoRepository;
}

public async Task LoginToAccount(ILoginParameters loginParameters)
Expand All @@ -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;
}
}
}

Expand Down

0 comments on commit 920c325

Please sign in to comment.