gameServer2/src/server/client.rs
author alfadur
Mon, 16 Jul 2018 22:59:58 +0300
changeset 13527 282e5e54386f
parent 13525 1ee192f13456
child 13534 662f7df89d06
permissions -rw-r--r--
Something down in the food chain already uses bitflags, so might as well switch to them
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13483
d79795acaa73 Mostly implement voting
alfadur
parents: 13482
diff changeset
     1
use super::coretypes::ClientId;
12133
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
     2
13527
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
     3
bitflags!{
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
     4
    pub struct ClientFlags: u8 {
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
     5
        const IS_ADMIN = 0b0000_0001;
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
     6
        const IS_MASTER = 0b0000_0010;
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
     7
        const IS_READY = 0b0000_0100;
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
     8
        const IS_IN_GAME = 0b0000_1000;
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
     9
        const IS_JOINED_MID_GAME = 0b0001_0000;
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    10
    }
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    11
}
13525
1ee192f13456 Better packing for clients
alfadur
parents: 13483
diff changeset
    12
12133
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
    13
pub struct HWClient {
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12858
diff changeset
    14
    pub id: ClientId,
12857
bd35cb2302b3 Quick dirty fix for building
unc0rr
parents: 12152
diff changeset
    15
    pub room_id: Option<usize>,
12146
78925eff02c2 Basic support for NICK message
unc0rr
parents: 12144
diff changeset
    16
    pub nick: String,
13525
1ee192f13456 Better packing for clients
alfadur
parents: 13483
diff changeset
    17
    pub protocol_number: u16,
13527
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    18
    pub flags: ClientFlags,
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13124
diff changeset
    19
    pub teams_in_game: u8,
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13424
diff changeset
    20
    pub team_indices: Vec<u8>,
13525
1ee192f13456 Better packing for clients
alfadur
parents: 13483
diff changeset
    21
    pub clan: Option<u8>
12133
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
    22
}
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
    23
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
    24
impl HWClient {
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12858
diff changeset
    25
    pub fn new(id: ClientId) -> HWClient {
12133
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
    26
        HWClient {
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12858
diff changeset
    27
            id,
12151
8d8fb85bc09c SendAllButMe action, list all clients in lobby in LobbyJoined message to newcomers
unc0rr
parents: 12149
diff changeset
    28
            room_id: None,
12146
78925eff02c2 Basic support for NICK message
unc0rr
parents: 12144
diff changeset
    29
            nick: String::new(),
12151
8d8fb85bc09c SendAllButMe action, list all clients in lobby in LobbyJoined message to newcomers
unc0rr
parents: 12149
diff changeset
    30
            protocol_number: 0,
13527
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    31
            flags: ClientFlags::empty(),
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13124
diff changeset
    32
            teams_in_game: 0,
13428
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13424
diff changeset
    33
            team_indices: Vec::new(),
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13124
diff changeset
    34
            clan: None,
12133
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
    35
        }
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
    36
    }
13525
1ee192f13456 Better packing for clients
alfadur
parents: 13483
diff changeset
    37
13527
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    38
    fn contains(& self, mask: ClientFlags) -> bool {
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    39
        self.flags.contains(mask)
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    40
    }
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    41
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    42
    fn set(&mut self, mask: ClientFlags, value: bool) {
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    43
        self.flags.set(mask, value);
13525
1ee192f13456 Better packing for clients
alfadur
parents: 13483
diff changeset
    44
    }
1ee192f13456 Better packing for clients
alfadur
parents: 13483
diff changeset
    45
13527
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    46
    pub fn is_admin(&self)-> bool { self.contains(ClientFlags::IS_ADMIN) }
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    47
    pub fn is_master(&self)-> bool { self.contains(ClientFlags::IS_MASTER) }
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    48
    pub fn is_ready(&self)-> bool { self.contains(ClientFlags::IS_READY) }
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    49
    pub fn is_in_game(&self)-> bool { self.contains(ClientFlags::IS_IN_GAME) }
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    50
    pub fn is_joined_mid_game(&self)-> bool { self.contains(ClientFlags::IS_JOINED_MID_GAME) }
13525
1ee192f13456 Better packing for clients
alfadur
parents: 13483
diff changeset
    51
13527
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    52
    pub fn set_is_admin(&mut self, value: bool) { self.set(ClientFlags::IS_ADMIN, value) }
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    53
    pub fn set_is_master(&mut self, value: bool) { self.set(ClientFlags::IS_MASTER, value) }
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    54
    pub fn set_is_ready(&mut self, value: bool) { self.set(ClientFlags::IS_READY, value) }
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    55
    pub fn set_is_in_game(&mut self, value: bool) { self.set(ClientFlags::IS_IN_GAME, value) }
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13525
diff changeset
    56
    pub fn set_is_joined_mid_game(&mut self, value: bool) { self.set(ClientFlags::IS_JOINED_MID_GAME, value) }
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12858
diff changeset
    57
}