2023-03-12 19:56:33 -05:00
|
|
|
use shipyard::{Component, EntityId, Unique, AllStoragesView};
|
2023-02-11 18:32:59 -06:00
|
|
|
use hashbrown::HashMap;
|
|
|
|
use nohash_hasher::BuildNoHashHasher;
|
2023-03-08 20:30:37 -06:00
|
|
|
use std::net::SocketAddr;
|
2023-03-08 10:27:53 -06:00
|
|
|
use kubi_shared::networking::client::ClientId;
|
2023-02-11 17:37:24 -06:00
|
|
|
|
2023-03-08 20:30:37 -06:00
|
|
|
#[derive(Component, Clone, Copy)]
|
|
|
|
pub struct ClientAddress(pub SocketAddr);
|
2023-02-11 18:32:59 -06:00
|
|
|
|
2023-03-08 20:30:37 -06:00
|
|
|
#[derive(Unique)]
|
|
|
|
pub struct ClientIdMap(pub HashMap<ClientId, EntityId, BuildNoHashHasher<ClientId>>);
|
|
|
|
impl ClientIdMap {
|
2023-02-11 18:32:59 -06:00
|
|
|
pub fn new() -> Self {
|
|
|
|
Self(HashMap::with_hasher(BuildNoHashHasher::default()))
|
|
|
|
}
|
|
|
|
}
|
2023-03-08 20:30:37 -06:00
|
|
|
impl Default for ClientIdMap {
|
2023-02-11 18:32:59 -06:00
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
2023-03-08 20:30:37 -06:00
|
|
|
|
|
|
|
#[derive(Unique, Default)]
|
|
|
|
pub struct ClientAddressMap(pub HashMap<SocketAddr, EntityId>);
|
|
|
|
impl ClientAddressMap {
|
|
|
|
pub fn new() -> Self { Self::default() }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn init_client_maps(
|
|
|
|
storages: AllStoragesView
|
|
|
|
) {
|
|
|
|
storages.add_unique(ClientIdMap::new());
|
|
|
|
storages.add_unique(ClientAddressMap::new());
|
|
|
|
}
|