author | Wuzzy <Wuzzy2@mail.ru> |
Wed, 19 Sep 2018 09:31:06 +0200 | |
changeset 13825 | 096cc009e0b8 |
parent 13666 | 09f4a30e50cc |
child 13771 | 4664da990556 |
permissions | -rw-r--r-- |
12149 | 1 |
use mio; |
13492 | 2 |
use std::{io, io::Write}; |
12149 | 3 |
|
13492 | 4 |
use super::{ |
5 |
server::HWServer, |
|
6 |
actions::{Action, Action::*}, |
|
7 |
coretypes::ClientId |
|
8 |
}; |
|
13666 | 9 |
use crate::{ |
10 |
protocol::messages::{ |
|
11 |
HWProtocolMessage, |
|
12 |
HWServerMessage::* |
|
13 |
} |
|
13492 | 14 |
}; |
13666 | 15 |
|
12149 | 16 |
mod loggingin; |
17 |
mod lobby; |
|
18 |
mod inroom; |
|
13666 | 19 |
mod common; |
12149 | 20 |
|
13492 | 21 |
pub fn handle(server: &mut HWServer, client_id: ClientId, message: HWProtocolMessage) { |
12149 | 22 |
match message { |
23 |
HWProtocolMessage::Ping => |
|
13492 | 24 |
server.react(client_id, vec![Pong.send_self().action()]), |
12149 | 25 |
HWProtocolMessage::Quit(Some(msg)) => |
13492 | 26 |
server.react(client_id, vec![ByeClient("User quit: ".to_string() + &msg)]), |
12149 | 27 |
HWProtocolMessage::Quit(None) => |
13492 | 28 |
server.react(client_id, vec![ByeClient("User quit".to_string())]), |
12149 | 29 |
HWProtocolMessage::Malformed => warn!("Malformed/unknown message"), |
30 |
HWProtocolMessage::Empty => warn!("Empty message"), |
|
31 |
_ => { |
|
13492 | 32 |
match server.clients[client_id].room_id { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
33 |
None => |
13492 | 34 |
loggingin::handle(server, client_id, message), |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
35 |
Some(id) if id == server.lobby_id => |
13492 | 36 |
lobby::handle(server, client_id, message), |
37 |
Some(id) => |
|
38 |
inroom::handle(server, client_id, id, message) |
|
12149 | 39 |
} |
40 |
}, |
|
41 |
} |
|
42 |
} |