kubi/kubi-server/src/client.rs

35 lines
890 B
Rust
Raw Normal View History

2023-03-09 02:30:37 +00:00
use shipyard::{Component, EntityId, Unique, Workload, AllStoragesView};
use hashbrown::HashMap;
use nohash_hasher::BuildNoHashHasher;
2023-03-09 02:30:37 +00:00
use std::net::SocketAddr;
2023-03-08 16:27:53 +00:00
use kubi_shared::networking::client::ClientId;
2023-02-11 23:37:24 +00:00
2023-03-09 02:30:37 +00:00
#[derive(Component, Clone, Copy)]
pub struct ClientAddress(pub SocketAddr);
2023-03-09 02:30:37 +00:00
#[derive(Unique)]
pub struct ClientIdMap(pub HashMap<ClientId, EntityId, BuildNoHashHasher<ClientId>>);
impl ClientIdMap {
pub fn new() -> Self {
Self(HashMap::with_hasher(BuildNoHashHasher::default()))
}
}
2023-03-09 02:30:37 +00:00
impl Default for ClientIdMap {
fn default() -> Self {
Self::new()
}
}
2023-03-09 02:30:37 +00: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());
}