gameServer2/src/server/client.rs
changeset 13520 1ee192f13456
parent 13478 d79795acaa73
child 13522 282e5e54386f
--- a/gameServer2/src/server/client.rs	Thu Jul 12 14:46:16 2018 +0200
+++ b/gameServer2/src/server/client.rs	Fri Jul 13 19:52:19 2018 +0300
@@ -1,18 +1,20 @@
 use super::coretypes::ClientId;
 
+const IS_ADMIN: u8 = 0b0000_0001;
+const IS_MASTER: u8 = 0b0000_0010;
+const IS_READY: u8 = 0b0000_0100;
+const IS_IN_GAME: u8 = 0b0000_1000;
+const IS_JOINED_MID_GAME: u8 = 0b0001_0000;
+
 pub struct HWClient {
     pub id: ClientId,
     pub room_id: Option<usize>,
     pub nick: String,
-    pub protocol_number: u32,
-    pub is_admin: bool,
-    pub is_master: bool,
-    pub is_ready: bool,
-    pub is_in_game: bool,
+    pub protocol_number: u16,
+    flags: u8,
     pub teams_in_game: u8,
     pub team_indices: Vec<u8>,
-    pub clan: Option<u8>,
-    pub is_joined_mid_game: bool,
+    pub clan: Option<u8>
 }
 
 impl HWClient {
@@ -22,14 +24,26 @@
             room_id: None,
             nick: String::new(),
             protocol_number: 0,
-            is_admin: false,
-            is_master: false,
-            is_ready: false,
-            is_in_game: false,
+            flags: 0,
             teams_in_game: 0,
             team_indices: Vec::new(),
             clan: None,
-            is_joined_mid_game: false,
         }
     }
+
+    fn set(&mut self, mask: u8, value: bool) {
+        if value { self.flags |= mask } else { self.flags &= !mask }
+    }
+
+    pub fn is_admin(&self)-> bool { self.flags & IS_ADMIN != 0 }
+    pub fn is_master(&self)-> bool { self.flags & IS_MASTER != 0 }
+    pub fn is_ready(&self)-> bool { self.flags & IS_READY != 0 }
+    pub fn is_in_game(&self)-> bool { self.flags & IS_IN_GAME != 0 }
+    pub fn is_joined_mid_game(&self)-> bool { self.flags & IS_JOINED_MID_GAME != 0 }
+
+    pub fn set_is_admin(&mut self, value: bool) { self.set(IS_ADMIN, value) }
+    pub fn set_is_master(&mut self, value: bool) { self.set(IS_MASTER, value) }
+    pub fn set_is_ready(&mut self, value: bool) { self.set(IS_READY, value) }
+    pub fn set_is_in_game(&mut self, value: bool) { self.set(IS_IN_GAME, value) }
+    pub fn set_is_joined_mid_game(&mut self, value: bool) { self.set(IS_JOINED_MID_GAME, value) }
 }
\ No newline at end of file