gameServer2/src/server/actions.rs
changeset 12144 589a2d7d3dc5
parent 12143 7e874846afe3
child 12145 a482c7a5f6e3
equal deleted inserted replaced
12143:7e874846afe3 12144:589a2d7d3dc5
     1 use protocol::messages::{HWProtocolMessage, HWServerMessage};
     1 use mio;
       
     2 use std::io::Write;
       
     3 use std::io;
       
     4 
       
     5 use super::server::HWServer;
       
     6 use protocol::messages::HWProtocolMessage;
       
     7 use protocol::messages::HWServerMessage::*;
       
     8 use super::handlers;
     2 
     9 
     3 pub enum Action {
    10 pub enum Action {
     4     SendMe(String),
    11     SendMe(String),
     5     RemoveClient,
    12     RemoveClient,
     6     ByeClient(String),
    13     ByeClient(String),
     7     ReactProtocolMessage(HWProtocolMessage),
    14     ReactProtocolMessage(HWProtocolMessage),
     8 }
    15 }
       
    16 
       
    17 use self::Action::*;
       
    18 
       
    19 pub fn run_action(server: &mut HWServer, token: mio::Token, poll: &mio::Poll, action: Action) {
       
    20     match action {
       
    21         SendMe(msg) =>
       
    22             server.send(token, &msg),
       
    23         ByeClient(msg) => {
       
    24             server.react(token, poll, vec![
       
    25                 SendMe(Bye(&msg).to_raw_protocol()),
       
    26                 RemoveClient,
       
    27                 ]);
       
    28         },
       
    29         RemoveClient => {
       
    30             server.clients[token].deregister(poll);
       
    31             server.clients.remove(token);
       
    32         },
       
    33         ReactProtocolMessage(msg) =>
       
    34             handlers::handle(server, token, poll, msg),
       
    35         //_ => unimplemented!(),
       
    36     }
       
    37 }