gameServer2/src/server/client.rs
changeset 13534 395a4c92e523
parent 13529 662f7df89d06
child 13798 4664da990556
equal deleted inserted replaced
13533:0c8001e43fd3 13534:395a4c92e523
     1 use super::coretypes::ClientId;
     1 use super::coretypes::ClientId;
       
     2 
       
     3 bitflags!{
       
     4     pub struct ClientFlags: u8 {
       
     5         const IS_ADMIN = 0b0000_0001;
       
     6         const IS_MASTER = 0b0000_0010;
       
     7         const IS_READY = 0b0000_0100;
       
     8         const IS_IN_GAME = 0b0000_1000;
       
     9         const IS_JOINED_MID_GAME = 0b0001_0000;
       
    10 
       
    11         const NONE = 0b0000_0000;
       
    12         const DEFAULT = Self::NONE.bits;
       
    13     }
       
    14 }
     2 
    15 
     3 pub struct HWClient {
    16 pub struct HWClient {
     4     pub id: ClientId,
    17     pub id: ClientId,
     5     pub room_id: Option<usize>,
    18     pub room_id: Option<usize>,
     6     pub nick: String,
    19     pub nick: String,
     7     pub protocol_number: u32,
    20     pub protocol_number: u16,
     8     pub is_admin: bool,
    21     pub flags: ClientFlags,
     9     pub is_master: bool,
       
    10     pub is_ready: bool,
       
    11     pub is_in_game: bool,
       
    12     pub teams_in_game: u8,
    22     pub teams_in_game: u8,
    13     pub team_indices: Vec<u8>,
    23     pub team_indices: Vec<u8>,
    14     pub clan: Option<u8>,
    24     pub clan: Option<u8>
    15     pub is_joined_mid_game: bool,
       
    16 }
    25 }
    17 
    26 
    18 impl HWClient {
    27 impl HWClient {
    19     pub fn new(id: ClientId) -> HWClient {
    28     pub fn new(id: ClientId) -> HWClient {
    20         HWClient {
    29         HWClient {
    21             id,
    30             id,
    22             room_id: None,
    31             room_id: None,
    23             nick: String::new(),
    32             nick: String::new(),
    24             protocol_number: 0,
    33             protocol_number: 0,
    25             is_admin: false,
    34             flags: ClientFlags::DEFAULT,
    26             is_master: false,
       
    27             is_ready: false,
       
    28             is_in_game: false,
       
    29             teams_in_game: 0,
    35             teams_in_game: 0,
    30             team_indices: Vec::new(),
    36             team_indices: Vec::new(),
    31             clan: None,
    37             clan: None,
    32             is_joined_mid_game: false,
       
    33         }
    38         }
    34     }
    39     }
       
    40 
       
    41     fn contains(& self, mask: ClientFlags) -> bool {
       
    42         self.flags.contains(mask)
       
    43     }
       
    44 
       
    45     fn set(&mut self, mask: ClientFlags, value: bool) {
       
    46         self.flags.set(mask, value);
       
    47     }
       
    48 
       
    49     pub fn is_admin(&self)-> bool { self.contains(ClientFlags::IS_ADMIN) }
       
    50     pub fn is_master(&self)-> bool { self.contains(ClientFlags::IS_MASTER) }
       
    51     pub fn is_ready(&self)-> bool { self.contains(ClientFlags::IS_READY) }
       
    52     pub fn is_in_game(&self)-> bool { self.contains(ClientFlags::IS_IN_GAME) }
       
    53     pub fn is_joined_mid_game(&self)-> bool { self.contains(ClientFlags::IS_JOINED_MID_GAME) }
       
    54 
       
    55     pub fn set_is_admin(&mut self, value: bool) { self.set(ClientFlags::IS_ADMIN, value) }
       
    56     pub fn set_is_master(&mut self, value: bool) { self.set(ClientFlags::IS_MASTER, value) }
       
    57     pub fn set_is_ready(&mut self, value: bool) { self.set(ClientFlags::IS_READY, value) }
       
    58     pub fn set_is_in_game(&mut self, value: bool) { self.set(ClientFlags::IS_IN_GAME, value) }
       
    59     pub fn set_is_joined_mid_game(&mut self, value: bool) { self.set(ClientFlags::IS_JOINED_MID_GAME, value) }
    35 }
    60 }