author | Marcin Mielniczuk <marmistrz.dev@zoho.eu> |
Fri, 06 Jul 2018 16:27:25 +0200 | |
changeset 13449 | 914f9b970f4d |
parent 13424 | 81e0ed105f5d |
child 13526 | ba5211dddb21 |
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 |
||
13449
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13424
diff
changeset
|
11 |
mod common; |
12154 | 12 |
mod loggingin; |
13 |
mod lobby; |
|
14 |
mod inroom; |
|
15 |
||
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
16 |
pub fn handle(server: &mut HWServer, token: usize, message: HWProtocolMessage) { |
12154 | 17 |
match message { |
18 |
HWProtocolMessage::Ping => |
|
13424 | 19 |
server.react(token, vec![Pong.send_self().action()]), |
12154 | 20 |
HWProtocolMessage::Quit(Some(msg)) => |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
21 |
server.react(token, vec![ByeClient("User quit: ".to_string() + &msg)]), |
12154 | 22 |
HWProtocolMessage::Quit(None) => |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
23 |
server.react(token, vec![ByeClient("User quit".to_string())]), |
12154 | 24 |
HWProtocolMessage::Malformed => warn!("Malformed/unknown message"), |
25 |
HWProtocolMessage::Empty => warn!("Empty message"), |
|
26 |
_ => { |
|
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
27 |
match server.clients[token].room_id { |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
28 |
None => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
29 |
loggingin::handle(server, token, message), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
30 |
Some(id) if id == server.lobby_id => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
31 |
lobby::handle(server, token, message), |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
32 |
_ => |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
33 |
inroom::handle(server, token, message) |
12154 | 34 |
} |
35 |
}, |
|
36 |
} |
|
37 |
} |