author | alfadur |
Tue, 17 Jul 2018 00:27:24 +0300 | |
changeset 13494 | 8c5dd562c9f7 |
parent 13492 | ba5211dddb21 |
child 13666 | 09f4a30e50cc |
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 |
}; |
|
9 |
use protocol::messages::{ |
|
10 |
HWProtocolMessage, |
|
11 |
HWServerMessage::* |
|
12 |
}; |
|
13444
914f9b970f4d
Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents:
13419
diff
changeset
|
13 |
mod common; |
12149 | 14 |
mod loggingin; |
15 |
mod lobby; |
|
16 |
mod inroom; |
|
17 |
||
13492 | 18 |
pub fn handle(server: &mut HWServer, client_id: ClientId, message: HWProtocolMessage) { |
12149 | 19 |
match message { |
20 |
HWProtocolMessage::Ping => |
|
13492 | 21 |
server.react(client_id, vec![Pong.send_self().action()]), |
12149 | 22 |
HWProtocolMessage::Quit(Some(msg)) => |
13492 | 23 |
server.react(client_id, vec![ByeClient("User quit: ".to_string() + &msg)]), |
12149 | 24 |
HWProtocolMessage::Quit(None) => |
13492 | 25 |
server.react(client_id, vec![ByeClient("User quit".to_string())]), |
12149 | 26 |
HWProtocolMessage::Malformed => warn!("Malformed/unknown message"), |
27 |
HWProtocolMessage::Empty => warn!("Empty message"), |
|
28 |
_ => { |
|
13492 | 29 |
match server.clients[client_id].room_id { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
30 |
None => |
13492 | 31 |
loggingin::handle(server, client_id, message), |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
32 |
Some(id) if id == server.lobby_id => |
13492 | 33 |
lobby::handle(server, client_id, message), |
34 |
Some(id) => |
|
35 |
inroom::handle(server, client_id, id, message) |
|
12149 | 36 |
} |
37 |
}, |
|
38 |
} |
|
39 |
} |