gameServer2/src/server/handlers/mod.rs
author alfadur
Mon, 27 Aug 2018 22:28:56 +0300
changeset 13800 e335daaa77a9
parent 13671 09f4a30e50cc
child 13803 4664da990556
permissions -rw-r--r--
Add hogs per team named constant that absolutely no one asked for

use mio;
use std::{io, io::Write};

use super::{
    server::HWServer,
    actions::{Action, Action::*},
    coretypes::ClientId
};
use crate::{
    protocol::messages::{
        HWProtocolMessage,
        HWServerMessage::*
    }
};

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

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