rust/hedgewars-server/src/core/server.rs
changeset 15534 bb93e9642b5b
parent 15533 0606f89698e7
child 15536 a798e6441a36
equal deleted inserted replaced
15533:0606f89698e7 15534:bb93e9642b5b
    23     DoesntExist,
    23     DoesntExist,
    24     WrongProtocol,
    24     WrongProtocol,
    25     WrongPassword,
    25     WrongPassword,
    26     Full,
    26     Full,
    27     Restricted,
    27     Restricted,
       
    28     RegistrationRequired,
    28 }
    29 }
    29 
    30 
    30 #[derive(Debug)]
    31 #[derive(Debug)]
    31 pub enum LeaveRoomResult {
    32 pub enum LeaveRoomResult {
    32     RoomRemoved,
    33     RoomRemoved,
   204     pub fn has_client(&self, client_id: ClientId) -> bool {
   205     pub fn has_client(&self, client_id: ClientId) -> bool {
   205         self.clients.contains(client_id)
   206         self.clients.contains(client_id)
   206     }
   207     }
   207 
   208 
   208     #[inline]
   209     #[inline]
   209     pub fn iter_clients(&self) -> impl Iterator<Item = &HwClient> {
   210     pub fn iter_clients(&self) -> impl Iterator<Item = &HwClient> + Clone {
   210         self.clients.iter().map(|(_, c)| c)
   211         self.clients.iter().map(|(_, c)| c)
   211     }
   212     }
   212 
   213 
   213     #[inline]
   214     #[inline]
   214     pub fn room(&self, room_id: RoomId) -> &HwRoom {
   215     pub fn room(&self, room_id: RoomId) -> &HwRoom {
   321         let room = &mut self.rooms[room_id];
   322         let room = &mut self.rooms[room_id];
   322         let client = &mut self.clients[client_id];
   323         let client = &mut self.clients[client_id];
   323 
   324 
   324         if client.protocol_number != room.protocol_number {
   325         if client.protocol_number != room.protocol_number {
   325             Err(WrongProtocol)
   326             Err(WrongProtocol)
   326         } else if room.password.is_some() && room_password != room.password.as_deref() {
   327         } else if room.password.is_some()
       
   328             && room_password != room.password.as_deref()
       
   329             && !client.has_super_power()
       
   330         {
   327             Err(WrongPassword)
   331             Err(WrongPassword)
   328         } else if room.is_join_restricted() {
   332         } else if room.is_join_restricted() {
   329             Err(Restricted)
   333             Err(Restricted)
       
   334         } else if room.is_registration_required() {
       
   335             Err(RegistrationRequired)
   330         } else if room.players_number == u8::max_value() {
   336         } else if room.players_number == u8::max_value() {
   331             Err(Full)
   337             Err(Full)
   332         } else {
   338         } else {
   333             move_to_room(client, room);
   339             move_to_room(client, room);
   334             let room_id = room.id;
   340             let room_id = room.id;
   335             Ok((
   341             Ok((
   336                 &self.clients[client_id],
   342                 &self.clients[client_id],
   337                 &self.rooms[room_id],
   343                 &self.rooms[room_id],
   338                 self.clients.iter().map(|(_, c)| c),
   344                 self.iter_clients()
       
   345                     .filter(move |c| c.room_id == Some(room_id)),
   339             ))
   346             ))
   340         }
   347         }
   341     }
   348     }
   342 
   349 
   343     #[inline]
   350     #[inline]