pub async fn authenticate(conn: &mut Connection, pg: PgPool) -> Result<Option<Player>> {
    let name = match get_name(conn).await {
        Ok(name) => name,
        Err(e) => return Err(e),
    };

    let exists = name_exists(&name, &pg).await?;

    if exists {
        let password = get_password(conn).await?;
        let partial_player = login(&name, &password, &pg).await;

        match partial_player {
            Ok(player) => Ok(Some(player)),
            Err(_) => {
                conn.send_message("Invalid credentials.").await?;

                Ok(None)
            }
        }
    } else {
        let password = set_password(conn).await?;
        let partial_player = create(&name, &password, &password, None, &pg).await?;

        let welcome_msg = format!(
            "\nWelcome, {}! You can view all the commands by typing \"help\" or \"?\".",
            &name
        )
        .bold()
        .foreground(YELLOW);

        conn.send_message(welcome_msg.to_string().as_str()).await?;
        Ok(Some(Player {
            _entityid: EntityId::empty(),
            id: partial_player.id,
            account: partial_player.account,
            name,
            position: Vec3::new(0, 0, 0),
            health: 100,
            max_health: 100,
            mana: 100,
            max_mana: 100,
            xp: 0,
            xp_to_level: 100,
            level: 1,
            brief: false,
            afk: false,
            dirty: false,
        }))
    }
}
/// This starts an authentication process for a player. It will handle input, finding if a player
/// name exists, password authentication, new account creation flow, and login. It will always
/// return a player if it succeeds.
///
/// This function will return additionally returns a special flag, `restart`, which will restart the
/// authentication process if the player. We need to do this because some responses should drop the
/// connection instead.
This starts an authentication process for a player. It will handle input, finding if a player
name exists, password authentication, new account creation flow, and login. It will always
return a player if it succeeds.

This function will return additionally returns a special flag, `restart`, which will restart the
authentication process if the player. We need to do this because some responses should drop the
connection instead.
This starts an authentication process for a player . It will handle input finding if a player name exists password authentication new account creation flow and login . It will always return a player if it succeeds . This function will return additionally returns a special flag ` restart ` which will restart the authentication process if the player . We need to do this because some responses should drop the connection instead .
pub async fn authenticate(conn: &mut Connection, pg: PgPool) -> Result<Option<Player>> {
    let name = match get_name(conn).await {
        Ok(name) => name,
        Err(e) => return Err(e),
    };
    let exists = name_exists(&name, &pg).await?;
    if exists {
        let password = get_password(conn).await?;
        let partial_player = login(&name, &password, &pg).await;
        match partial_player {
            Ok(player) => Ok(Some(player)),
            Err(_) => {
                conn.send_message("Invalid credentials.").await?;
                Ok(None)
            }
        }
    } else {
        let password = set_password(conn).await?;
        let partial_player = create(&name, &password, &password, None, &pg).await?;
        let welcome_msg = format!(
            "\nWelcome, {}! You can view all the commands by typing \"help\" or \"?\".",
            &name
        )
        .bold()
        .foreground(YELLOW);
        conn.send_message(welcome_msg.to_string().as_str()).await?;
        Ok(Some(Player {
            _entityid: EntityId::empty(),
            id: partial_player.id,
            account: partial_player.account,
            name,
            position: Vec3::new(0, 0, 0),
            health: 100,
            max_health: 100,
            mana: 100,
            max_mana: 100,
            xp: 0,
            xp_to_level: 100,
            level: 1,
            brief: false,
            afk: false,
            dirty: false,
        }))
    }
}
pub async fn authenticate ( conn : & mut Connection , pg : PgPool ) -> Result < Option < Player > > { let name = match get_name ( conn ) . await { Ok ( name ) => name , Err ( e ) => return Err ( e ) , } ; let exists = name_exists ( & name , & pg ) . await ? ; if exists { let password = get_password ( conn ) . await ? ; let partial_player = login ( & name , & password , & pg ) . await ; match partial_player { Ok ( player ) => Ok ( Some ( player ) ) , Err ( _ ) => { conn . send_message ( " " ) . await ? ; Ok ( None ) } } } else { let password = set_password ( conn ) . await ? ; let partial_player = create ( & name , & password , & password , None , & pg ) . await ? ; let welcome_msg = format ! ( " \n \" \" \" \" " name ) . bold ( ) . foreground ( YELLOW ) ; conn . send_message ( welcome_msg . to_string ( ) . as_str ( ) ) . await ? ; Ok ( Some ( Player { _entityid : EntityId :: empty ( ) , id : partial_player . id , account : partial_player . account , name , position : Vec3 :: new ( 0 , 0 , 0 ) , health : 100 , max_health : 100 , mana : 100 , max_mana : 100 , xp : 0 , xp_to_level : 100 , level : 1 , brief : false , afk : false , dirty : false , } ) ) } }
This starts an authentication process for a player.
This starts an authentication process for a player .
conn
&mut Connection
pg
PgPool
conn
&mut Connection
pg
PgPool