author | alfadur |
Wed, 27 Jun 2018 02:34:46 +0300 | |
changeset 13423 | 87a6cad20c90 |
parent 13419 | 81e0ed105f5d |
child 13444 | 914f9b970f4d |
permissions | -rw-r--r-- |
12149 | 1 |
use mio; |
2 |
use std::io::Write; |
|
3 |
use std::io; |
|
4 |
||
5 |
use super::server::HWServer; |
|
6 |
use super::actions::Action; |
|
7 |
use super::actions::Action::*; |
|
8 |
use protocol::messages::HWProtocolMessage; |
|
9 |
use protocol::messages::HWServerMessage::*; |
|
10 |
||
11 |
mod loggingin; |
|
12 |
mod lobby; |
|
13 |
mod inroom; |
|
14 |
||
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
15 |
pub fn handle(server: &mut HWServer, token: usize, message: HWProtocolMessage) { |
12149 | 16 |
match message { |
17 |
HWProtocolMessage::Ping => |
|
13419 | 18 |
server.react(token, vec![Pong.send_self().action()]), |
12149 | 19 |
HWProtocolMessage::Quit(Some(msg)) => |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
20 |
server.react(token, vec![ByeClient("User quit: ".to_string() + &msg)]), |
12149 | 21 |
HWProtocolMessage::Quit(None) => |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
22 |
server.react(token, vec![ByeClient("User quit".to_string())]), |
12149 | 23 |
HWProtocolMessage::Malformed => warn!("Malformed/unknown message"), |
24 |
HWProtocolMessage::Empty => warn!("Empty message"), |
|
25 |
_ => { |
|
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
26 |
match server.clients[token].room_id { |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
27 |
None => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
28 |
loggingin::handle(server, token, message), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
29 |
Some(id) if id == server.lobby_id => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
30 |
lobby::handle(server, token, message), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
31 |
_ => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
32 |
inroom::handle(server, token, message) |
12149 | 33 |
} |
34 |
}, |
|
35 |
} |
|
36 |
} |