--- a/gameServer2/src/server/client.rs Thu Mar 08 16:49:49 2018 +0100
+++ b/gameServer2/src/server/client.rs Thu Mar 08 15:01:18 2018 -0500
@@ -1,21 +1,7 @@
-use mio::net::TcpStream;
-use mio::*;
-use std::io::Write;
-use std::io;
-use netbuf;
-
-use utils;
-use protocol::ProtocolDecoder;
-use protocol::messages::*;
-use super::actions::Action::*;
-use super::actions::Action;
+pub type ClientId = usize;
pub struct HWClient {
- sock: TcpStream,
- decoder: ProtocolDecoder,
- buf_out: netbuf::Buf,
-
- pub id: usize,
+ pub id: ClientId,
pub room_id: Option<usize>,
pub nick: String,
pub protocol_number: u32,
@@ -25,14 +11,10 @@
}
impl HWClient {
- pub fn new(sock: TcpStream) -> HWClient {
+ pub fn new(id: ClientId) -> HWClient {
HWClient {
- sock: sock,
- decoder: ProtocolDecoder::new(),
- buf_out: netbuf::Buf::new(),
+ id,
room_id: None,
- id: 0,
-
nick: String::new(),
protocol_number: 0,
is_master: false,
@@ -40,58 +22,4 @@
is_joined_mid_game: false,
}
}
-
- pub fn register(&mut self, poll: &Poll, token: Token) {
- poll.register(&self.sock, token, Ready::readable() | Ready::writable(),
- PollOpt::edge())
- .ok().expect("could not register socket with event loop");
-
- self.send_msg(HWServerMessage::Connected(utils::PROTOCOL_VERSION));
- }
-
- pub fn deregister(&mut self, poll: &Poll) {
- poll.deregister(&self.sock)
- .ok().expect("could not deregister socket");
- }
-
- pub fn send_raw_msg(&mut self, msg: &[u8]) {
- self.buf_out.write(msg).unwrap();
- self.flush();
- }
-
- pub fn send_string(&mut self, msg: &String) {
- self.send_raw_msg(&msg.as_bytes());
- }
-
- pub fn send_msg(&mut self, msg: HWServerMessage) {
- self.send_string(&msg.to_raw_protocol());
- }
-
- fn flush(&mut self) {
- self.buf_out.write_to(&mut self.sock).unwrap();
- self.sock.flush();
- }
-
- pub fn readable(&mut self, _poll: &Poll) -> Vec<Action> {
- let v = self.decoder.read_from(&mut self.sock).unwrap();
- debug!("Read {} bytes", v);
- let mut response = Vec::new();
- {
- for msg in self.decoder.extract_messages() {
- response.push(ReactProtocolMessage(msg));
- }
- }
- self.decoder.sweep();
- response
- }
-
- pub fn writable(&mut self, _poll: &Poll) -> io::Result<()> {
- self.buf_out.write_to(&mut self.sock)?;
-
- Ok(())
- }
-
- pub fn error(&mut self, _poll: &Poll) -> Vec<Action> {
- return vec![ByeClient("Connection reset".to_string())]
- }
-}
+}
\ No newline at end of file