gameServer2/src/server/handlers/mod.rs
author Marcin Mielniczuk <marmistrz.dev@zoho.eu>
Fri, 06 Jul 2018 16:27:25 +0200
changeset 13449 914f9b970f4d
parent 13424 81e0ed105f5d
child 13526 ba5211dddb21
permissions -rw-r--r--
Implement server-side logic for Rnd
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
13449
914f9b970f4d Implement server-side logic for Rnd
Marcin Mielniczuk <marmistrz.dev@zoho.eu>
parents: 13424
diff changeset
    11
mod common;
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    12
mod loggingin;
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    13
mod lobby;
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    14
mod inroom;
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    15
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    16
pub fn handle(server: &mut HWServer, token: usize, message: HWProtocolMessage) {
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    17
    match message {
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    18
        HWProtocolMessage::Ping =>
13424
81e0ed105f5d implementation of team related messages
alfadur
parents: 13124
diff changeset
    19
            server.react(token, vec![Pong.send_self().action()]),
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    20
        HWProtocolMessage::Quit(Some(msg)) =>
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    21
            server.react(token, vec![ByeClient("User quit: ".to_string() + &msg)]),
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    22
        HWProtocolMessage::Quit(None) =>
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    23
            server.react(token, vec![ByeClient("User quit".to_string())]),
12154
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    24
        HWProtocolMessage::Malformed => warn!("Malformed/unknown message"),
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    25
        HWProtocolMessage::Empty => warn!("Empty message"),
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    26
        _ => {
13124
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    27
            match server.clients[token].room_id {
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    28
                None =>
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    29
                    loggingin::handle(server, token, message),
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    30
                Some(id) if id == server.lobby_id =>
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    31
                    lobby::handle(server, token, message),
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    32
                _ =>
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12857
diff changeset
    33
                    inroom::handle(server, token, message)
12154
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
    }
44b06731278b Fix handlers module
unc0rr
parents:
diff changeset
    37
}