diff -r 65861ba8b4e8 -r 01f8ab45f806 rust/hedgewars-server/src/server/core.rs --- a/rust/hedgewars-server/src/server/core.rs Tue Apr 09 23:03:12 2019 +0300 +++ b/rust/hedgewars-server/src/server/core.rs Wed Apr 10 01:13:29 2019 +0300 @@ -16,6 +16,7 @@ pub nick: Option, pub protocol_number: Option, pub server_salt: String, + pub is_checker: bool, } pub struct HWAnteroom { @@ -33,6 +34,7 @@ nick: None, protocol_number: None, server_salt: salt, + is_checker: false, }; self.clients.insert(client_id, client); } @@ -62,7 +64,8 @@ pub fn add_client(&mut self, client_id: ClientId, data: HWAnteClient) { if let (Some(protocol), Some(nick)) = (data.protocol_number, data.nick) { - let client = HWClient::new(client_id, protocol.get(), nick); + let mut client = HWClient::new(client_id, protocol.get(), nick); + client.set_is_checker(data.is_checker); self.clients.insert(client_id, client); } } @@ -119,28 +122,39 @@ .find_map(|(_, c)| Some(c).filter(|c| c.nick == nick)) } - pub fn select_clients(&self, f: F) -> Vec + pub fn collect_clients(&self, f: F) -> Vec where F: Fn(&(usize, &HWClient)) -> bool, { self.clients.iter().filter(f).map(|(_, c)| c.id).collect() } - pub fn lobby_clients(&self) -> Vec { - self.select_clients(|(_, c)| c.room_id == None) + pub fn collect_nicks(&self, f: F) -> Vec + where + F: Fn(&(usize, &HWClient)) -> bool, + { + self.clients + .iter() + .filter(f) + .map(|(_, c)| c.nick.clone()) + .collect() } - pub fn room_clients(&self, room_id: RoomId) -> Vec { - self.select_clients(|(_, c)| c.room_id == Some(room_id)) + pub fn collect_lobby_clients(&self) -> Vec { + self.collect_clients(|(_, c)| c.room_id == None) + } + + pub fn collect_room_clients(&self, room_id: RoomId) -> Vec { + self.collect_clients(|(_, c)| c.room_id == Some(room_id)) } pub fn protocol_clients(&self, protocol: u16) -> Vec { - self.select_clients(|(_, c)| c.protocol_number == protocol) + self.collect_clients(|(_, c)| c.protocol_number == protocol) } pub fn other_clients_in_room(&self, self_id: ClientId) -> Vec { let room_id = self.clients[self_id].room_id; - self.select_clients(|(id, c)| *id != self_id && c.room_id == room_id) + self.collect_clients(|(id, c)| *id != self_id && c.room_id == room_id) } }