diff -r f091f69d59e4 -r 6f6a866c86a2 gameServer2/src/server/room.rs --- a/gameServer2/src/server/room.rs Wed Jun 27 17:58:33 2018 +0300 +++ b/gameServer2/src/server/room.rs Wed Jun 27 23:26:29 2018 +0300 @@ -7,16 +7,19 @@ const MAX_HEDGEHOGS_IN_ROOM: u8 = 48; pub type RoomId = usize; +#[derive(Clone)] struct Ammo { name: String, settings: Option } +#[derive(Clone)] struct Scheme { name: String, settings: Option> } +#[derive(Clone)] struct RoomConfig { feature_size: u32, map_type: String, @@ -51,18 +54,57 @@ } } +fn client_teams_impl(teams: &Vec<(ClientId, TeamInfo)>, client_id: ClientId) + -> impl Iterator + Clone +{ + teams.iter().filter(move |(id, _)| *id == client_id).map(|(_, t)| t) +} + +fn map_config_from(c: &RoomConfig) -> Vec { + vec![c.feature_size.to_string(), c.map_type.to_string(), + c.map_generator.to_string(), c.maze_size.to_string(), + c.seed.to_string(), c.template.to_string()] +} + +fn game_config_from(c: &RoomConfig) -> Vec { + use server::coretypes::GameCfg::*; + let mut v = vec![ + Ammo(c.ammo.name.to_string(), c.ammo.settings.clone()), + Scheme(c.scheme.name.to_string(), c.scheme.settings.clone()), + Script(c.script.to_string()), + Theme(c.theme.to_string())]; + if let Some(ref m) = c.drawn_map { + v.push(DrawnMap(m.to_string())) + } + v +} + pub struct GameInfo { pub teams_in_game: u8, - pub left_teams: Vec + pub teams_at_start: Vec<(ClientId, TeamInfo)>, + pub left_teams: Vec, + pub msg_log: String, + pub last_msg: Option, + pub is_paused: bool, + config: RoomConfig } impl GameInfo { - pub fn new(teams_number: u8) -> GameInfo { + fn new(teams: Vec<(ClientId, TeamInfo)>, config: RoomConfig) -> GameInfo { GameInfo { - teams_in_game: teams_number, - left_teams: Vec::new() + left_teams: Vec::new(), + msg_log: String::new(), + last_msg: None, + is_paused: false, + teams_in_game: teams.len() as u8, + teams_at_start: teams, + config } } + + pub fn client_teams(&self, client_id: ClientId) -> impl Iterator + Clone { + client_teams_impl(&self.teams_at_start, client_id) + } } pub struct HWRoom { @@ -138,7 +180,7 @@ } pub fn client_teams(&self, client_id: ClientId) -> impl Iterator { - self.teams.iter().filter(move |(id, _)| *id == client_id).map(|(_, t)| t) + client_teams_impl(&self.teams, client_id) } pub fn client_team_indices(&self, client_id: ClientId) -> Vec { @@ -179,6 +221,13 @@ }; } + pub fn start_round(&mut self) { + if self.game_info.is_none() { + self.game_info = Some(GameInfo::new( + self.teams.clone(), self.config.clone())); + } + } + pub fn info(&self, master: Option<&HWClient>) -> Vec { let flags = "-".to_string(); let c = &self.config; @@ -196,24 +245,17 @@ } pub fn map_config(&self) -> Vec { - let c = &self.config; - vec![c.feature_size.to_string(), c.map_type.to_string(), - c.map_generator.to_string(), c.maze_size.to_string(), - c.seed.to_string(), c.template.to_string()] + match self.game_info { + Some(ref info) => map_config_from(&info.config), + None => map_config_from(&self.config) + } } pub fn game_config(&self) -> Vec { - use server::coretypes::GameCfg::*; - let c = &self.config; - let mut v = vec![ - Ammo(c.ammo.name.to_string(), c.ammo.settings.clone()), - Scheme(c.scheme.name.to_string(), c.scheme.settings.clone()), - Script(c.script.to_string()), - Theme(c.theme.to_string())]; - if let Some(ref m) = c.drawn_map { - v.push(DrawnMap(m.to_string())) + match self.game_info { + Some(ref info) => game_config_from(&info.config), + None => game_config_from(&self.config) } - v } pub fn team_info(owner: &HWClient, team: &TeamInfo) -> Vec {