author | alfadur |
Wed, 31 Oct 2018 20:42:04 +0300 | |
changeset 14051 | e92cdb6d637e |
parent 13810 | 0463a4221327 |
permissions | -rw-r--r-- |
12154 | 1 |
use mio; |
13526 | 2 |
use std::{io, io::Write}; |
12154 | 3 |
|
13526 | 4 |
use super::{ |
5 |
server::HWServer, |
|
6 |
actions::{Action, Action::*}, |
|
7 |
coretypes::ClientId |
|
8 |
}; |
|
13671 | 9 |
use crate::{ |
10 |
protocol::messages::{ |
|
11 |
HWProtocolMessage, |
|
12 |
HWServerMessage::* |
|
13 |
} |
|
13526 | 14 |
}; |
13810 | 15 |
use log::*; |
13671 | 16 |
|
12154 | 17 |
mod loggingin; |
18 |
mod lobby; |
|
19 |
mod inroom; |
|
13671 | 20 |
mod common; |
13803 | 21 |
mod checker; |
12154 | 22 |
|
13526 | 23 |
pub fn handle(server: &mut HWServer, client_id: ClientId, message: HWProtocolMessage) { |
12154 | 24 |
match message { |
25 |
HWProtocolMessage::Ping => |
|
13526 | 26 |
server.react(client_id, vec![Pong.send_self().action()]), |
12154 | 27 |
HWProtocolMessage::Quit(Some(msg)) => |
13526 | 28 |
server.react(client_id, vec![ByeClient("User quit: ".to_string() + &msg)]), |
12154 | 29 |
HWProtocolMessage::Quit(None) => |
13526 | 30 |
server.react(client_id, vec![ByeClient("User quit".to_string())]), |
12154 | 31 |
HWProtocolMessage::Malformed => warn!("Malformed/unknown message"), |
32 |
HWProtocolMessage::Empty => warn!("Empty message"), |
|
33 |
_ => { |
|
13526 | 34 |
match server.clients[client_id].room_id { |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
35 |
None => |
13526 | 36 |
loggingin::handle(server, client_id, message), |
13124
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12857
diff
changeset
|
37 |
Some(id) if id == server.lobby_id => |
13526 | 38 |
lobby::handle(server, client_id, message), |
39 |
Some(id) => |
|
40 |
inroom::handle(server, client_id, id, message) |
|
12154 | 41 |
} |
42 |
}, |
|
43 |
} |
|
44 |
} |