gameServer2/src/server/handlers/mod.rs
author alfadur
Thu, 21 Jun 2018 17:23:10 -0400
changeset 13419 81e0ed105f5d
parent 13119 1e39b8749072
child 13444 914f9b970f4d
permissions -rw-r--r--
implementation of team related messages
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12149
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
     1
use mio;
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
     2
use std::io::Write;
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
     3
use std::io;
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
     4
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
     5
use super::server::HWServer;
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
     6
use super::actions::Action;
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
     7
use super::actions::Action::*;
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
     8
use protocol::messages::HWProtocolMessage;
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
     9
use protocol::messages::HWServerMessage::*;
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    10
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    11
mod loggingin;
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    12
mod lobby;
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    13
mod inroom;
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    14
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    15
pub fn handle(server: &mut HWServer, token: usize, message: HWProtocolMessage) {
12149
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    16
    match message {
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    17
        HWProtocolMessage::Ping =>
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13119
diff changeset
    18
            server.react(token, vec![Pong.send_self().action()]),
12149
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    19
        HWProtocolMessage::Quit(Some(msg)) =>
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    20
            server.react(token, vec![ByeClient("User quit: ".to_string() + &msg)]),
12149
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    21
        HWProtocolMessage::Quit(None) =>
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    22
            server.react(token, vec![ByeClient("User quit".to_string())]),
12149
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    23
        HWProtocolMessage::Malformed => warn!("Malformed/unknown message"),
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    24
        HWProtocolMessage::Empty => warn!("Empty message"),
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    25
        _ => {
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    26
            match server.clients[token].room_id {
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    27
                None =>
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    28
                    loggingin::handle(server, token, message),
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    29
                Some(id) if id == server.lobby_id =>
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    30
                    lobby::handle(server, token, message),
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    31
                _ =>
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12852
diff changeset
    32
                    inroom::handle(server, token, message)
12149
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    33
            }
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    34
        },
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    35
    }
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    36
}