gameServer2/src/server/client.rs
author alfadur
Mon, 16 Jul 2018 22:32:04 +0300
changeset 13521 ba5211dddb21
parent 13520 1ee192f13456
child 13522 282e5e54386f
permissions -rw-r--r--
Assorted chat fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13478
d79795acaa73 Mostly implement voting
alfadur
parents: 13477
diff changeset
     1
use super::coretypes::ClientId;
12128
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
     2
13520
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
     3
const IS_ADMIN: u8 = 0b0000_0001;
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
     4
const IS_MASTER: u8 = 0b0000_0010;
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
     5
const IS_READY: u8 = 0b0000_0100;
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
     6
const IS_IN_GAME: u8 = 0b0000_1000;
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
     7
const IS_JOINED_MID_GAME: u8 = 0b0001_0000;
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
     8
12128
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
     9
pub struct HWClient {
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12853
diff changeset
    10
    pub id: ClientId,
12852
bd35cb2302b3 Quick dirty fix for building
unc0rr
parents: 12147
diff changeset
    11
    pub room_id: Option<usize>,
12141
78925eff02c2 Basic support for NICK message
unc0rr
parents: 12139
diff changeset
    12
    pub nick: String,
13520
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    13
    pub protocol_number: u16,
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    14
    flags: u8,
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13119
diff changeset
    15
    pub teams_in_game: u8,
13423
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13419
diff changeset
    16
    pub team_indices: Vec<u8>,
13520
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    17
    pub clan: Option<u8>
12128
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
    18
}
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
    19
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
    20
impl HWClient {
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12853
diff changeset
    21
    pub fn new(id: ClientId) -> HWClient {
12128
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
    22
        HWClient {
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12853
diff changeset
    23
            id,
12146
8d8fb85bc09c SendAllButMe action, list all clients in lobby in LobbyJoined message to newcomers
unc0rr
parents: 12144
diff changeset
    24
            room_id: None,
12141
78925eff02c2 Basic support for NICK message
unc0rr
parents: 12139
diff changeset
    25
            nick: String::new(),
12146
8d8fb85bc09c SendAllButMe action, list all clients in lobby in LobbyJoined message to newcomers
unc0rr
parents: 12144
diff changeset
    26
            protocol_number: 0,
13520
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    27
            flags: 0,
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13119
diff changeset
    28
            teams_in_game: 0,
13423
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13419
diff changeset
    29
            team_indices: Vec::new(),
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13119
diff changeset
    30
            clan: None,
12128
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
    31
        }
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
    32
    }
13520
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    33
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    34
    fn set(&mut self, mask: u8, value: bool) {
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    35
        if value { self.flags |= mask } else { self.flags &= !mask }
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    36
    }
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    37
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    38
    pub fn is_admin(&self)-> bool { self.flags & IS_ADMIN != 0 }
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    39
    pub fn is_master(&self)-> bool { self.flags & IS_MASTER != 0 }
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    40
    pub fn is_ready(&self)-> bool { self.flags & IS_READY != 0 }
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    41
    pub fn is_in_game(&self)-> bool { self.flags & IS_IN_GAME != 0 }
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    42
    pub fn is_joined_mid_game(&self)-> bool { self.flags & IS_JOINED_MID_GAME != 0 }
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    43
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    44
    pub fn set_is_admin(&mut self, value: bool) { self.set(IS_ADMIN, value) }
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    45
    pub fn set_is_master(&mut self, value: bool) { self.set(IS_MASTER, value) }
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    46
    pub fn set_is_ready(&mut self, value: bool) { self.set(IS_READY, value) }
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    47
    pub fn set_is_in_game(&mut self, value: bool) { self.set(IS_IN_GAME, value) }
1ee192f13456 Better packing for clients
alfadur
parents: 13478
diff changeset
    48
    pub fn set_is_joined_mid_game(&mut self, value: bool) { self.set(IS_JOINED_MID_GAME, value) }
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12853
diff changeset
    49
}