async fn handle_client_disconnect(
    client: &session_types::Client,
    sessions: &data_types::SafeSessions,
    game_states: &data_types::SafeGameStates,
) {
    println!("[event] {} disconnected", client.id);
    if let Some(session_id) = &client.session_id {
        let mut session_empty = false;
        // remove the client from the session and check if the session become empty
        if let Some(session) = sessions.write().await.get_mut(session_id) {
            session.set_client_active_status(&client.id, false);
            session_empty = session.get_clients_with_active_status(true).is_empty();
        }
        // remove the session if empty
        if session_empty {
            cleanup_session(session_id, sessions, game_states).await;
        }
    }
}
/// If a client exists in a session, then set their status to inactive.
///
/// If setting inactive status would leave no other active member, remove the session

If a client exists in a session, then set their status to inactive.
If setting inactive status would leave no other active member, remove the session
If a client exists in a session then set their status to inactive . If setting inactive status would leave no other active member remove the session
async fn handle_client_disconnect(
    client: &session_types::Client,
    sessions: &data_types::SafeSessions,
    game_states: &data_types::SafeGameStates,
) {
    println!("[event] {} disconnected", client.id);
    if let Some(session_id) = &client.session_id {
        let mut session_empty = false;
        // remove the client from the session and check if the session become empty
        if let Some(session) = sessions.write().await.get_mut(session_id) {
            session.set_client_active_status(&client.id, false);
            session_empty = session.get_clients_with_active_status(true).is_empty();
        }
        // remove the session if empty
        if session_empty {
            cleanup_session(session_id, sessions, game_states).await;
        }
    }
}
async fn handle_client_disconnect ( client : & session_types :: Client , sessions : & data_types :: SafeSessions , game_states : & data_types :: SafeGameStates , ) { println ! ( " " client id ) ; if let Some ( session_id ) = & client . session_id { let mut session_empty = false ; // remove the client from the session and check if the session become empty
 if let Some ( session ) = sessions . write ( ) . await . get_mut ( session_id ) { session . set_client_active_status ( & client . id , false ) ; session_empty = session . get_clients_with_active_status ( true ) . is_empty ( ) ; } // remove the session if empty
 if session_empty { cleanup_session ( session_id , sessions , game_states ) . await ; } } }
If a client exists in a session, then set their status to inactive.
If a client exists in a session then set their status to inactive .
client
&session_types::Client
sessions
&data_types::SafeSessions
game_states
&data_types::SafeGameStates
client
&session_types::Client
sessions
&data_types::SafeSessions
game_states
&data_types::SafeGameStates