rust/hedgewars-server/src/core/server.rs
changeset 15882 f185e7367dd3
parent 15848 3d05bada4799
child 15938 ce47259d5c86
equal deleted inserted replaced
15881:212e16c60bf5 15882:f185e7367dd3
     1 use super::{
     1 use super::{
     2     anteroom::HwAnteroomClient,
     2     anteroom::HwAnteroomClient,
     3     client::HwClient,
     3     client::HwClient,
     4     indexslab::IndexSlab,
     4     indexslab::IndexSlab,
     5     room::HwRoom,
     5     room::HwRoom,
     6     types::{ClientId, RoomId, Voting},
     6     types::{CheckerId, ClientId, RoomId, Voting},
     7 };
     7 };
     8 use crate::utils;
     8 use crate::utils;
     9 use hedgewars_network_protocol::types::{GameCfg, ServerVar, TeamInfo, Vote, VoteType};
     9 use hedgewars_network_protocol::types::{GameCfg, ServerVar, TeamInfo, Vote, VoteType};
       
    10 
       
    11 use crate::server::replaystorage::ReplayStorage;
    10 
    12 
    11 use bitflags::*;
    13 use bitflags::*;
    12 use log::*;
    14 use log::*;
    13 use slab::Slab;
    15 use slab::Slab;
    14 use std::{borrow::BorrowMut, cmp::min, collections::HashSet, iter, mem::replace};
    16 use std::{borrow::BorrowMut, cmp::min, collections::HashSet, iter, mem::replace};
   155     pub struct ServerFlags: u8 {
   157     pub struct ServerFlags: u8 {
   156         const REGISTERED_ONLY = 0b0000_1000;
   158         const REGISTERED_ONLY = 0b0000_1000;
   157     }
   159     }
   158 }
   160 }
   159 
   161 
   160 struct HwChecker {
   162 pub struct HwChecker {
   161     pub id: ClientId,
   163     pub id: ClientId,
   162     pub is_ready: bool,
   164     pub is_ready: bool,
   163 }
   165 }
   164 
   166 
   165 impl HwChecker {
   167 impl HwChecker {
   166     pub fn new(id: ClientId) -> Self {
   168     pub fn new(id: ClientId) -> Self {
   167         Self {
   169         Self {
   168             id,
   170             id,
   169             is_ready: false,
   171             is_ready: false,
   170         }
   172         }
       
   173     }
       
   174 
       
   175     pub fn set_is_ready(&mut self, ready: bool) {
       
   176         self.is_ready = ready
   171     }
   177     }
   172 }
   178 }
   173 
   179 
   174 pub struct HwServer {
   180 pub struct HwServer {
   175     clients: IndexSlab<HwClient>,
   181     clients: IndexSlab<HwClient>,
   176     rooms: Slab<HwRoom>,
   182     rooms: Slab<HwRoom>,
   177     checkers: IndexSlab<HwChecker>,
   183     checkers: IndexSlab<HwChecker>,
   178     latest_protocol: u16,
   184     latest_protocol: u16,
   179     flags: ServerFlags,
   185     flags: ServerFlags,
   180     greetings: ServerGreetings,
   186     greetings: ServerGreetings,
       
   187     replay_storage: Option<ReplayStorage>,
   181 }
   188 }
   182 
   189 
   183 impl HwServer {
   190 impl HwServer {
   184     pub fn new(clients_limit: usize, rooms_limit: usize) -> Self {
   191     pub fn new(clients_limit: usize, rooms_limit: usize) -> Self {
   185         let rooms = Slab::with_capacity(rooms_limit);
   192         let rooms = Slab::with_capacity(rooms_limit);
   190             rooms,
   197             rooms,
   191             checkers,
   198             checkers,
   192             greetings: ServerGreetings::new(),
   199             greetings: ServerGreetings::new(),
   193             latest_protocol: 58,
   200             latest_protocol: 58,
   194             flags: ServerFlags::empty(),
   201             flags: ServerFlags::empty(),
       
   202             replay_storage: None,
   195         }
   203         }
   196     }
   204     }
   197 
   205 
   198     #[inline]
   206     #[inline]
   199     pub fn client(&self, client_id: ClientId) -> &HwClient {
   207     pub fn client(&self, client_id: ClientId) -> &HwClient {
   200         &self.clients[client_id]
   208         &self.clients[client_id]
       
   209     }
       
   210 
       
   211     #[inline]
       
   212     pub fn get_checker_mut(&mut self, checker_id: CheckerId) -> Option<&mut HwChecker> {
       
   213         self.checkers.get_mut(checker_id)
   201     }
   214     }
   202 
   215 
   203     #[inline]
   216     #[inline]
   204     pub fn has_client(&self, client_id: ClientId) -> bool {
   217     pub fn has_client(&self, client_id: ClientId) -> bool {
   205         self.clients.contains(client_id)
   218         self.clients.contains(client_id)