author | alfadur |
Wed, 04 Jul 2018 18:49:51 +0300 | |
changeset 13448 | 2501428303a2 |
parent 13424 | 81e0ed105f5d |
child 13449 | 914f9b970f4d |
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 => |
|
13424 | 18 |
server.react(token, vec![Pong.send_self().action()]), |
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 |
} |