author | alfadur |
Fri, 13 Jul 2018 19:52:19 +0300 | |
changeset 13525 | 1ee192f13456 |
parent 13483 | d79795acaa73 |
child 13527 | 282e5e54386f |
permissions | -rw-r--r-- |
13483 | 1 |
use super::coretypes::ClientId; |
12133 | 2 |
|
13525 | 3 |
const IS_ADMIN: u8 = 0b0000_0001; |
4 |
const IS_MASTER: u8 = 0b0000_0010; |
|
5 |
const IS_READY: u8 = 0b0000_0100; |
|
6 |
const IS_IN_GAME: u8 = 0b0000_1000; |
|
7 |
const IS_JOINED_MID_GAME: u8 = 0b0001_0000; |
|
8 |
||
12133 | 9 |
pub struct HWClient { |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12858
diff
changeset
|
10 |
pub id: ClientId, |
12857 | 11 |
pub room_id: Option<usize>, |
12146 | 12 |
pub nick: String, |
13525 | 13 |
pub protocol_number: u16, |
14 |
flags: u8, |
|
13424 | 15 |
pub teams_in_game: u8, |
13428 | 16 |
pub team_indices: Vec<u8>, |
13525 | 17 |
pub clan: Option<u8> |
12133 | 18 |
} |
19 |
||
20 |
impl HWClient { |
|
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12858
diff
changeset
|
21 |
pub fn new(id: ClientId) -> HWClient { |
12133 | 22 |
HWClient { |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12858
diff
changeset
|
23 |
id, |
12151
8d8fb85bc09c
SendAllButMe action, list all clients in lobby in LobbyJoined message to newcomers
unc0rr
parents:
12149
diff
changeset
|
24 |
room_id: None, |
12146 | 25 |
nick: String::new(), |
12151
8d8fb85bc09c
SendAllButMe action, list all clients in lobby in LobbyJoined message to newcomers
unc0rr
parents:
12149
diff
changeset
|
26 |
protocol_number: 0, |
13525 | 27 |
flags: 0, |
13424 | 28 |
teams_in_game: 0, |
13428 | 29 |
team_indices: Vec::new(), |
13424 | 30 |
clan: None, |
12133 | 31 |
} |
32 |
} |
|
13525 | 33 |
|
34 |
fn set(&mut self, mask: u8, value: bool) { |
|
35 |
if value { self.flags |= mask } else { self.flags &= !mask } |
|
36 |
} |
|
37 |
||
38 |
pub fn is_admin(&self)-> bool { self.flags & IS_ADMIN != 0 } |
|
39 |
pub fn is_master(&self)-> bool { self.flags & IS_MASTER != 0 } |
|
40 |
pub fn is_ready(&self)-> bool { self.flags & IS_READY != 0 } |
|
41 |
pub fn is_in_game(&self)-> bool { self.flags & IS_IN_GAME != 0 } |
|
42 |
pub fn is_joined_mid_game(&self)-> bool { self.flags & IS_JOINED_MID_GAME != 0 } |
|
43 |
||
44 |
pub fn set_is_admin(&mut self, value: bool) { self.set(IS_ADMIN, value) } |
|
45 |
pub fn set_is_master(&mut self, value: bool) { self.set(IS_MASTER, value) } |
|
46 |
pub fn set_is_ready(&mut self, value: bool) { self.set(IS_READY, value) } |
|
47 |
pub fn set_is_in_game(&mut self, value: bool) { self.set(IS_IN_GAME, value) } |
|
48 |
pub fn set_is_joined_mid_game(&mut self, value: bool) { self.set(IS_JOINED_MID_GAME, value) } |
|
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12858
diff
changeset
|
49 |
} |