gameServer2/src/server/client.rs
changeset 12139 f3121d7dedec
parent 12138 e0bf51609062
child 12141 78925eff02c2
equal deleted inserted replaced
12138:e0bf51609062 12139:f3121d7dedec
    34             .ok().expect("could not register socket with event loop");
    34             .ok().expect("could not register socket with event loop");
    35 
    35 
    36         self.send_msg(Connected(utils::PROTOCOL_VERSION));
    36         self.send_msg(Connected(utils::PROTOCOL_VERSION));
    37     }
    37     }
    38 
    38 
       
    39     pub fn deregister(&mut self, poll: &Poll) {
       
    40         poll.deregister(&self.sock);
       
    41     }
       
    42 
    39     pub fn send_raw_msg(&mut self, msg: &[u8]) {
    43     pub fn send_raw_msg(&mut self, msg: &[u8]) {
    40         self.buf_out.write(msg).unwrap();
    44         self.buf_out.write(msg).unwrap();
    41         self.flush();
    45         self.flush();
    42     }
    46     }
    43 
    47 
    61         {
    65         {
    62             let msgs = self.decoder.extract_messages();
    66             let msgs = self.decoder.extract_messages();
    63             for msg in msgs {
    67             for msg in msgs {
    64                 match msg {
    68                 match msg {
    65                     Ping => response.push(SendMe(Pong.to_raw_protocol())),
    69                     Ping => response.push(SendMe(Pong.to_raw_protocol())),
       
    70                     Quit(Some(msg)) => response.push(ByeClient("User quit: ".to_string() + msg)),
       
    71                     Quit(None) => response.push(ByeClient("User quit".to_string())),
    66                     Malformed => warn!("Malformed/unknown message"),
    72                     Malformed => warn!("Malformed/unknown message"),
    67                     Empty => warn!("Empty message"),
    73                     Empty => warn!("Empty message"),
    68                     _ => unimplemented!(),
    74                     _ => unimplemented!(),
    69                 }
    75                 }
    70             }
    76             }
    73         response
    79         response
    74     }
    80     }
    75 
    81 
    76     pub fn writable(&mut self, poll: &Poll) -> io::Result<()> {
    82     pub fn writable(&mut self, poll: &Poll) -> io::Result<()> {
    77         self.buf_out.write_to(&mut self.sock)?;
    83         self.buf_out.write_to(&mut self.sock)?;
       
    84 
    78         Ok(())
    85         Ok(())
    79     }
    86     }
    80 
    87 
    81     pub fn error(&mut self, poll: &Poll) -> io::Result<()> {
    88     pub fn error(&mut self, poll: &Poll) -> Vec<Action> {
    82         debug!("Client error");
    89         return vec![ByeClient("Connection reset".to_string())]
    83         Ok(())
       
    84     }
    90     }
    85 }
    91 }