gameServer2/src/server/client.rs
changeset 12141 78925eff02c2
parent 12139 f3121d7dedec
child 12142 4d7d41be1993
--- a/gameServer2/src/server/client.rs	Wed Jan 18 22:23:41 2017 +0300
+++ b/gameServer2/src/server/client.rs	Wed Jan 18 22:54:02 2017 +0300
@@ -16,15 +16,19 @@
 pub struct HWClient {
     sock: TcpStream,
     decoder: ProtocolDecoder,
-    buf_out: netbuf::Buf
+    buf_out: netbuf::Buf,
+    pub nick: String,
+    roomId: Token,
 }
 
 impl HWClient {
-    pub fn new(sock: TcpStream) -> HWClient {
+    pub fn new(sock: TcpStream, roomId: &Token) -> HWClient {
         HWClient {
             sock: sock,
             decoder: ProtocolDecoder::new(),
             buf_out: netbuf::Buf::new(),
+            nick: String::new(),
+            roomId: roomId.clone(),
         }
     }
 
@@ -69,6 +73,9 @@
                     Ping => response.push(SendMe(Pong.to_raw_protocol())),
                     Quit(Some(msg)) => response.push(ByeClient("User quit: ".to_string() + msg)),
                     Quit(None) => response.push(ByeClient("User quit".to_string())),
+                    Nick(nick) => if self.nick.len() == 0 {
+                        response.push(SetNick(nick.to_string()));
+                    },
                     Malformed => warn!("Malformed/unknown message"),
                     Empty => warn!("Empty message"),
                     _ => unimplemented!(),