author | alfadur <mail@none> |
Thu, 07 Feb 2019 14:49:51 +0300 | |
changeset 14713 | e5415faa117b |
parent 14478 | 98ef2913ec73 |
child 14714 | 6a2e13e36b7f |
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, |
13771 | 22 |
pub web_password: String, |
23 |
pub server_salt: String, |
|
13486 | 24 |
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
|
25 |
pub flags: ClientFlags, |
13419 | 26 |
pub teams_in_game: u8, |
13423 | 27 |
pub team_indices: Vec<u8>, |
14478 | 28 |
pub clan: Option<u8>, |
12128 | 29 |
} |
30 |
||
31 |
impl HWClient { |
|
13771 | 32 |
pub fn new(id: ClientId, salt: String) -> HWClient { |
12128 | 33 |
HWClient { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12853
diff
changeset
|
34 |
id, |
12146
8d8fb85bc09c
SendAllButMe action, list all clients in lobby in LobbyJoined message to newcomers
unc0rr
parents:
12144
diff
changeset
|
35 |
room_id: None, |
12141 | 36 |
nick: String::new(), |
13771 | 37 |
web_password: String::new(), |
38 |
server_salt: salt, |
|
12146
8d8fb85bc09c
SendAllButMe action, list all clients in lobby in LobbyJoined message to newcomers
unc0rr
parents:
12144
diff
changeset
|
39 |
protocol_number: 0, |
13529 | 40 |
flags: ClientFlags::DEFAULT, |
13419 | 41 |
teams_in_game: 0, |
13423 | 42 |
team_indices: Vec::new(), |
13419 | 43 |
clan: None, |
12128 | 44 |
} |
45 |
} |
|
13486 | 46 |
|
14478 | 47 |
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
|
48 |
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
|
49 |
} |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
50 |
|
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
51 |
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
|
52 |
self.flags.set(mask, value); |
13486 | 53 |
} |
54 |
||
14478 | 55 |
pub fn is_admin(&self) -> bool { |
56 |
self.contains(ClientFlags::IS_ADMIN) |
|
57 |
} |
|
58 |
pub fn is_master(&self) -> bool { |
|
59 |
self.contains(ClientFlags::IS_MASTER) |
|
60 |
} |
|
61 |
pub fn is_ready(&self) -> bool { |
|
62 |
self.contains(ClientFlags::IS_READY) |
|
63 |
} |
|
64 |
pub fn is_in_game(&self) -> bool { |
|
65 |
self.contains(ClientFlags::IS_IN_GAME) |
|
66 |
} |
|
67 |
pub fn is_joined_mid_game(&self) -> bool { |
|
68 |
self.contains(ClientFlags::IS_JOINED_MID_GAME) |
|
69 |
} |
|
70 |
pub fn is_checker(&self) -> bool { |
|
71 |
self.contains(ClientFlags::IS_CHECKER) |
|
72 |
} |
|
13486 | 73 |
|
14478 | 74 |
pub fn set_is_admin(&mut self, value: bool) { |
75 |
self.set(ClientFlags::IS_ADMIN, value) |
|
76 |
} |
|
77 |
pub fn set_is_master(&mut self, value: bool) { |
|
78 |
self.set(ClientFlags::IS_MASTER, value) |
|
79 |
} |
|
80 |
pub fn set_is_ready(&mut self, value: bool) { |
|
81 |
self.set(ClientFlags::IS_READY, value) |
|
82 |
} |
|
83 |
pub fn set_is_in_game(&mut self, value: bool) { |
|
84 |
self.set(ClientFlags::IS_IN_GAME, value) |
|
85 |
} |
|
86 |
pub fn set_is_joined_mid_game(&mut self, value: bool) { |
|
87 |
self.set(ClientFlags::IS_JOINED_MID_GAME, value) |
|
88 |
} |
|
89 |
pub fn set_is_checker(&mut self, value: bool) { |
|
90 |
self.set(ClientFlags::IS_CHECKER, value) |
|
91 |
} |
|
92 |
} |