gameServer2/src/server/room.rs
changeset 13423 87a6cad20c90
parent 13422 5fb27f94fc3b
child 13426 f091f69d59e4
equal deleted inserted replaced
13422:5fb27f94fc3b 13423:87a6cad20c90
    49             drawn_map: None
    49             drawn_map: None
    50         }
    50         }
    51     }
    51     }
    52 }
    52 }
    53 
    53 
       
    54 pub struct GameInfo {
       
    55     pub teams_in_game: u8
       
    56 }
       
    57 
    54 pub struct HWRoom {
    58 pub struct HWRoom {
    55     pub id: RoomId,
    59     pub id: RoomId,
    56     pub master_id: Option<ClientId>,
    60     pub master_id: Option<ClientId>,
    57     pub name: String,
    61     pub name: String,
    58     pub password: Option<String>,
    62     pub password: Option<String>,
    62     pub default_hedgehog_number: u8,
    66     pub default_hedgehog_number: u8,
    63     pub team_limit: u8,
    67     pub team_limit: u8,
    64     pub ready_players_number: u8,
    68     pub ready_players_number: u8,
    65     pub teams: Vec<(ClientId, TeamInfo)>,
    69     pub teams: Vec<(ClientId, TeamInfo)>,
    66     config: RoomConfig,
    70     config: RoomConfig,
    67     pub game_info: Option<()>
    71     pub game_info: Option<GameInfo>
    68 }
    72 }
    69 
    73 
    70 impl HWRoom {
    74 impl HWRoom {
    71     pub fn new(id: RoomId) -> HWRoom {
    75     pub fn new(id: RoomId) -> HWRoom {
    72         HWRoom {
    76         HWRoom {
   125 
   129 
   126     pub fn client_teams(&self, client_id: ClientId) -> impl Iterator<Item = &TeamInfo> {
   130     pub fn client_teams(&self, client_id: ClientId) -> impl Iterator<Item = &TeamInfo> {
   127         self.teams.iter().filter(move |(id, _)| *id == client_id).map(|(_, t)| t)
   131         self.teams.iter().filter(move |(id, _)| *id == client_id).map(|(_, t)| t)
   128     }
   132     }
   129 
   133 
       
   134     pub fn client_team_indices(&self, client_id: ClientId) -> Vec<u8> {
       
   135         self.teams.iter().enumerate()
       
   136             .filter(move |(_, (id, _))| *id == client_id)
       
   137             .map(|(i, _)| i as u8).collect()
       
   138     }
       
   139 
   130     pub fn find_team_owner(&self, team_name: &str) -> Option<(ClientId, &str)> {
   140     pub fn find_team_owner(&self, team_name: &str) -> Option<(ClientId, &str)> {
   131         self.teams.iter().find(|(_, t)| t.name == team_name)
   141         self.teams.iter().find(|(_, t)| t.name == team_name)
   132             .map(|(id, t)| (*id, &t.name[..]))
   142             .map(|(id, t)| (*id, &t.name[..]))
   133     }
   143     }
   134 
   144 
   135     pub fn find_team_color(&self, owner_id: ClientId) -> Option<u8> {
   145     pub fn find_team_color(&self, owner_id: ClientId) -> Option<u8> {
   136         self.client_teams(owner_id).nth(0).map(|t| t.color)
   146         self.client_teams(owner_id).nth(0).map(|t| t.color)
       
   147     }
       
   148 
       
   149     pub fn has_multiple_clans(&self) -> bool {
       
   150         self.teams.iter().min_by_key(|(_, t)| t.color) !=
       
   151             self.teams.iter().max_by_key(|(_, t)| t.color)
   137     }
   152     }
   138 
   153 
   139     pub fn set_config(&mut self, cfg: GameCfg) {
   154     pub fn set_config(&mut self, cfg: GameCfg) {
   140         let c = &mut self.config;
   155         let c = &mut self.config;
   141         match cfg {
   156         match cfg {