author | alfadur |
Wed, 05 Sep 2018 19:22:29 +0300 | |
changeset 13803 | 4664da990556 |
parent 13534 | 662f7df89d06 |
child 13810 | 0463a4221327 |
permissions | -rw-r--r-- |
13483 | 1 |
use super::coretypes::ClientId; |
12133 | 2 |
|
13527
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
3 |
bitflags!{ |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
4 |
pub struct ClientFlags: u8 { |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
5 |
const IS_ADMIN = 0b0000_0001; |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
6 |
const IS_MASTER = 0b0000_0010; |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
7 |
const IS_READY = 0b0000_0100; |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
8 |
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:
13525
diff
changeset
|
9 |
const IS_JOINED_MID_GAME = 0b0001_0000; |
13803 | 10 |
const IS_CHECKER = 0b0010_0000; |
13534 | 11 |
|
12 |
const NONE = 0b0000_0000; |
|
13 |
const DEFAULT = Self::NONE.bits; |
|
13527
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
14 |
} |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
15 |
} |
13525 | 16 |
|
12133 | 17 |
pub struct HWClient { |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12858
diff
changeset
|
18 |
pub id: ClientId, |
12857 | 19 |
pub room_id: Option<usize>, |
12146 | 20 |
pub nick: String, |
13803 | 21 |
pub web_password: String, |
22 |
pub server_salt: String, |
|
13525 | 23 |
pub protocol_number: u16, |
13527
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
24 |
pub flags: ClientFlags, |
13424 | 25 |
pub teams_in_game: u8, |
13428 | 26 |
pub team_indices: Vec<u8>, |
13525 | 27 |
pub clan: Option<u8> |
12133 | 28 |
} |
29 |
||
30 |
impl HWClient { |
|
13803 | 31 |
pub fn new(id: ClientId, salt: String) -> HWClient { |
12133 | 32 |
HWClient { |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12858
diff
changeset
|
33 |
id, |
12151
8d8fb85bc09c
SendAllButMe action, list all clients in lobby in LobbyJoined message to newcomers
unc0rr
parents:
12149
diff
changeset
|
34 |
room_id: None, |
12146 | 35 |
nick: String::new(), |
13803 | 36 |
web_password: String::new(), |
37 |
server_salt: salt, |
|
12151
8d8fb85bc09c
SendAllButMe action, list all clients in lobby in LobbyJoined message to newcomers
unc0rr
parents:
12149
diff
changeset
|
38 |
protocol_number: 0, |
13534 | 39 |
flags: ClientFlags::DEFAULT, |
13424 | 40 |
teams_in_game: 0, |
13428 | 41 |
team_indices: Vec::new(), |
13424 | 42 |
clan: None, |
12133 | 43 |
} |
44 |
} |
|
13525 | 45 |
|
13527
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
46 |
fn contains(& self, mask: ClientFlags) -> bool { |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
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:
13525
diff
changeset
|
48 |
} |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
49 |
|
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
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:
13525
diff
changeset
|
51 |
self.flags.set(mask, value); |
13525 | 52 |
} |
53 |
||
13527
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
54 |
pub fn is_admin(&self)-> bool { self.contains(ClientFlags::IS_ADMIN) } |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
55 |
pub fn is_master(&self)-> bool { self.contains(ClientFlags::IS_MASTER) } |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
56 |
pub fn is_ready(&self)-> bool { self.contains(ClientFlags::IS_READY) } |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
57 |
pub fn is_in_game(&self)-> bool { self.contains(ClientFlags::IS_IN_GAME) } |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
58 |
pub fn is_joined_mid_game(&self)-> bool { self.contains(ClientFlags::IS_JOINED_MID_GAME) } |
13803 | 59 |
pub fn is_checker(&self)-> bool { self.contains(ClientFlags::IS_CHECKER) } |
13525 | 60 |
|
13527
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
61 |
pub fn set_is_admin(&mut self, value: bool) { self.set(ClientFlags::IS_ADMIN, value) } |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
62 |
pub fn set_is_master(&mut self, value: bool) { self.set(ClientFlags::IS_MASTER, value) } |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
63 |
pub fn set_is_ready(&mut self, value: bool) { self.set(ClientFlags::IS_READY, value) } |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
64 |
pub fn set_is_in_game(&mut self, value: bool) { self.set(ClientFlags::IS_IN_GAME, value) } |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13525
diff
changeset
|
65 |
pub fn set_is_joined_mid_game(&mut self, value: bool) { self.set(ClientFlags::IS_JOINED_MID_GAME, value) } |
13803 | 66 |
pub fn set_is_checker(&mut self, value: bool) { self.set(ClientFlags::IS_CHECKER, value) } |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12858
diff
changeset
|
67 |
} |