1 use super::coretypes::ClientId; |
1 use super::coretypes::ClientId; |
2 |
2 |
3 const IS_ADMIN: u8 = 0b0000_0001; |
3 bitflags!{ |
4 const IS_MASTER: u8 = 0b0000_0010; |
4 pub struct ClientFlags: u8 { |
5 const IS_READY: u8 = 0b0000_0100; |
5 const IS_ADMIN = 0b0000_0001; |
6 const IS_IN_GAME: u8 = 0b0000_1000; |
6 const IS_MASTER = 0b0000_0010; |
7 const IS_JOINED_MID_GAME: u8 = 0b0001_0000; |
7 const IS_READY = 0b0000_0100; |
|
8 const IS_IN_GAME = 0b0000_1000; |
|
9 const IS_JOINED_MID_GAME = 0b0001_0000; |
|
10 } |
|
11 } |
8 |
12 |
9 pub struct HWClient { |
13 pub struct HWClient { |
10 pub id: ClientId, |
14 pub id: ClientId, |
11 pub room_id: Option<usize>, |
15 pub room_id: Option<usize>, |
12 pub nick: String, |
16 pub nick: String, |
13 pub protocol_number: u16, |
17 pub protocol_number: u16, |
14 flags: u8, |
18 pub flags: ClientFlags, |
15 pub teams_in_game: u8, |
19 pub teams_in_game: u8, |
16 pub team_indices: Vec<u8>, |
20 pub team_indices: Vec<u8>, |
17 pub clan: Option<u8> |
21 pub clan: Option<u8> |
18 } |
22 } |
19 |
23 |
22 HWClient { |
26 HWClient { |
23 id, |
27 id, |
24 room_id: None, |
28 room_id: None, |
25 nick: String::new(), |
29 nick: String::new(), |
26 protocol_number: 0, |
30 protocol_number: 0, |
27 flags: 0, |
31 flags: ClientFlags::empty(), |
28 teams_in_game: 0, |
32 teams_in_game: 0, |
29 team_indices: Vec::new(), |
33 team_indices: Vec::new(), |
30 clan: None, |
34 clan: None, |
31 } |
35 } |
32 } |
36 } |
33 |
37 |
34 fn set(&mut self, mask: u8, value: bool) { |
38 fn contains(& self, mask: ClientFlags) -> bool { |
35 if value { self.flags |= mask } else { self.flags &= !mask } |
39 self.flags.contains(mask) |
36 } |
40 } |
37 |
41 |
38 pub fn is_admin(&self)-> bool { self.flags & IS_ADMIN != 0 } |
42 fn set(&mut self, mask: ClientFlags, value: bool) { |
39 pub fn is_master(&self)-> bool { self.flags & IS_MASTER != 0 } |
43 self.flags.set(mask, value); |
40 pub fn is_ready(&self)-> bool { self.flags & IS_READY != 0 } |
44 } |
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 |
45 |
44 pub fn set_is_admin(&mut self, value: bool) { self.set(IS_ADMIN, value) } |
46 pub fn is_admin(&self)-> bool { self.contains(ClientFlags::IS_ADMIN) } |
45 pub fn set_is_master(&mut self, value: bool) { self.set(IS_MASTER, value) } |
47 pub fn is_master(&self)-> bool { self.contains(ClientFlags::IS_MASTER) } |
46 pub fn set_is_ready(&mut self, value: bool) { self.set(IS_READY, value) } |
48 pub fn is_ready(&self)-> bool { self.contains(ClientFlags::IS_READY) } |
47 pub fn set_is_in_game(&mut self, value: bool) { self.set(IS_IN_GAME, value) } |
49 pub fn is_in_game(&self)-> bool { self.contains(ClientFlags::IS_IN_GAME) } |
48 pub fn set_is_joined_mid_game(&mut self, value: bool) { self.set(IS_JOINED_MID_GAME, value) } |
50 pub fn is_joined_mid_game(&self)-> bool { self.contains(ClientFlags::IS_JOINED_MID_GAME) } |
|
51 |
|
52 pub fn set_is_admin(&mut self, value: bool) { self.set(ClientFlags::IS_ADMIN, value) } |
|
53 pub fn set_is_master(&mut self, value: bool) { self.set(ClientFlags::IS_MASTER, value) } |
|
54 pub fn set_is_ready(&mut self, value: bool) { self.set(ClientFlags::IS_READY, value) } |
|
55 pub fn set_is_in_game(&mut self, value: bool) { self.set(ClientFlags::IS_IN_GAME, value) } |
|
56 pub fn set_is_joined_mid_game(&mut self, value: bool) { self.set(ClientFlags::IS_JOINED_MID_GAME, value) } |
49 } |
57 } |