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