12149
|
1 |
use mio;
|
13521
|
2 |
use std::{io, io::Write};
|
12149
|
3 |
|
13521
|
4 |
use super::{
|
14457
|
5 |
actions::{Action, Action::*},
|
14375
|
6 |
core::HWServer,
|
14457
|
7 |
coretypes::ClientId,
|
13521
|
8 |
};
|
14457
|
9 |
use crate::protocol::messages::{HWProtocolMessage, HWServerMessage::*};
|
13805
|
10 |
use log::*;
|
13666
|
11 |
|
14457
|
12 |
mod checker;
|
|
13 |
mod common;
|
12149
|
14 |
mod inroom;
|
14457
|
15 |
mod lobby;
|
|
16 |
mod loggingin;
|
12149
|
17 |
|
13521
|
18 |
pub fn handle(server: &mut HWServer, client_id: ClientId, message: HWProtocolMessage) {
|
12149
|
19 |
match message {
|
14457
|
20 |
HWProtocolMessage::Ping => server.react(client_id, vec![Pong.send_self().action()]),
|
|
21 |
HWProtocolMessage::Quit(Some(msg)) => {
|
|
22 |
server.react(client_id, vec![ByeClient("User quit: ".to_string() + &msg)])
|
|
23 |
}
|
|
24 |
HWProtocolMessage::Quit(None) => {
|
|
25 |
server.react(client_id, vec![ByeClient("User quit".to_string())])
|
|
26 |
}
|
12149
|
27 |
HWProtocolMessage::Malformed => warn!("Malformed/unknown message"),
|
|
28 |
HWProtocolMessage::Empty => warn!("Empty message"),
|
14457
|
29 |
_ => match server.clients[client_id].room_id {
|
|
30 |
None => loggingin::handle(server, client_id, message),
|
|
31 |
Some(id) if id == server.lobby_id => lobby::handle(server, client_id, message),
|
|
32 |
Some(id) => inroom::handle(server, client_id, id, message),
|
12149
|
33 |
},
|
|
34 |
}
|
|
35 |
}
|