rust/hedgewars-server/src/core/server.rs
changeset 15532 f1205f33bf5b
parent 15531 ede5f4ec48f3
child 15533 0606f89698e7
equal deleted inserted replaced
15531:ede5f4ec48f3 15532:f1205f33bf5b
   155     pub struct ServerFlags: u8 {
   155     pub struct ServerFlags: u8 {
   156         const REGISTERED_ONLY = 0b0000_1000;
   156         const REGISTERED_ONLY = 0b0000_1000;
   157     }
   157     }
   158 }
   158 }
   159 
   159 
       
   160 struct HwChecker {
       
   161     pub id: ClientId,
       
   162     pub is_ready: bool,
       
   163 }
       
   164 
       
   165 impl HwChecker {
       
   166     pub fn new(id: ClientId) -> Self {
       
   167         Self {
       
   168             id,
       
   169             is_ready: false,
       
   170         }
       
   171     }
       
   172 }
       
   173 
   160 pub struct HwServer {
   174 pub struct HwServer {
   161     clients: IndexSlab<HwClient>,
   175     clients: IndexSlab<HwClient>,
   162     rooms: Slab<HwRoom>,
   176     rooms: Slab<HwRoom>,
       
   177     checkers: IndexSlab<HwChecker>,
   163     latest_protocol: u16,
   178     latest_protocol: u16,
   164     flags: ServerFlags,
   179     flags: ServerFlags,
   165     greetings: ServerGreetings,
   180     greetings: ServerGreetings,
   166 }
   181 }
   167 
   182 
   168 impl HwServer {
   183 impl HwServer {
   169     pub fn new(clients_limit: usize, rooms_limit: usize) -> Self {
   184     pub fn new(clients_limit: usize, rooms_limit: usize) -> Self {
   170         let rooms = Slab::with_capacity(rooms_limit);
   185         let rooms = Slab::with_capacity(rooms_limit);
   171         let clients = IndexSlab::with_capacity(clients_limit);
   186         let clients = IndexSlab::with_capacity(clients_limit);
       
   187         let checkers = IndexSlab::new();
   172         Self {
   188         Self {
   173             clients,
   189             clients,
   174             rooms,
   190             rooms,
       
   191             checkers,
   175             greetings: ServerGreetings::new(),
   192             greetings: ServerGreetings::new(),
   176             latest_protocol: 58,
   193             latest_protocol: 58,
   177             flags: ServerFlags::empty(),
   194             flags: ServerFlags::empty(),
   178         }
   195         }
   179     }
   196     }
   240             .map(|c| c.is_admin())
   257             .map(|c| c.is_admin())
   241             .unwrap_or(false)
   258             .unwrap_or(false)
   242     }
   259     }
   243 
   260 
   244     pub fn add_client(&mut self, client_id: ClientId, data: HwAnteroomClient) {
   261     pub fn add_client(&mut self, client_id: ClientId, data: HwAnteroomClient) {
   245         if let (Some(protocol), Some(nick)) = (data.protocol_number, data.nick) {
   262         if data.is_checker {
       
   263             self.checkers.insert(client_id, HwChecker::new(client_id));
       
   264         } else if let (Some(protocol), Some(nick)) = (data.protocol_number, data.nick) {
   246             let mut client = HwClient::new(client_id, protocol.get(), nick);
   265             let mut client = HwClient::new(client_id, protocol.get(), nick);
   247             client.set_is_checker(data.is_checker);
       
   248             #[cfg(not(feature = "official-server"))]
   266             #[cfg(not(feature = "official-server"))]
   249             client.set_is_admin(data.is_local_admin);
   267             client.set_is_admin(data.is_local_admin);
   250 
   268 
   251             #[cfg(feature = "official-server")]
   269             #[cfg(feature = "official-server")]
   252             {
   270             {