gameServer2/src/server/client.rs
changeset 12137 193dfdcb0620
parent 12136 e25a82ce2374
child 12138 e0bf51609062
--- a/gameServer2/src/server/client.rs	Sat Jan 14 00:46:52 2017 +0300
+++ b/gameServer2/src/server/client.rs	Sat Jan 14 22:30:09 2017 +0300
@@ -9,6 +9,7 @@
 use protocol::ProtocolDecoder;
 use protocol::messages;
 use protocol::messages::HWProtocolMessage::*;
+use log;
 
 pub struct HWClient {
     sock: TcpStream,
@@ -26,13 +27,11 @@
     }
 
     pub fn register(&mut self, poll: &Poll, token: Token) {
-        poll.register(&self.sock, token, Ready::readable(),
+        poll.register(&self.sock, token, Ready::all(),
                       PollOpt::edge())
             .ok().expect("could not register socket with event loop");
 
-        self.send_raw_msg(
-            format!("CONNECTED\nHedgewars server http://www.hedgewars.org/\n{}\n\n"
-                    , utils::PROTOCOL_VERSION).as_bytes());
+        self.send_msg(Connected(utils::PROTOCOL_VERSION));
     }
 
     fn send_raw_msg(&mut self, msg: &[u8]) {
@@ -51,14 +50,16 @@
 
     pub fn readable(&mut self, poll: &Poll) -> io::Result<()> {
         let v = self.decoder.read_from(&mut self.sock)?;
-        println!("Read {} bytes", v);
+        debug!("Read {} bytes", v);
         let mut response = Vec::new();
         {
             let msgs = self.decoder.extract_messages();
             for msg in msgs {
                 match msg {
                     Ping => response.push(Pong),
-                    _ => println!("Unknown message")
+                    Malformed => warn!("Malformed/unknown message"),
+                    Empty => warn!("Empty message"),
+                    _ => unimplemented!(),
                 }
             }
         }
@@ -73,4 +74,9 @@
         self.buf_out.write_to(&mut self.sock)?;
         Ok(())
     }
+
+    pub fn error(&mut self, poll: &Poll) -> io::Result<()> {
+        debug!("Client error");
+        Ok(())
+    }
 }