gameServer2/src/server/room.rs
changeset 13527 e3ae9eea0689
parent 13525 d126d9a646ac
child 13528 c8b626b0a3ad
equal deleted inserted replaced
13526:3f69acc7e268 13527:e3ae9eea0689
     1 use std::{iter};
     1 use std::{
       
     2     iter, collections::HashMap
       
     3 };
     2 use server::{
     4 use server::{
     3     coretypes::{ClientId, RoomId, TeamInfo, GameCfg, GameCfg::*, Voting},
     5     coretypes::{ClientId, RoomId, TeamInfo, GameCfg, GameCfg::*, Voting},
     4     client::{HWClient}
     6     client::{HWClient}
     5 };
     7 };
     6 
     8 
   105     pub fn client_teams(&self, client_id: ClientId) -> impl Iterator<Item = &TeamInfo> + Clone {
   107     pub fn client_teams(&self, client_id: ClientId) -> impl Iterator<Item = &TeamInfo> + Clone {
   106         client_teams_impl(&self.teams_at_start, client_id)
   108         client_teams_impl(&self.teams_at_start, client_id)
   107     }
   109     }
   108 }
   110 }
   109 
   111 
       
   112 pub struct RoomSave {
       
   113     pub location: String,
       
   114     config: RoomConfig
       
   115 }
       
   116 
   110 bitflags!{
   117 bitflags!{
   111     pub struct RoomFlags: u8 {
   118     pub struct RoomFlags: u8 {
   112         const FIXED = 0b0000_0001;
   119         const FIXED = 0b0000_0001;
   113         const RESTRICTED_JOIN = 0b0000_0010;
   120         const RESTRICTED_JOIN = 0b0000_0010;
   114         const RESTRICTED_TEAM_ADD = 0b0000_0100;
   121         const RESTRICTED_TEAM_ADD = 0b0000_0100;
   130     pub team_limit: u8,
   137     pub team_limit: u8,
   131     pub ready_players_number: u8,
   138     pub ready_players_number: u8,
   132     pub teams: Vec<(ClientId, TeamInfo)>,
   139     pub teams: Vec<(ClientId, TeamInfo)>,
   133     config: RoomConfig,
   140     config: RoomConfig,
   134     pub voting: Option<Voting>,
   141     pub voting: Option<Voting>,
       
   142     pub saves: HashMap<String, RoomSave>,
   135     pub game_info: Option<GameInfo>
   143     pub game_info: Option<GameInfo>
   136 }
   144 }
   137 
   145 
   138 impl HWRoom {
   146 impl HWRoom {
   139     pub fn new(id: RoomId) -> HWRoom {
   147     pub fn new(id: RoomId) -> HWRoom {
   150             team_limit: MAX_TEAMS_IN_ROOM,
   158             team_limit: MAX_TEAMS_IN_ROOM,
   151             ready_players_number: 0,
   159             ready_players_number: 0,
   152             teams: Vec::new(),
   160             teams: Vec::new(),
   153             config: RoomConfig::new(),
   161             config: RoomConfig::new(),
   154             voting: None,
   162             voting: None,
       
   163             saves: HashMap::new(),
   155             game_info: None
   164             game_info: None
   156         }
   165         }
   157     }
   166     }
   158 
   167 
   159     pub fn hedgehogs_number(&self) -> u8 {
   168     pub fn hedgehogs_number(&self) -> u8 {
   324             Some(ref info) => game_config_from(&info.config),
   333             Some(ref info) => game_config_from(&info.config),
   325             None => game_config_from(&self.config)
   334             None => game_config_from(&self.config)
   326         }
   335         }
   327     }
   336     }
   328 
   337 
       
   338     pub fn load_config(&mut self, name: &str) -> Option<&str> {
       
   339         if let Some(save) = self.saves.get(name) {
       
   340             self.config = save.config.clone();
       
   341             Some(&save.location[..])
       
   342         } else {
       
   343             None
       
   344         }
       
   345     }
       
   346 
   329     pub fn team_info(owner: &HWClient, team: &TeamInfo) -> Vec<String> {
   347     pub fn team_info(owner: &HWClient, team: &TeamInfo) -> Vec<String> {
   330         let mut info = vec![
   348         let mut info = vec![
   331             team.name.clone(),
   349             team.name.clone(),
   332             team.grave.clone(),
   350             team.grave.clone(),
   333             team.fort.clone(),
   351             team.fort.clone(),