author | alfadur <mail@none> |
Thu, 07 Feb 2019 17:02:24 +0300 | |
changeset 14714 | 6a2e13e36b7f |
parent 14478 | 98ef2913ec73 |
child 14800 | f43ab2bd76ae |
permissions | -rw-r--r-- |
13450 | 1 |
use super::coretypes::ClientId; |
13810 | 2 |
use bitflags::*; |
12128 | 3 |
|
14478 | 4 |
bitflags! { |
13493
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
5 |
pub struct ClientFlags: u8 { |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
6 |
const IS_ADMIN = 0b0000_0001; |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
7 |
const IS_MASTER = 0b0000_0010; |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
8 |
const IS_READY = 0b0000_0100; |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
9 |
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:
13486
diff
changeset
|
10 |
const IS_JOINED_MID_GAME = 0b0001_0000; |
13771 | 11 |
const IS_CHECKER = 0b0010_0000; |
13529 | 12 |
|
13 |
const NONE = 0b0000_0000; |
|
14 |
const DEFAULT = Self::NONE.bits; |
|
13493
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
15 |
} |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
16 |
} |
13486 | 17 |
|
12128 | 18 |
pub struct HWClient { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12853
diff
changeset
|
19 |
pub id: ClientId, |
12852 | 20 |
pub room_id: Option<usize>, |
12141 | 21 |
pub nick: String, |
13486 | 22 |
pub protocol_number: u16, |
13493
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
23 |
pub flags: ClientFlags, |
13419 | 24 |
pub teams_in_game: u8, |
13423 | 25 |
pub team_indices: Vec<u8>, |
14478 | 26 |
pub clan: Option<u8>, |
12128 | 27 |
} |
28 |
||
29 |
impl HWClient { |
|
14714 | 30 |
pub fn new(id: ClientId, protocol_number: u16, nick: String) -> HWClient { |
12128 | 31 |
HWClient { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12853
diff
changeset
|
32 |
id, |
14714 | 33 |
nick, |
34 |
protocol_number, |
|
12146
8d8fb85bc09c
SendAllButMe action, list all clients in lobby in LobbyJoined message to newcomers
unc0rr
parents:
12144
diff
changeset
|
35 |
room_id: None, |
13529 | 36 |
flags: ClientFlags::DEFAULT, |
13419 | 37 |
teams_in_game: 0, |
13423 | 38 |
team_indices: Vec::new(), |
13419 | 39 |
clan: None, |
12128 | 40 |
} |
41 |
} |
|
13486 | 42 |
|
14478 | 43 |
fn contains(&self, mask: ClientFlags) -> bool { |
13493
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
44 |
self.flags.contains(mask) |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
45 |
} |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
46 |
|
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
47 |
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:
13486
diff
changeset
|
48 |
self.flags.set(mask, value); |
13486 | 49 |
} |
50 |
||
14478 | 51 |
pub fn is_admin(&self) -> bool { |
52 |
self.contains(ClientFlags::IS_ADMIN) |
|
53 |
} |
|
54 |
pub fn is_master(&self) -> bool { |
|
55 |
self.contains(ClientFlags::IS_MASTER) |
|
56 |
} |
|
57 |
pub fn is_ready(&self) -> bool { |
|
58 |
self.contains(ClientFlags::IS_READY) |
|
59 |
} |
|
60 |
pub fn is_in_game(&self) -> bool { |
|
61 |
self.contains(ClientFlags::IS_IN_GAME) |
|
62 |
} |
|
63 |
pub fn is_joined_mid_game(&self) -> bool { |
|
64 |
self.contains(ClientFlags::IS_JOINED_MID_GAME) |
|
65 |
} |
|
66 |
pub fn is_checker(&self) -> bool { |
|
67 |
self.contains(ClientFlags::IS_CHECKER) |
|
68 |
} |
|
13486 | 69 |
|
14478 | 70 |
pub fn set_is_admin(&mut self, value: bool) { |
71 |
self.set(ClientFlags::IS_ADMIN, value) |
|
72 |
} |
|
73 |
pub fn set_is_master(&mut self, value: bool) { |
|
74 |
self.set(ClientFlags::IS_MASTER, value) |
|
75 |
} |
|
76 |
pub fn set_is_ready(&mut self, value: bool) { |
|
77 |
self.set(ClientFlags::IS_READY, value) |
|
78 |
} |
|
79 |
pub fn set_is_in_game(&mut self, value: bool) { |
|
80 |
self.set(ClientFlags::IS_IN_GAME, value) |
|
81 |
} |
|
82 |
pub fn set_is_joined_mid_game(&mut self, value: bool) { |
|
83 |
self.set(ClientFlags::IS_JOINED_MID_GAME, value) |
|
84 |
} |
|
85 |
pub fn set_is_checker(&mut self, value: bool) { |
|
86 |
self.set(ClientFlags::IS_CHECKER, value) |
|
87 |
} |
|
88 |
} |