gameServer2/src/server/handlers/mod.rs
changeset 12149 44b06731278b
child 12852 bd35cb2302b3
equal deleted inserted replaced
12148:8591375271b8 12149:44b06731278b
       
     1 use mio;
       
     2 use std::io::Write;
       
     3 use std::io;
       
     4 
       
     5 use super::server::HWServer;
       
     6 use super::actions::Action;
       
     7 use super::actions::Action::*;
       
     8 use protocol::messages::HWProtocolMessage;
       
     9 use protocol::messages::HWServerMessage::*;
       
    10 
       
    11 mod loggingin;
       
    12 mod lobby;
       
    13 mod inroom;
       
    14 
       
    15 pub fn handle(server: &mut HWServer, token: mio::Token, poll: &mio::Poll, message: HWProtocolMessage) {
       
    16     match message {
       
    17         HWProtocolMessage::Ping =>
       
    18             server.react(token, poll, vec![SendMe(Pong.to_raw_protocol())]),
       
    19         HWProtocolMessage::Quit(Some(msg)) =>
       
    20             server.react(token, poll, vec![ByeClient("User quit: ".to_string() + &msg)]),
       
    21         HWProtocolMessage::Quit(None) =>
       
    22             server.react(token, poll, vec![ByeClient("User quit".to_string())]),
       
    23         HWProtocolMessage::Malformed => warn!("Malformed/unknown message"),
       
    24         HWProtocolMessage::Empty => warn!("Empty message"),
       
    25         _ => {
       
    26             if !server.clients[token].room_id.is_some() {
       
    27                 loggingin::handle(server, token, poll, message);
       
    28             } else if server.clients[token].room_id == Some(server.lobby_id) {
       
    29                 lobby::handle(server, token, poll, message);
       
    30             } else {
       
    31                 inroom::handle(server, token, poll, message);
       
    32             }
       
    33         },
       
    34     }
       
    35 }