gameServer2/src/server/handlers/mod.rs
author kompowiec
Thu, 03 May 2018 18:00:49 +0200
changeset 13371 f2e1c0422396
parent 13124 1e39b8749072
child 13424 81e0ed105f5d
permissions -rw-r--r--
Update Taiwanese translation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12154
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
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    15
pub fn handle(server: &mut HWServer, token: usize, message: HWProtocolMessage) {
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    16
    match message {
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    17
        HWProtocolMessage::Ping =>
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    18
            server.react(token, vec![SendMe(Pong)]),
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    19
        HWProtocolMessage::Quit(Some(msg)) =>
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    20
            server.react(token, vec![ByeClient("User quit: ".to_string() + &msg)]),
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    21
        HWProtocolMessage::Quit(None) =>
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    22
            server.react(token, vec![ByeClient("User quit".to_string())]),
12154
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
        _ => {
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    26
            match server.clients[token].room_id {
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    27
                None =>
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    28
                    loggingin::handle(server, token, message),
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    29
                Some(id) if id == server.lobby_id =>
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    30
                    lobby::handle(server, token, message),
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    31
                _ =>
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    32
                    inroom::handle(server, token, message)
12154
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
}