veloren/server/src/client.rs

41 lines
871 B
Rust
Raw Normal View History

use specs::Entity as EcsEntity;
use common::{
msg::{ServerMsg, ClientMsg},
net::PostBox,
};
use crate::Error;
pub struct Client {
pub ecs_entity: EcsEntity,
pub postbox: PostBox<ServerMsg, ClientMsg>,
pub last_ping: f64,
}
pub struct Clients {
clients: Vec<Client>,
}
impl Clients {
pub fn empty() -> Self {
Self {
clients: Vec::new(),
}
}
pub fn add(&mut self, client: Client) {
self.clients.push(client);
}
pub fn remove_if<F: FnMut(&mut Client) -> bool>(&mut self, f: F) {
self.clients.drain_filter(f);
}
pub fn notify_all(&mut self, msg: ServerMsg) {
for client in &mut self.clients {
// Consume any errors, deal with them later
let _ = client.postbox.send(msg.clone());
println!("Sending message...");
}
}
}