gameServer2/src/server/handlers/mod.rs
changeset 14396 cc99f7c673c7
parent 14395 e5db279308d7
child 14397 c3ae3cac8fba
equal deleted inserted replaced
14395:e5db279308d7 14396:cc99f7c673c7
     1 use mio;
       
     2 use std::{io, io::Write};
       
     3 
       
     4 use super::{
       
     5     server::HWServer,
       
     6     actions::{Action, Action::*},
       
     7     coretypes::ClientId
       
     8 };
       
     9 use crate::{
       
    10     protocol::messages::{
       
    11         HWProtocolMessage,
       
    12         HWServerMessage::*
       
    13     }
       
    14 };
       
    15 use log::*;
       
    16 
       
    17 mod loggingin;
       
    18 mod lobby;
       
    19 mod inroom;
       
    20 mod common;
       
    21 mod checker;
       
    22 
       
    23 pub fn handle(server: &mut HWServer, client_id: ClientId, message: HWProtocolMessage) {
       
    24     match message {
       
    25         HWProtocolMessage::Ping =>
       
    26             server.react(client_id, vec![Pong.send_self().action()]),
       
    27         HWProtocolMessage::Quit(Some(msg)) =>
       
    28             server.react(client_id, vec![ByeClient("User quit: ".to_string() + &msg)]),
       
    29         HWProtocolMessage::Quit(None) =>
       
    30             server.react(client_id, vec![ByeClient("User quit".to_string())]),
       
    31         HWProtocolMessage::Malformed => warn!("Malformed/unknown message"),
       
    32         HWProtocolMessage::Empty => warn!("Empty message"),
       
    33         _ => {
       
    34             match server.clients[client_id].room_id {
       
    35                 None =>
       
    36                     loggingin::handle(server, client_id, message),
       
    37                 Some(id) if id == server.lobby_id =>
       
    38                     lobby::handle(server, client_id, message),
       
    39                 Some(id) =>
       
    40                     inroom::handle(server, client_id, id, message)
       
    41             }
       
    42         },
       
    43     }
       
    44 }