use dashmap::DashMap;

pub struct PlayerMgr {
    player_map: DashMap<u32, u32>, // uid-session_id
}

impl PlayerMgr {
    pub fn new() -> Self {
        Self {
            player_map: DashMap::new(),
        }
    }

    pub fn add_to_online_map(&self, uid: u32, session_id: u32) {
        self.player_map.insert(uid, session_id);
    }

    pub fn remove_from_online_map(&self, uid: u32) {
        self.player_map.remove(&uid);
    }

    pub fn find_online_player(&self, uid: u32) -> Option<u32> {
        self.player_map.get(&uid).map(|a| a.clone())
    }
}
