1 use mio; |
1 use mio; |
2 use std::io::Write; |
2 use std::{io, io::Write}; |
3 use std::io; |
|
4 |
3 |
5 use super::server::HWServer; |
4 use super::{ |
6 use super::actions::Action; |
5 server::HWServer, |
7 use super::actions::Action::*; |
6 actions::{Action, Action::*}, |
8 use protocol::messages::HWProtocolMessage; |
7 coretypes::ClientId |
9 use protocol::messages::HWServerMessage::*; |
8 }; |
10 |
9 use protocol::messages::{ |
|
10 HWProtocolMessage, |
|
11 HWServerMessage::* |
|
12 }; |
11 mod common; |
13 mod common; |
12 mod loggingin; |
14 mod loggingin; |
13 mod lobby; |
15 mod lobby; |
14 mod inroom; |
16 mod inroom; |
15 |
17 |
16 pub fn handle(server: &mut HWServer, token: usize, message: HWProtocolMessage) { |
18 pub fn handle(server: &mut HWServer, client_id: ClientId, message: HWProtocolMessage) { |
17 match message { |
19 match message { |
18 HWProtocolMessage::Ping => |
20 HWProtocolMessage::Ping => |
19 server.react(token, vec![Pong.send_self().action()]), |
21 server.react(client_id, vec![Pong.send_self().action()]), |
20 HWProtocolMessage::Quit(Some(msg)) => |
22 HWProtocolMessage::Quit(Some(msg)) => |
21 server.react(token, vec![ByeClient("User quit: ".to_string() + &msg)]), |
23 server.react(client_id, vec![ByeClient("User quit: ".to_string() + &msg)]), |
22 HWProtocolMessage::Quit(None) => |
24 HWProtocolMessage::Quit(None) => |
23 server.react(token, vec![ByeClient("User quit".to_string())]), |
25 server.react(client_id, vec![ByeClient("User quit".to_string())]), |
24 HWProtocolMessage::Malformed => warn!("Malformed/unknown message"), |
26 HWProtocolMessage::Malformed => warn!("Malformed/unknown message"), |
25 HWProtocolMessage::Empty => warn!("Empty message"), |
27 HWProtocolMessage::Empty => warn!("Empty message"), |
26 _ => { |
28 _ => { |
27 match server.clients[token].room_id { |
29 match server.clients[client_id].room_id { |
28 None => |
30 None => |
29 loggingin::handle(server, token, message), |
31 loggingin::handle(server, client_id, message), |
30 Some(id) if id == server.lobby_id => |
32 Some(id) if id == server.lobby_id => |
31 lobby::handle(server, token, message), |
33 lobby::handle(server, client_id, message), |
32 _ => |
34 Some(id) => |
33 inroom::handle(server, token, message) |
35 inroom::handle(server, client_id, id, message) |
34 } |
36 } |
35 }, |
37 }, |
36 } |
38 } |
37 } |
39 } |