gameServer2/src/server/handlers/mod.rs
author Marcin Mielniczuk <marmistrz.dev@zoho.eu>
Fri, 06 Jul 2018 16:59:52 +0200
changeset 13450 d3c86ade3d4d
parent 13449 914f9b970f4d
child 13526 ba5211dddb21
permissions -rw-r--r--
Send the rnd reply to the room only.

use mio;
use std::io::Write;
use std::io;

use super::server::HWServer;
use super::actions::Action;
use super::actions::Action::*;
use protocol::messages::HWProtocolMessage;
use protocol::messages::HWServerMessage::*;

mod common;
mod loggingin;
mod lobby;
mod inroom;

pub fn handle(server: &mut HWServer, token: usize, message: HWProtocolMessage) {
    match message {
        HWProtocolMessage::Ping =>
            server.react(token, vec![Pong.send_self().action()]),
        HWProtocolMessage::Quit(Some(msg)) =>
            server.react(token, vec![ByeClient("User quit: ".to_string() + &msg)]),
        HWProtocolMessage::Quit(None) =>
            server.react(token, vec![ByeClient("User quit".to_string())]),
        HWProtocolMessage::Malformed => warn!("Malformed/unknown message"),
        HWProtocolMessage::Empty => warn!("Empty message"),
        _ => {
            match server.clients[token].room_id {
                None =>
                    loggingin::handle(server, token, message),
                Some(id) if id == server.lobby_id =>
                    lobby::handle(server, token, message),
                _ =>
                    inroom::handle(server, token, message)
            }
        },
    }
}