author | alfadur |
Sat, 22 Feb 2025 19:39:31 +0300 | |
changeset 16120 | 5febd2bc5372 |
parent 16018 | fb389df02e3e |
permissions | -rw-r--r-- |
15095 | 1 |
use super::types::ClientId; |
13810 | 2 |
use bitflags::*; |
16120
5febd2bc5372
Add server reconnection tokens and anteroom local list of used nicks
alfadur
parents:
16018
diff
changeset
|
3 |
use std::ops::Deref; |
12128 | 4 |
|
14478 | 5 |
bitflags! { |
16120
5febd2bc5372
Add server reconnection tokens and anteroom local list of used nicks
alfadur
parents:
16018
diff
changeset
|
6 |
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
|
7 |
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
|
8 |
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
|
9 |
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
|
10 |
const IS_IN_GAME = 0b0000_1000; |
15591 | 11 |
const IS_CONTRIBUTOR = 0b0001_0000; |
12 |
const HAS_SUPER_POWER = 0b0010_0000; |
|
13 |
const IS_REGISTERED = 0b0100_0000; |
|
15960
ab57c0d81748
add a client moderator flag just to commit something
alfadur
parents:
15591
diff
changeset
|
14 |
const IS_MODERATOR = 0b1000_0000; |
16120
5febd2bc5372
Add server reconnection tokens and anteroom local list of used nicks
alfadur
parents:
16018
diff
changeset
|
15 |
const IS_REJOINED = 0b1_0000_0000; |
13529 | 16 |
|
17 |
const NONE = 0b0000_0000; |
|
18 |
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
|
19 |
} |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
20 |
} |
13486 | 21 |
|
15096 | 22 |
pub struct HwClient { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12853
diff
changeset
|
23 |
pub id: ClientId, |
12852 | 24 |
pub room_id: Option<usize>, |
12141 | 25 |
pub nick: String, |
13486 | 26 |
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
|
27 |
pub flags: ClientFlags, |
13419 | 28 |
pub teams_in_game: u8, |
13423 | 29 |
pub team_indices: Vec<u8>, |
14478 | 30 |
pub clan: Option<u8>, |
12128 | 31 |
} |
32 |
||
15096 | 33 |
impl HwClient { |
34 |
pub fn new(id: ClientId, protocol_number: u16, nick: String) -> HwClient { |
|
16018 | 35 |
//todo!("add quiet flag"); |
15096 | 36 |
HwClient { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12853
diff
changeset
|
37 |
id, |
14714 | 38 |
nick, |
39 |
protocol_number, |
|
12146
8d8fb85bc09c
SendAllButMe action, list all clients in lobby in LobbyJoined message to newcomers
unc0rr
parents:
12144
diff
changeset
|
40 |
room_id: None, |
13529 | 41 |
flags: ClientFlags::DEFAULT, |
13419 | 42 |
teams_in_game: 0, |
13423 | 43 |
team_indices: Vec::new(), |
13419 | 44 |
clan: None, |
12128 | 45 |
} |
46 |
} |
|
13486 | 47 |
|
14478 | 48 |
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
|
49 |
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
|
50 |
} |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
51 |
|
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13486
diff
changeset
|
52 |
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
|
53 |
self.flags.set(mask, value); |
13486 | 54 |
} |
55 |
||
14478 | 56 |
pub fn is_admin(&self) -> bool { |
57 |
self.contains(ClientFlags::IS_ADMIN) |
|
58 |
} |
|
59 |
pub fn is_master(&self) -> bool { |
|
60 |
self.contains(ClientFlags::IS_MASTER) |
|
61 |
} |
|
62 |
pub fn is_ready(&self) -> bool { |
|
63 |
self.contains(ClientFlags::IS_READY) |
|
64 |
} |
|
65 |
pub fn is_in_game(&self) -> bool { |
|
66 |
self.contains(ClientFlags::IS_IN_GAME) |
|
67 |
} |
|
14800
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14714
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:
14714
diff
changeset
|
69 |
self.contains(ClientFlags::IS_CONTRIBUTOR) |
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14714
diff
changeset
|
70 |
} |
14807
8ecdb5c6bb2a
implement info, registered only & super power messages
alfadur
parents:
14800
diff
changeset
|
71 |
pub fn has_super_power(&self) -> bool { |
8ecdb5c6bb2a
implement info, registered only & super power messages
alfadur
parents:
14800
diff
changeset
|
72 |
self.contains(ClientFlags::HAS_SUPER_POWER) |
8ecdb5c6bb2a
implement info, registered only & super power messages
alfadur
parents:
14800
diff
changeset
|
73 |
} |
14812 | 74 |
pub fn is_registered(&self) -> bool { |
75 |
self.contains(ClientFlags::IS_REGISTERED) |
|
76 |
} |
|
16120
5febd2bc5372
Add server reconnection tokens and anteroom local list of used nicks
alfadur
parents:
16018
diff
changeset
|
77 |
pub fn is_rejoined(&self) -> bool { |
5febd2bc5372
Add server reconnection tokens and anteroom local list of used nicks
alfadur
parents:
16018
diff
changeset
|
78 |
self.contains(ClientFlags::IS_REJOINED) |
5febd2bc5372
Add server reconnection tokens and anteroom local list of used nicks
alfadur
parents:
16018
diff
changeset
|
79 |
} |
13486 | 80 |
|
14478 | 81 |
pub fn set_is_admin(&mut self, value: bool) { |
82 |
self.set(ClientFlags::IS_ADMIN, value) |
|
83 |
} |
|
84 |
pub fn set_is_master(&mut self, value: bool) { |
|
85 |
self.set(ClientFlags::IS_MASTER, value) |
|
86 |
} |
|
87 |
pub fn set_is_ready(&mut self, value: bool) { |
|
88 |
self.set(ClientFlags::IS_READY, value) |
|
89 |
} |
|
90 |
pub fn set_is_in_game(&mut self, value: bool) { |
|
91 |
self.set(ClientFlags::IS_IN_GAME, value) |
|
92 |
} |
|
14800
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14714
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:
14714
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:
14714
diff
changeset
|
95 |
} |
14807
8ecdb5c6bb2a
implement info, registered only & super power messages
alfadur
parents:
14800
diff
changeset
|
96 |
pub fn set_has_super_power(&mut self, value: bool) { |
8ecdb5c6bb2a
implement info, registered only & super power messages
alfadur
parents:
14800
diff
changeset
|
97 |
self.set(ClientFlags::HAS_SUPER_POWER, value) |
8ecdb5c6bb2a
implement info, registered only & super power messages
alfadur
parents:
14800
diff
changeset
|
98 |
} |
14812 | 99 |
pub fn set_is_registered(&mut self, value: bool) { |
100 |
self.set(ClientFlags::IS_REGISTERED, value) |
|
101 |
} |
|
16120
5febd2bc5372
Add server reconnection tokens and anteroom local list of used nicks
alfadur
parents:
16018
diff
changeset
|
102 |
pub fn set_is_rejoined(&mut self, value: bool) { |
5febd2bc5372
Add server reconnection tokens and anteroom local list of used nicks
alfadur
parents:
16018
diff
changeset
|
103 |
self.set(ClientFlags::IS_REJOINED, value) |
5febd2bc5372
Add server reconnection tokens and anteroom local list of used nicks
alfadur
parents:
16018
diff
changeset
|
104 |
} |
14478 | 105 |
} |