12154
|
1 |
use mio;
|
13526
|
2 |
use std::{io, io::Write};
|
12154
|
3 |
|
13526
|
4 |
use super::{
|
14462
|
5 |
actions::{Action, Action::*},
|
14380
|
6 |
core::HWServer,
|
14462
|
7 |
coretypes::ClientId,
|
13526
|
8 |
};
|
14462
|
9 |
use crate::protocol::messages::{HWProtocolMessage, HWServerMessage::*};
|
13810
|
10 |
use log::*;
|
13671
|
11 |
|
14462
|
12 |
mod checker;
|
|
13 |
mod common;
|
12154
|
14 |
mod inroom;
|
14462
|
15 |
mod lobby;
|
|
16 |
mod loggingin;
|
12154
|
17 |
|
13526
|
18 |
pub fn handle(server: &mut HWServer, client_id: ClientId, message: HWProtocolMessage) {
|
12154
|
19 |
match message {
|
14462
|
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 |
}
|
12154
|
27 |
HWProtocolMessage::Malformed => warn!("Malformed/unknown message"),
|
|
28 |
HWProtocolMessage::Empty => warn!("Empty message"),
|
14462
|
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),
|
12154
|
33 |
},
|
|
34 |
}
|
|
35 |
}
|