author | Wuzzy <Wuzzy2@mail.ru> |
Mon, 29 Apr 2019 21:24:42 +0200 | |
changeset 14870 | 24df603fbcd2 |
parent 14812 | b889d9e1115f |
permissions | -rw-r--r-- |
13450 | 1 |
use super::coretypes::ClientId; |
13810 | 2 |
use bitflags::*; |
12128 | 3 |
|
14478 | 4 |
bitflags! { |
14812 | 5 |
pub struct ClientFlags: u16 { |
13493
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; |
14800
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14714
diff
changeset
|
12 |
const IS_CONTRIBUTOR = 0b0100_0000; |
14807
8ecdb5c6bb2a
implement info, registered only & super power messages
alfadur
parents:
14800
diff
changeset
|
13 |
const HAS_SUPER_POWER = 0b1000_0000; |
14812 | 14 |
const IS_REGISTERED = 0b0001_0000_0000; |
13529 | 15 |
|
16 |
const NONE = 0b0000_0000; |
|
17 |
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
|
18 |
} |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
19 |
} |
13486 | 20 |
|
12128 | 21 |
pub struct HWClient { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12853
diff
changeset
|
22 |
pub id: ClientId, |
12852 | 23 |
pub room_id: Option<usize>, |
12141 | 24 |
pub nick: String, |
13486 | 25 |
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
|
26 |
pub flags: ClientFlags, |
13419 | 27 |
pub teams_in_game: u8, |
13423 | 28 |
pub team_indices: Vec<u8>, |
14478 | 29 |
pub clan: Option<u8>, |
12128 | 30 |
} |
31 |
||
32 |
impl HWClient { |
|
14714 | 33 |
pub fn new(id: ClientId, protocol_number: u16, nick: String) -> HWClient { |
12128 | 34 |
HWClient { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12853
diff
changeset
|
35 |
id, |
14714 | 36 |
nick, |
37 |
protocol_number, |
|
12146
8d8fb85bc09c
SendAllButMe action, list all clients in lobby in LobbyJoined message to newcomers
unc0rr
parents:
12144
diff
changeset
|
38 |
room_id: None, |
13529 | 39 |
flags: ClientFlags::DEFAULT, |
13419 | 40 |
teams_in_game: 0, |
13423 | 41 |
team_indices: Vec::new(), |
13419 | 42 |
clan: None, |
12128 | 43 |
} |
44 |
} |
|
13486 | 45 |
|
14478 | 46 |
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
|
47 |
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
|
48 |
} |
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 |
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
|
51 |
self.flags.set(mask, value); |
13486 | 52 |
} |
53 |
||
14478 | 54 |
pub fn is_admin(&self) -> bool { |
55 |
self.contains(ClientFlags::IS_ADMIN) |
|
56 |
} |
|
57 |
pub fn is_master(&self) -> bool { |
|
58 |
self.contains(ClientFlags::IS_MASTER) |
|
59 |
} |
|
60 |
pub fn is_ready(&self) -> bool { |
|
61 |
self.contains(ClientFlags::IS_READY) |
|
62 |
} |
|
63 |
pub fn is_in_game(&self) -> bool { |
|
64 |
self.contains(ClientFlags::IS_IN_GAME) |
|
65 |
} |
|
66 |
pub fn is_joined_mid_game(&self) -> bool { |
|
67 |
self.contains(ClientFlags::IS_JOINED_MID_GAME) |
|
68 |
} |
|
69 |
pub fn is_checker(&self) -> bool { |
|
70 |
self.contains(ClientFlags::IS_CHECKER) |
|
71 |
} |
|
14800
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14714
diff
changeset
|
72 |
pub fn is_contributor(&self) -> bool { |
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14714
diff
changeset
|
73 |
self.contains(ClientFlags::IS_CONTRIBUTOR) |
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14714
diff
changeset
|
74 |
} |
14807
8ecdb5c6bb2a
implement info, registered only & super power messages
alfadur
parents:
14800
diff
changeset
|
75 |
pub fn has_super_power(&self) -> bool { |
8ecdb5c6bb2a
implement info, registered only & super power messages
alfadur
parents:
14800
diff
changeset
|
76 |
self.contains(ClientFlags::HAS_SUPER_POWER) |
8ecdb5c6bb2a
implement info, registered only & super power messages
alfadur
parents:
14800
diff
changeset
|
77 |
} |
14812 | 78 |
pub fn is_registered(&self) -> bool { |
79 |
self.contains(ClientFlags::IS_REGISTERED) |
|
80 |
} |
|
13486 | 81 |
|
14478 | 82 |
pub fn set_is_admin(&mut self, value: bool) { |
83 |
self.set(ClientFlags::IS_ADMIN, value) |
|
84 |
} |
|
85 |
pub fn set_is_master(&mut self, value: bool) { |
|
86 |
self.set(ClientFlags::IS_MASTER, value) |
|
87 |
} |
|
88 |
pub fn set_is_ready(&mut self, value: bool) { |
|
89 |
self.set(ClientFlags::IS_READY, value) |
|
90 |
} |
|
91 |
pub fn set_is_in_game(&mut self, value: bool) { |
|
92 |
self.set(ClientFlags::IS_IN_GAME, value) |
|
93 |
} |
|
94 |
pub fn set_is_joined_mid_game(&mut self, value: bool) { |
|
95 |
self.set(ClientFlags::IS_JOINED_MID_GAME, value) |
|
96 |
} |
|
97 |
pub fn set_is_checker(&mut self, value: bool) { |
|
98 |
self.set(ClientFlags::IS_CHECKER, value) |
|
99 |
} |
|
14800
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14714
diff
changeset
|
100 |
pub fn set_is_contributor(&mut self, value: bool) { |
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14714
diff
changeset
|
101 |
self.set(ClientFlags::IS_CONTRIBUTOR, value) |
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14714
diff
changeset
|
102 |
} |
14807
8ecdb5c6bb2a
implement info, registered only & super power messages
alfadur
parents:
14800
diff
changeset
|
103 |
pub fn set_has_super_power(&mut self, value: bool) { |
8ecdb5c6bb2a
implement info, registered only & super power messages
alfadur
parents:
14800
diff
changeset
|
104 |
self.set(ClientFlags::HAS_SUPER_POWER, value) |
8ecdb5c6bb2a
implement info, registered only & super power messages
alfadur
parents:
14800
diff
changeset
|
105 |
} |
14812 | 106 |
pub fn set_is_registered(&mut self, value: bool) { |
107 |
self.set(ClientFlags::IS_REGISTERED, value) |
|
108 |
} |
|
14478 | 109 |
} |