author | alfadur |
Tue, 17 Jul 2018 16:03:34 +0300 | |
changeset 13524 | 5359ff75da3a |
parent 13521 | ba5211dddb21 |
child 13666 | 09f4a30e50cc |
permissions | -rw-r--r-- |
12149 | 1 |
use mio; |
13521 | 2 |
use std::{io, io::Write}; |
12149 | 3 |
|
13521 | 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 |
||
13521 | 18 |
pub fn handle(server: &mut HWServer, client_id: ClientId, message: HWProtocolMessage) { |
12149 | 19 |
match message { |
20 |
HWProtocolMessage::Ping => |
|
13521 | 21 |
server.react(client_id, vec![Pong.send_self().action()]), |
12149 | 22 |
HWProtocolMessage::Quit(Some(msg)) => |
13521 | 23 |
server.react(client_id, vec![ByeClient("User quit: ".to_string() + &msg)]), |
12149 | 24 |
HWProtocolMessage::Quit(None) => |
13521 | 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 |
_ => { |
|
13521 | 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 => |
13521 | 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 => |
13521 | 33 |
lobby::handle(server, client_id, message), |
34 |
Some(id) => |
|
35 |
inroom::handle(server, client_id, id, message) |
|
12149 | 36 |
} |
37 |
}, |
|
38 |
} |
|
39 |
} |