/// <inheritdoc/> /// <summary> /// Initializes a new instance of the <see cref="AuthClient"/> class and binds it with a network session. /// </summary> /// <param name="authenticator">The <see cref="IAuthenticator"/> to use for authenticating the user.</param> /// <param name="nexus">The <see cref="IAuthToNexusRequestHandler"/> to query for... world stuff.</param> /// <param name="serverSession"><inheritdoc/></param> /// <param name="packetFactory"><inheritdoc/></param> /// <param name="logger"><inheritdoc/></param> public AuthClient(IAuthenticator authenticator, IAuthToNexusRequestHandler nexus, IServerSession serverSession, IPacketFactory packetFactory, ILogger logger) : base(serverSession, packetFactory, logger) { _authenticator = authenticator; _nexus = nexus; LoginAttempts = 0; State = AuthClientState.NotLoggedIn; }
private void HandleAuthentication(IUnsafePacketReader reader) { if (State != AuthClientState.NotLoggedIn) { Disconnect("Invalid client authentication state."); return; } // TODO: more stuff to read, later. IAccountSession accountSession; Account account; var result = _authenticator.Authenticate(reader, out accountSession, out account); if (result == AuthenticationResult.Success) { AccountSession = accountSession; Account = account; if (!account.Gender.HasValue) { State = AuthClientState.SetGender; } else { // TODO: cover cases where further authentication is not required and this should be set to LoggedIn. if (account.AccountPin == null) { State = AuthClientState.SetPin; } else { State = AuthClientState.AskPin; } } } else if (LoginAttempts++ > MaxLoginAttempts) { Disconnect("Too many login attempts."); return; } ServerSession.WritePacket(AuthResponse(result, account)); ServerSession.WritePacket(CheckPinResponse()); }
private void HandlePinValidation(IUnsafePacketReader reader) { // TODO: Configuring the server to not require PINs. var action = reader.ReadByte <PinRequestType>(); reader.Skip(5); switch (action) { case PinRequestType.PinNotSet: State = AuthClientState.AskPin; ServerSession.WritePacket(SetPinResponse()); break; case PinRequestType.CheckPin: if (CheckPin(reader)) { State = AuthClientState.LoggedIn; ServerSession.WritePacket(PinAcceptedResponse()); } else { ServerSession.WritePacket(InvalidPinResponse()); } break; case PinRequestType.AssignPin: if (CheckPin(reader)) { State = AuthClientState.LoggedIn; ServerSession.WritePacket(SetPinResponse()); } else { ServerSession.WritePacket(InvalidPinResponse()); } break; } }
private void HandlePinValidation(IUnsafePacketReader reader) { // TODO: Configuring the server to not require PINs. var action = reader.ReadByte<PinRequestType>(); reader.Skip(5); switch (action) { case PinRequestType.PinNotSet: this.State = AuthClientState.AskPin; this.ServerSession.WritePacket(this.SetPinResponse()); break; case PinRequestType.CheckPin: if (this.CheckPin(reader)) { this.State = AuthClientState.LoggedIn; this.ServerSession.WritePacket(this.PinAcceptedResponse()); } else { this.ServerSession.WritePacket(this.InvalidPinResponse()); } break; case PinRequestType.AssignPin: if (this.CheckPin(reader)) { this.State = AuthClientState.LoggedIn; this.ServerSession.WritePacket(this.SetPinResponse()); } else { this.ServerSession.WritePacket(this.InvalidPinResponse()); } break; } }
private void HandleAuthentication(IUnsafePacketReader reader) { if (this.State != AuthClientState.NotLoggedIn) { this.Disconnect("Invalid client authentication state."); return; } // TODO: more stuff to read, later. IAccountSession accountSession; Account account; var result = this.authenticator.Authenticate(reader, out accountSession, out account); if (result == AuthenticationResult.Success) { this.AccountSession = accountSession; this.Account = account; if (!account.Gender.HasValue) { this.State = AuthClientState.SetGender; } else { // TODO: cover cases where further authentication is not required and this should be set to LoggedIn. if (account.AccountPin == null) { this.State = AuthClientState.SetPin; } else { this.State = AuthClientState.AskPin; } } } else if (this.LoginAttempts++ > MaxLoginAttempts) { this.Disconnect("Too many login attempts."); return; } this.ServerSession.WritePacket(this.AuthResponse(result, account)); this.ServerSession.WritePacket(this.CheckPinResponse()); }