author | Wuzzy <Wuzzy2@mail.ru> |
Wed, 14 Mar 2018 23:02:11 +0100 | |
changeset 13210 | 25ebc1ac0967 |
parent 13119 | 1e39b8749072 |
child 13419 | 81e0ed105f5d |
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 => |
|
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
18 |
server.react(token, vec![SendMe(Pong)]), |
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 |
} |