wip updating of server status

This commit is contained in:
Luuk van Oijen
2023-11-20 10:55:31 +01:00
parent 7598261aff
commit 0e75a35c83
3 changed files with 40 additions and 18 deletions

View File

@@ -71,19 +71,11 @@ fn load_plugins() -> Vec<Plugin> {
plugins
}
#[derive(PartialEq, IntoPrimitive, Copy, Clone, Debug)]
#[repr(u8)]
enum ServerState {
Unknown = 0,
WaitingForClients,
WaitingForReady,
WaitingForSpawns,
Qualifying,
LiningUp,
Countdown,
Race,
Finish,
#[derive(PartialEq, Clone, Debug)]
pub struct ServerStatus {
pub player_count: usize,
pub player_list: String,
pub max_players: usize,
}
pub struct Server {
@@ -338,6 +330,17 @@ impl Server {
Ok(())
}
pub fn get_server_status(&self) -> ServerStatus {
ServerStatus {
player_count: self.clients.len(),
player_list: self.clients.iter().map(|client| {
format!("{};", &client.get_name())
}).collect(),
// max_players: self.max_players, // TODO: Support this
max_players: self.config.general.max_players,
}
}
async fn process_udp(&mut self) -> anyhow::Result<()> {
// Process UDP packets
// TODO: Use a UDP addr -> client ID look up table