author | alfadur |
Tue, 09 Apr 2019 21:08:35 +0300 | |
changeset 14779 | f43ab2bd76ae |
parent 14693 | 6a2e13e36b7f |
child 14786 | 8ecdb5c6bb2a |
permissions | -rw-r--r-- |
13478 | 1 |
use super::coretypes::ClientId; |
13805 | 2 |
use bitflags::*; |
12128 | 3 |
|
14457 | 4 |
bitflags! { |
13522
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13520
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:
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; |
13798 | 11 |
const IS_CHECKER = 0b0010_0000; |
14779
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14693
diff
changeset
|
12 |
const IS_CONTRIBUTOR = 0b0100_0000; |
13529 | 13 |
|
14 |
const NONE = 0b0000_0000; |
|
15 |
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
|
16 |
} |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13520
diff
changeset
|
17 |
} |
13520 | 18 |
|
12128 | 19 |
pub struct HWClient { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12853
diff
changeset
|
20 |
pub id: ClientId, |
12852 | 21 |
pub room_id: Option<usize>, |
12141 | 22 |
pub nick: String, |
13520 | 23 |
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
|
24 |
pub flags: ClientFlags, |
13419 | 25 |
pub teams_in_game: u8, |
13423 | 26 |
pub team_indices: Vec<u8>, |
14457 | 27 |
pub clan: Option<u8>, |
12128 | 28 |
} |
29 |
||
30 |
impl HWClient { |
|
14693 | 31 |
pub fn new(id: ClientId, protocol_number: u16, nick: String) -> HWClient { |
12128 | 32 |
HWClient { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12853
diff
changeset
|
33 |
id, |
14693 | 34 |
nick, |
35 |
protocol_number, |
|
12146
8d8fb85bc09c
SendAllButMe action, list all clients in lobby in LobbyJoined message to newcomers
unc0rr
parents:
12144
diff
changeset
|
36 |
room_id: None, |
13529 | 37 |
flags: ClientFlags::DEFAULT, |
13419 | 38 |
teams_in_game: 0, |
13423 | 39 |
team_indices: Vec::new(), |
13419 | 40 |
clan: None, |
12128 | 41 |
} |
42 |
} |
|
13520 | 43 |
|
14457 | 44 |
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
|
45 |
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
|
46 |
} |
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 |
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
|
49 |
self.flags.set(mask, value); |
13520 | 50 |
} |
51 |
||
14457 | 52 |
pub fn is_admin(&self) -> bool { |
53 |
self.contains(ClientFlags::IS_ADMIN) |
|
54 |
} |
|
55 |
pub fn is_master(&self) -> bool { |
|
56 |
self.contains(ClientFlags::IS_MASTER) |
|
57 |
} |
|
58 |
pub fn is_ready(&self) -> bool { |
|
59 |
self.contains(ClientFlags::IS_READY) |
|
60 |
} |
|
61 |
pub fn is_in_game(&self) -> bool { |
|
62 |
self.contains(ClientFlags::IS_IN_GAME) |
|
63 |
} |
|
64 |
pub fn is_joined_mid_game(&self) -> bool { |
|
65 |
self.contains(ClientFlags::IS_JOINED_MID_GAME) |
|
66 |
} |
|
67 |
pub fn is_checker(&self) -> bool { |
|
68 |
self.contains(ClientFlags::IS_CHECKER) |
|
69 |
} |
|
14779
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14693
diff
changeset
|
70 |
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
|
71 |
self.contains(ClientFlags::IS_CONTRIBUTOR) |
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14693
diff
changeset
|
72 |
} |
13520 | 73 |
|
14457 | 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 |
} |
|
14779
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14693
diff
changeset
|
92 |
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
|
93 |
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
|
94 |
} |
14457 | 95 |
} |