gameServer2/src/server/room.rs
author alfadur
Mon, 18 Jun 2018 09:22:53 -0400
changeset 13421 cdf69667593b
parent 13124 1e39b8749072
child 13424 81e0ed105f5d
permissions -rw-r--r--
partial room implementation

use server::{
    coretypes::TeamInfo,
    client::{ClientId, HWClient}
};

pub type RoomId = usize;

pub struct HWRoom {
    pub id: RoomId,
    pub master_id: Option<ClientId>,
    pub name: String,
    pub password: Option<String>,
    pub protocol_number: u32,

    pub players_number: u32,
    pub ready_players_number: u8,
    pub teams: Vec<TeamInfo>,
}

impl HWRoom {
    pub fn new(id: RoomId) -> HWRoom {
        HWRoom {
            id,
            master_id: None,
            name: String::new(),
            password: None,
            protocol_number: 0,
            players_number: 0,
            ready_players_number: 0,
            teams: Vec::new()
        }
    }

    pub fn info(&self, master: Option<&HWClient>) -> Vec<String> {
        let flags = "-".to_string();
        vec![
            flags,
            self.name.clone(),
            self.players_number.to_string(),
            self.teams.len().to_string(),
            master.map_or("?", |c| &c.nick).to_string(),
            "Default".to_string(),
            "Default".to_string(),
            "Default".to_string(),
            "Default".to_string(),
        ]
    }
}