author | unc0rr |
Thu, 08 Mar 2018 21:58:59 +0100 | |
changeset 13136 | f10f4bf5f84d |
parent 13124 | 1e39b8749072 |
child 13424 | 81e0ed105f5d |
permissions | -rw-r--r-- |
12154 | 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 |
||
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
15 |
pub fn handle(server: &mut HWServer, token: usize, message: HWProtocolMessage) { |
12154 | 16 |
match message { |
17 |
HWProtocolMessage::Ping => |
|
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
18 |
server.react(token, vec![SendMe(Pong)]), |
12154 | 19 |
HWProtocolMessage::Quit(Some(msg)) => |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
20 |
server.react(token, vec![ByeClient("User quit: ".to_string() + &msg)]), |
12154 | 21 |
HWProtocolMessage::Quit(None) => |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
22 |
server.react(token, vec![ByeClient("User quit".to_string())]), |
12154 | 23 |
HWProtocolMessage::Malformed => warn!("Malformed/unknown message"), |
24 |
HWProtocolMessage::Empty => warn!("Empty message"), |
|
25 |
_ => { |
|
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
26 |
match server.clients[token].room_id { |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
27 |
None => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
28 |
loggingin::handle(server, token, message), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
29 |
Some(id) if id == server.lobby_id => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
30 |
lobby::handle(server, token, message), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
31 |
_ => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
32 |
inroom::handle(server, token, message) |
12154 | 33 |
} |
34 |
}, |
|
35 |
} |
|
36 |
} |