gameServer2/src/server/handlers/mod.rs
author unc0rr
Mon, 06 Feb 2017 18:15:29 +0300
changeset 12149 44b06731278b
child 12852 bd35cb2302b3
permissions -rw-r--r--
Fix handlers module
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
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    15
pub fn handle(server: &mut HWServer, token: mio::Token, poll: &mio::Poll, message: HWProtocolMessage) {
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    16
    match message {
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    17
        HWProtocolMessage::Ping =>
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    18
            server.react(token, poll, vec![SendMe(Pong.to_raw_protocol())]),
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    19
        HWProtocolMessage::Quit(Some(msg)) =>
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    20
            server.react(token, poll, vec![ByeClient("User quit: ".to_string() + &msg)]),
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    21
        HWProtocolMessage::Quit(None) =>
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    22
            server.react(token, poll, vec![ByeClient("User quit".to_string())]),
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
        _ => {
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    26
            if !server.clients[token].room_id.is_some() {
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    27
                loggingin::handle(server, token, poll, message);
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    28
            } else if server.clients[token].room_id == Some(server.lobby_id) {
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    29
                lobby::handle(server, token, poll, message);
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    30
            } else {
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    31
                inroom::handle(server, token, poll, message);
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    32
            }
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
}