gameServer2/src/server/room.rs
author alfadur
Mon, 18 Jun 2018 09:22:53 -0400
changeset 13416 cdf69667593b
parent 13119 1e39b8749072
child 13419 81e0ed105f5d
permissions -rw-r--r--
partial room implementation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
     1
use server::{
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
     2
    coretypes::TeamInfo,
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
     3
    client::{ClientId, HWClient}
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
     4
};
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
     5
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
     6
pub type RoomId = usize;
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
     7
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
     8
pub struct HWRoom {
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
     9
    pub id: RoomId,
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    10
    pub master_id: Option<ClientId>,
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    11
    pub name: String,
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    12
    pub password: Option<String>,
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    13
    pub protocol_number: u32,
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    14
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    15
    pub players_number: u32,
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    16
    pub ready_players_number: u8,
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    17
    pub teams: Vec<TeamInfo>,
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    18
}
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    19
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    20
impl HWRoom {
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    21
    pub fn new(id: RoomId) -> HWRoom {
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    22
        HWRoom {
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    23
            id,
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    24
            master_id: None,
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    25
            name: String::new(),
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    26
            password: None,
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    27
            protocol_number: 0,
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    28
            players_number: 0,
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    29
            ready_players_number: 0,
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    30
            teams: Vec::new()
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    31
        }
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    32
    }
13416
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    33
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    34
    pub fn info(&self, master: Option<&HWClient>) -> Vec<String> {
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    35
        let flags = "-".to_string();
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    36
        vec![
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    37
            flags,
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    38
            self.name.clone(),
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    39
            self.players_number.to_string(),
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    40
            self.teams.len().to_string(),
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    41
            master.map_or("?", |c| &c.nick).to_string(),
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    42
            "Default".to_string(),
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    43
            "Default".to_string(),
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    44
            "Default".to_string(),
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    45
            "Default".to_string(),
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    46
        ]
cdf69667593b partial room implementation
alfadur
parents: 13119
diff changeset
    47
    }
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents:
diff changeset
    48
}