rust/hedgewars-server/src/core/server.rs
changeset 15563 d122b65bdf6f
parent 15562 479911540e17
child 15573 7478568cffbe
equal deleted inserted replaced
15562:479911540e17 15563:d122b65bdf6f
   984                 .client_teams(client.id)
   984                 .client_teams(client.id)
   985                 .map(|t| t.name.clone())
   985                 .map(|t| t.name.clone())
   986                 .collect();
   986                 .collect();
   987 
   987 
   988             if let Some(ref mut info) = room.game_info {
   988             if let Some(ref mut info) = room.game_info {
   989                 info.teams_in_game -= team_names.len() as u8;
       
   990 
       
   991                 for team_name in &team_names {
   989                 for team_name in &team_names {
   992                     let remove_msg =
   990                     let remove_msg =
   993                         utils::to_engine_msg(std::iter::once(b'F').chain(team_name.bytes()));
   991                         utils::to_engine_msg(std::iter::once(b'F').chain(team_name.bytes()));
   994                     if let Some(m) = &info.sync_msg {
   992                     if let Some(m) = &info.sync_msg {
   995                         info.msg_log.push(m.clone());
   993                         info.msg_log.push(m.clone());
  1010 
  1008 
  1011     pub fn end_game(&mut self) -> Option<EndGameResult> {
  1009     pub fn end_game(&mut self) -> Option<EndGameResult> {
  1012         let room = self.room_mut();
  1010         let room = self.room_mut();
  1013         room.ready_players_number = room.master_id.is_some() as u8;
  1011         room.ready_players_number = room.master_id.is_some() as u8;
  1014 
  1012 
  1015         if let Some(info) = replace(&mut room.game_info, None) {
  1013         if let Some(mut info) = replace(&mut room.game_info, None) {
  1016             let room_id = room.id;
  1014             let room_id = room.id;
       
  1015             for team_name in &info.left_teams {
       
  1016                 room.remove_team(team_name);
       
  1017             }
       
  1018 
  1017             let joined_mid_game_clients = self
  1019             let joined_mid_game_clients = self
  1018                 .server
  1020                 .server
  1019                 .clients
  1021                 .clients
  1020                 .iter()
  1022                 .iter()
  1021                 .filter(|(_, c)| c.room_id == Some(self.room_id) && c.is_joined_mid_game())
  1023                 .filter(|(_, c)| c.room_id == Some(self.room_id) && c.is_joined_mid_game())
  1041                 })
  1043                 })
  1042                 .collect();
  1044                 .collect();
  1043 
  1045 
  1044             Some(EndGameResult {
  1046             Some(EndGameResult {
  1045                 joined_mid_game_clients,
  1047                 joined_mid_game_clients,
  1046                 left_teams: info.left_teams.clone(),
  1048                 left_teams: replace(&mut info.left_teams, vec![]),
  1047                 unreadied_nicks,
  1049                 unreadied_nicks,
  1048             })
  1050             })
  1049         } else {
  1051         } else {
  1050             None
  1052             None
  1051         }
  1053         }
  1112         client.clan = teams.clone().next().map(|t| t.color);
  1114         client.clan = teams.clone().next().map(|t| t.color);
  1113         let team_names: Vec<_> = teams.map(|t| t.name.clone()).collect();
  1115         let team_names: Vec<_> = teams.map(|t| t.name.clone()).collect();
  1114 
  1116 
  1115         if !team_names.is_empty() {
  1117         if !team_names.is_empty() {
  1116             info.left_teams.retain(|name| !team_names.contains(&name));
  1118             info.left_teams.retain(|name| !team_names.contains(&name));
  1117             info.teams_in_game += team_names.len() as u8;
  1119         }
  1118             room.teams = info
  1120     }
  1119                 .teams_at_start
  1121 }
  1120                 .iter()
       
  1121                 .filter(|(_, t)| !team_names.contains(&t.name))
       
  1122                 .cloned()
       
  1123                 .collect();
       
  1124         }
       
  1125     }
       
  1126 }