public void ProcessAuthentication(Connection connection, LCAuthentication authentication) { //Check the salt if (!validateSalt(authentication.Salt)) { //Probably a custom made connection, drop it and quit authentication connection.Socket.Disconnect(false); Console.WriteLine(authentication.Username + " failed authentication with reason: WRONG SALT"); return; } //Prepare the response LCAuthenticationResponse response = new LCAuthenticationResponse(); //Check the username if (!checkUsername(authentication.Username)) { //Username is not existing in the database, send this result to the user and quit authentication response.Result = AuthenticationResult.BAD_USERNAME; connection.Send(response); Console.WriteLine(authentication.Username + " failed authentication with reason: BAD USERNAME"); return; } //Check the username with the password if (!checkPassword(authentication.Username, authentication.Password)) { //Password is not correct for this username, send this result to the user and quit authentication response.Result = AuthenticationResult.BAD_PASSWORD; connection.Send(response); Console.WriteLine(authentication.Username + " failed authentication with reason: BAD PASSWORD"); return; } //Authentication succeeded response.Result = AuthenticationResult.SUCCESS; connection.Send(response); Console.WriteLine(authentication.Username + " successfully authenticated"); //Send state switch LCStateSwitch stateSwitch = new LCStateSwitch { GameState = GameState.CHARACTER_SELECTION }; connection.Send(stateSwitch); Console.WriteLine("Sent game state switch to " + stateSwitch.GameState + " - User: "******"Sent character list"); }
private void TCPClient_PacketReceived(object sender, PacketReceivedArgs e) { IPacket packet = e.Packet; if (packet is LCStateSwitch) { LCStateSwitch state = (LCStateSwitch)packet; switch (state.GameState) { case GameState.LOGIN: SwitchScene(typeof(LoginScene)); break; case GameState.CHARACTER_SELECTION: SwitchScene(typeof(CharacterSelectionScene)); break; default: throw new ArgumentOutOfRangeException(); } } }