author | Wuzzy <Wuzzy2@mail.ru> |
Tue, 31 Jul 2018 01:00:27 +0200 | |
changeset 13577 | 66460d5f0d9b |
parent 13529 | 662f7df89d06 |
child 13798 | 4664da990556 |
permissions | -rw-r--r-- |
13478 | 1 |
use super::coretypes::ClientId; |
12128 | 2 |
|
13522
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13520
diff
changeset
|
3 |
bitflags!{ |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13520
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:
13520
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:
13520
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:
13520
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:
13520
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:
13520
diff
changeset
|
9 |
const IS_JOINED_MID_GAME = 0b0001_0000; |
13529 | 10 |
|
11 |
const NONE = 0b0000_0000; |
|
12 |
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
|
13 |
} |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13520
diff
changeset
|
14 |
} |
13520 | 15 |
|
12128 | 16 |
pub struct HWClient { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12853
diff
changeset
|
17 |
pub id: ClientId, |
12852 | 18 |
pub room_id: Option<usize>, |
12141 | 19 |
pub nick: String, |
13520 | 20 |
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
|
21 |
pub flags: ClientFlags, |
13419 | 22 |
pub teams_in_game: u8, |
13423 | 23 |
pub team_indices: Vec<u8>, |
13520 | 24 |
pub clan: Option<u8> |
12128 | 25 |
} |
26 |
||
27 |
impl HWClient { |
|
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12853
diff
changeset
|
28 |
pub fn new(id: ClientId) -> HWClient { |
12128 | 29 |
HWClient { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12853
diff
changeset
|
30 |
id, |
12146
8d8fb85bc09c
SendAllButMe action, list all clients in lobby in LobbyJoined message to newcomers
unc0rr
parents:
12144
diff
changeset
|
31 |
room_id: None, |
12141 | 32 |
nick: String::new(), |
12146
8d8fb85bc09c
SendAllButMe action, list all clients in lobby in LobbyJoined message to newcomers
unc0rr
parents:
12144
diff
changeset
|
33 |
protocol_number: 0, |
13529 | 34 |
flags: ClientFlags::DEFAULT, |
13419 | 35 |
teams_in_game: 0, |
13423 | 36 |
team_indices: Vec::new(), |
13419 | 37 |
clan: None, |
12128 | 38 |
} |
39 |
} |
|
13520 | 40 |
|
13522
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13520
diff
changeset
|
41 |
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:
13520
diff
changeset
|
42 |
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
|
43 |
} |
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13520
diff
changeset
|
44 |
|
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13520
diff
changeset
|
45 |
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
|
46 |
self.flags.set(mask, value); |
13520 | 47 |
} |
48 |
||
13522
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13520
diff
changeset
|
49 |
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:
13520
diff
changeset
|
50 |
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:
13520
diff
changeset
|
51 |
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:
13520
diff
changeset
|
52 |
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:
13520
diff
changeset
|
53 |
pub fn is_joined_mid_game(&self)-> bool { self.contains(ClientFlags::IS_JOINED_MID_GAME) } |
13520 | 54 |
|
13522
282e5e54386f
Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents:
13520
diff
changeset
|
55 |
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:
13520
diff
changeset
|
56 |
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:
13520
diff
changeset
|
57 |
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:
13520
diff
changeset
|
58 |
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:
13520
diff
changeset
|
59 |
pub fn set_is_joined_mid_game(&mut self, value: bool) { self.set(ClientFlags::IS_JOINED_MID_GAME, value) } |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12853
diff
changeset
|
60 |
} |