rust/hedgewars-server/src/server/handlers/common.rs
changeset 14796 b889d9e1115f
parent 14795 e94fbf6cad2b
child 14803 d11481978633
equal deleted inserted replaced
14795:e94fbf6cad2b 14796:b889d9e1115f
    37 }
    37 }
    38 
    38 
    39 pub fn join_lobby(server: &mut HWServer, response: &mut Response) {
    39 pub fn join_lobby(server: &mut HWServer, response: &mut Response) {
    40     let client_id = response.client_id();
    40     let client_id = response.client_id();
    41 
    41 
    42     let lobby_nicks: Vec<_> = server.collect_nicks(|(_, c)| c.room_id.is_none());
    42     let client = &server.clients[client_id];
    43 
    43     let nick = vec![client.nick.clone()];
    44     let joined_msg = LobbyJoined(lobby_nicks);
    44     let mut flags = vec![];
    45 
    45     if client.is_registered() {
    46     let everyone_msg = LobbyJoined(vec![server.clients[client_id].nick.clone()]);
    46         flags.push(Flags::Registered)
    47     let flags_msg = ClientFlags(
    47     }
    48         add_flags(&[Flags::InRoom]),
    48     if client.is_admin() {
    49         server.collect_nicks(|(_, c)| c.room_id.is_some()),
    49         flags.push(Flags::Admin)
    50     );
    50     }
       
    51     if client.is_contributor() {
       
    52         flags.push(Flags::Contributor)
       
    53     }
       
    54 
       
    55     let all_nicks: Vec<_> = server.collect_nicks(|_| true);
       
    56 
       
    57     let mut flag_selectors = [
       
    58         (
       
    59             Flags::Registered,
       
    60             server.collect_nicks(|(_, c)| c.is_registered()),
       
    61         ),
       
    62         (Flags::Admin, server.collect_nicks(|(_, c)| c.is_admin())),
       
    63         (
       
    64             Flags::Contributor,
       
    65             server.collect_nicks(|(_, c)| c.is_contributor()),
       
    66         ),
       
    67         (
       
    68             Flags::InRoom,
       
    69             server.collect_nicks(|(_, c)| c.room_id.is_some()),
       
    70         ),
       
    71     ];
       
    72 
    51     let server_msg = ServerMessage(server.get_greetings(client_id).to_string());
    73     let server_msg = ServerMessage(server.get_greetings(client_id).to_string());
    52 
    74 
    53     let rooms_msg = Rooms(
    75     let rooms_msg = Rooms(
    54         server
    76         server
    55             .rooms
    77             .rooms
    56             .iter()
    78             .iter()
    57             .flat_map(|(_, r)| r.info(r.master_id.map(|id| &server.clients[id])))
    79             .flat_map(|(_, r)| r.info(r.master_id.map(|id| &server.clients[id])))
    58             .collect(),
    80             .collect(),
    59     );
    81     );
    60 
    82 
    61     response.add(everyone_msg.send_all().but_self());
    83     response.add(LobbyJoined(nick).send_all().but_self());
    62     response.add(joined_msg.send_self());
    84     response.add(
    63     response.add(flags_msg.send_self());
    85         ClientFlags(add_flags(&flags), all_nicks.clone())
       
    86             .send_all()
       
    87             .but_self(),
       
    88     );
       
    89 
       
    90     response.add(LobbyJoined(all_nicks).send_self());
       
    91     for (flag, nicks) in &mut flag_selectors {
       
    92         response.add(ClientFlags(add_flags(&[*flag]), replace(nicks, vec![])).send_self());
       
    93     }
       
    94 
    64     response.add(server_msg.send_self());
    95     response.add(server_msg.send_self());
    65     response.add(rooms_msg.send_self());
    96     response.add(rooms_msg.send_self());
    66 }
    97 }
    67 
    98 
    68 pub fn remove_teams(
    99 pub fn remove_teams(