rust/hedgewars-server/src/server/handlers/common.rs
changeset 14710 aae29ba56aec
parent 14709 4569d8d50286
child 14711 f61ce544d436
equal deleted inserted replaced
14709:4569d8d50286 14710:aae29ba56aec
   198 ) {
   198 ) {
   199     let update_msg = RoomUpdated(room_name.unwrap_or(room.name.clone()), room.info(master));
   199     let update_msg = RoomUpdated(room_name.unwrap_or(room.name.clone()), room.info(master));
   200     response.add(update_msg.send_all().with_protocol(room.protocol_number));
   200     response.add(update_msg.send_all().with_protocol(room.protocol_number));
   201 }
   201 }
   202 
   202 
       
   203 pub fn get_room_config(room: &HWRoom, to_client: ClientId, response: &mut Response) {
       
   204     response.add(ConfigEntry("FULLMAPCONFIG".to_string(), room.map_config()).send(to_client));
       
   205     for cfg in room.game_config() {
       
   206         response.add(cfg.to_server_msg().send(to_client));
       
   207     }
       
   208 }
       
   209 
       
   210 pub fn get_room_teams(
       
   211     server: &HWServer,
       
   212     room_id: RoomId,
       
   213     to_client: ClientId,
       
   214     response: &mut Response,
       
   215 ) {
       
   216     let room = &server.rooms[room_id];
       
   217     let current_teams = match room.game_info {
       
   218         Some(ref info) => &info.teams_at_start,
       
   219         None => &room.teams,
       
   220     };
       
   221 
       
   222     for (owner_id, team) in current_teams.iter() {
       
   223         response.add(TeamAdd(HWRoom::team_info(&server.clients[*owner_id], &team)).send(to_client));
       
   224         response.add(TeamColor(team.name.clone(), team.color).send(to_client));
       
   225         response.add(HedgehogsNumber(team.name.clone(), team.hedgehogs_number).send(to_client));
       
   226     }
       
   227 }
       
   228 
       
   229 pub fn get_room_flags(
       
   230     server: &HWServer,
       
   231     room_id: RoomId,
       
   232     to_client: ClientId,
       
   233     response: &mut Response,
       
   234 ) {
       
   235     let room = &server.rooms[room_id];
       
   236     if let Some(id) = room.master_id {
       
   237         response.add(
       
   238             ClientFlags("+h".to_string(), vec![server.clients[id].nick.clone()]).send(to_client),
       
   239         );
       
   240     }
       
   241     let nicks: Vec<_> = server
       
   242         .clients
       
   243         .iter()
       
   244         .filter(|(_, c)| c.room_id == Some(room_id) && c.is_ready())
       
   245         .map(|(_, c)| c.nick.clone())
       
   246         .collect();
       
   247     if !nicks.is_empty() {
       
   248         response.add(ClientFlags("+r".to_string(), nicks).send(to_client));
       
   249     }
       
   250 }
       
   251 
   203 pub fn apply_voting_result(
   252 pub fn apply_voting_result(
   204     server: &mut HWServer,
   253     server: &mut HWServer,
   205     room_id: RoomId,
   254     room_id: RoomId,
   206     response: &mut Response,
   255     response: &mut Response,
   207     kind: VoteType,
   256     kind: VoteType,
   237                 } else {
   286                 } else {
   238                     None
   287                     None
   239                 };
   288                 };
   240                 get_room_update(None, room, room_master, response);
   289                 get_room_update(None, room, room_master, response);
   241 
   290 
   242                 for (_, c) in server.clients.iter() {
   291                 for (_, client) in server.clients.iter() {
   243                     if c.room_id == Some(room_id) {
   292                     if client.room_id == Some(room_id) {
   244                         /*SendRoomData {
   293                         super::common::get_room_config(&server.rooms[room_id], client.id, response);
   245                             to: c.id,
       
   246                             teams: false,
       
   247                             config: true,
       
   248                             flags: false,
       
   249                         }*/
       
   250                     }
   294                     }
   251                 }
   295                 }
   252             }
   296             }
   253         }
   297         }
   254         VoteType::Pause => {
   298         VoteType::Pause => {
   385     response.add(RoundFinished.send_all().in_room(room_id));
   429     response.add(RoundFinished.send_all().in_room(room_id));
   386 
   430 
   387     if let Some(info) = replace(&mut room.game_info, None) {
   431     if let Some(info) = replace(&mut room.game_info, None) {
   388         for (_, client) in server.clients.iter() {
   432         for (_, client) in server.clients.iter() {
   389             if client.room_id == Some(room_id) && client.is_joined_mid_game() {
   433             if client.room_id == Some(room_id) && client.is_joined_mid_game() {
   390                 //SendRoomData { to: client.id, teams: false, config: true, flags: false}
   434                 super::common::get_room_config(room, client.id, response);
   391 
       
   392                 response.extend(
   435                 response.extend(
   393                     info.left_teams
   436                     info.left_teams
   394                         .iter()
   437                         .iter()
   395                         .map(|name| TeamRemove(name.clone()).send(client.id)),
   438                         .map(|name| TeamRemove(name.clone()).send(client.id)),
   396                 );
   439                 );