gameServer2/src/server/handlers/mod.rs
author nemo
Tue, 21 Aug 2018 15:11:28 -0400
branch0.9.24
changeset 13682 f60b3998ba56
parent 13119 1e39b8749072
child 13419 81e0ed105f5d
permissions -rw-r--r--
only-stats should never create visual gears. and lua should never rely on visual gears being created. critical is just to help ensure ones important to gameplay don't get lost in fast-forward

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 loggingin;
mod lobby;
mod inroom;

pub fn handle(server: &mut HWServer, token: usize, message: HWProtocolMessage) {
    match message {
        HWProtocolMessage::Ping =>
            server.react(token, vec![SendMe(Pong)]),
        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)
            }
        },
    }
}