gameServer2/src/main.rs
changeset 12137 193dfdcb0620
parent 12133 81df2e1f9ae9
child 12852 bd35cb2302b3
equal deleted inserted replaced
12136:e25a82ce2374 12137:193dfdcb0620
     2 extern crate mio;
     2 extern crate mio;
     3 extern crate slab;
     3 extern crate slab;
     4 extern crate netbuf;
     4 extern crate netbuf;
     5 #[macro_use]
     5 #[macro_use]
     6 extern crate nom;
     6 extern crate nom;
       
     7 #[macro_use]
       
     8 extern crate log;
       
     9 extern crate env_logger;
     7 
    10 
     8 //use std::io::*;
    11 //use std::io::*;
     9 //use rand::Rng;
    12 //use rand::Rng;
    10 //use std::cmp::Ordering;
    13 //use std::cmp::Ordering;
    11 use mio::tcp::*;
    14 use mio::tcp::*;
    14 mod utils;
    17 mod utils;
    15 mod server;
    18 mod server;
    16 mod protocol;
    19 mod protocol;
    17 
    20 
    18 fn main() {
    21 fn main() {
    19     println!("Hedgewars game server, protocol {}", utils::PROTOCOL_VERSION);
    22     env_logger::init().unwrap();
       
    23 
       
    24     info!("Hedgewars game server, protocol {}", utils::PROTOCOL_VERSION);
    20 
    25 
    21     let address = "0.0.0.0:46631".parse().unwrap();
    26     let address = "0.0.0.0:46631".parse().unwrap();
    22     let listener = TcpListener::bind(&address).unwrap();
    27     let listener = TcpListener::bind(&address).unwrap();
    23     let mut server = server::server::HWServer::new(listener, 1024, 512);
    28     let mut server = server::server::HWServer::new(listener, 1024, 512);
    24 
    29 
    41                 match event.token() {
    46                 match event.token() {
    42                     utils::SERVER => unreachable!(),
    47                     utils::SERVER => unreachable!(),
    43                     tok => server.client_writable(&poll, tok).unwrap(),
    48                     tok => server.client_writable(&poll, tok).unwrap(),
    44                 }
    49                 }
    45             }
    50             }
       
    51             if event.kind().is_hup() || event.kind().is_error() {
       
    52                 match event.token() {
       
    53                     utils::SERVER => unreachable!(),
       
    54                     tok => server.client_error(&poll, tok).unwrap(),
       
    55                 }
       
    56             }
    46         }
    57         }
    47     }
    58     }
    48 }
    59 }