author | unc0rr |
Mon, 10 Dec 2018 22:44:46 +0100 | |
changeset 14415 | 06672690d71b |
parent 14375 | gameServer2/src/server/handlers.rs@cc99f7c673c7 |
child 14457 | 98ef2913ec73 |
permissions | -rw-r--r-- |
12149 | 1 |
use mio; |
13521 | 2 |
use std::{io, io::Write}; |
12149 | 3 |
|
13521 | 4 |
use super::{ |
14375 | 5 |
core::HWServer, |
13521 | 6 |
actions::{Action, Action::*}, |
7 |
coretypes::ClientId |
|
8 |
}; |
|
13666 | 9 |
use crate::{ |
10 |
protocol::messages::{ |
|
11 |
HWProtocolMessage, |
|
12 |
HWServerMessage::* |
|
13 |
} |
|
13521 | 14 |
}; |
13805 | 15 |
use log::*; |
13666 | 16 |
|
12149 | 17 |
mod loggingin; |
18 |
mod lobby; |
|
19 |
mod inroom; |
|
13666 | 20 |
mod common; |
13798 | 21 |
mod checker; |
12149 | 22 |
|
13521 | 23 |
pub fn handle(server: &mut HWServer, client_id: ClientId, message: HWProtocolMessage) { |
12149 | 24 |
match message { |
25 |
HWProtocolMessage::Ping => |
|
13521 | 26 |
server.react(client_id, vec![Pong.send_self().action()]), |
12149 | 27 |
HWProtocolMessage::Quit(Some(msg)) => |
13521 | 28 |
server.react(client_id, vec![ByeClient("User quit: ".to_string() + &msg)]), |
12149 | 29 |
HWProtocolMessage::Quit(None) => |
13521 | 30 |
server.react(client_id, vec![ByeClient("User quit".to_string())]), |
12149 | 31 |
HWProtocolMessage::Malformed => warn!("Malformed/unknown message"), |
32 |
HWProtocolMessage::Empty => warn!("Empty message"), |
|
33 |
_ => { |
|
13521 | 34 |
match server.clients[client_id].room_id { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
35 |
None => |
13521 | 36 |
loggingin::handle(server, client_id, message), |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
37 |
Some(id) if id == server.lobby_id => |
13521 | 38 |
lobby::handle(server, client_id, message), |
39 |
Some(id) => |
|
40 |
inroom::handle(server, client_id, id, message) |
|
12149 | 41 |
} |
42 |
}, |
|
43 |
} |
|
44 |
} |