rust/hedgewars-server/src/core/server.rs
changeset 15492 395be40faa51
parent 15487 91f0c5ec37b5
child 15516 b907b9071ec5
equal deleted inserted replaced
15491:3dc01bbcd0d8 15492:395be40faa51
    54 pub enum ChangeMasterError {
    54 pub enum ChangeMasterError {
    55     NoAccess,
    55     NoAccess,
    56     AlreadyMaster,
    56     AlreadyMaster,
    57     NoClient,
    57     NoClient,
    58     ClientNotInRoom,
    58     ClientNotInRoom,
       
    59 }
       
    60 
       
    61 #[derive(Debug)]
       
    62 pub enum StartGameError {
       
    63     NotEnoughClans,
       
    64     NotEnoughTeams,
       
    65     NotReady,
       
    66     AlreadyInGame,
    59 }
    67 }
    60 
    68 
    61 #[derive(Debug)]
    69 #[derive(Debug)]
    62 pub struct UninitializedError();
    70 pub struct UninitializedError();
    63 #[derive(Debug)]
    71 #[derive(Debug)]
   405         } else {
   413         } else {
   406             Err(ChangeMasterError::NoAccess)
   414             Err(ChangeMasterError::NoAccess)
   407         }
   415         }
   408     }
   416     }
   409 
   417 
       
   418     pub fn start_game(&mut self, room_id: RoomId) -> Result<Vec<String>, StartGameError> {
       
   419         let (room_clients, room_nicks): (Vec<_>, Vec<_>) = self
       
   420             .clients
       
   421             .iter()
       
   422             .map(|(id, c)| (id, c.nick.clone()))
       
   423             .unzip();
       
   424 
       
   425         let room = &mut self.rooms[room_id];
       
   426 
       
   427         if !room.has_multiple_clans() {
       
   428             Err(StartGameError::NotEnoughClans)
       
   429         } else if room.protocol_number <= 43 && room.players_number != room.ready_players_number {
       
   430             Err(StartGameError::NotReady)
       
   431         } else if room.game_info.is_some() {
       
   432             Err(StartGameError::AlreadyInGame)
       
   433         } else {
       
   434             room.start_round();
       
   435             for id in room_clients {
       
   436                 let c = &mut self.clients[id];
       
   437                 c.set_is_in_game(true);
       
   438                 c.team_indices = room.client_team_indices(c.id);
       
   439             }
       
   440             Ok(room_nicks)
       
   441         }
       
   442     }
       
   443 
   410     #[inline]
   444     #[inline]
   411     pub fn set_var(&mut self, client_id: ClientId, var: ServerVar) -> Result<(), AccessError> {
   445     pub fn set_var(&mut self, client_id: ClientId, var: ServerVar) -> Result<(), AccessError> {
   412         if self.clients[client_id].is_admin() {
   446         if self.clients[client_id].is_admin() {
   413             match var {
   447             match var {
   414                 ServerVar::MOTDNew(msg) => self.greetings.for_latest_protocol = msg,
   448                 ServerVar::MOTDNew(msg) => self.greetings.for_latest_protocol = msg,