rust/hedgewars-server/src/main.rs
changeset 14794 fc2cfec95d86
parent 14793 9de13d9a6312
child 14803 92225a708bda
equal deleted inserted replaced
14793:9de13d9a6312 14794:fc2cfec95d86
     1 #![allow(unused_imports)]
     1 #![allow(unused_imports)]
     2 #![deny(bare_trait_objects)]
     2 #![deny(bare_trait_objects)]
     3 
     3 
     4 extern crate getopts;
     4 extern crate getopts;
     5 use getopts::Options;
     5 use getopts::Options;
     6 use std::env;
       
     7 use log::*;
     6 use log::*;
     8 use mio::net::*;
     7 use mio::net::*;
     9 use mio::*;
     8 use mio::*;
       
     9 use std::env;
    10 
    10 
    11 mod protocol;
    11 mod protocol;
    12 mod server;
    12 mod server;
    13 mod utils;
    13 mod utils;
    14 
    14 
    15 use crate::server::network::NetworkLayer;
    15 use crate::server::network::NetworkLayer;
    16 use std::time::Duration;
    16 use std::time::Duration;
       
    17 
       
    18 const PROGRAM_NAME: &'_ str = "Hedgewars Game Server";
    17 
    19 
    18 fn main() {
    20 fn main() {
    19     env_logger::init();
    21     env_logger::init();
    20 
    22 
    21     let args: Vec<String> = env::args().collect();
    23     let args: Vec<String> = env::args().collect();
    22     let mut opts = Options::new();
    24     let mut opts = Options::new();
    23 
    25 
    24     opts.optopt("p", "port", "port - defaults to 46631", "PORT");
    26     opts.optopt("p", "port", "port - defaults to 46631", "PORT");
    25     opts.optflag("h", "help", "help");
    27     opts.optflag("h", "help", "help");
    26     let matches = match opts.parse(&args[1..]) {
    28     let matches = match opts.parse(&args[1..]) {
    27         Ok(m) => { m }
    29         Ok(m) => m,
    28         Err(f) => { panic!(f.to_string()) }
    30         Err(e) => {
       
    31             println!("{}\n{}", e, opts.short_usage(""));
       
    32             return;
       
    33         }
    29     };
    34     };
    30     if matches.opt_present("h") {
    35     if matches.opt_present("h") {
    31         println!("-p/--port - defaults to 46631");
    36         println!("{}", opts.usage(PROGRAM_NAME));
    32         return;
    37         return;
    33     }
    38     }
    34     info!("Hedgewars game server, protocol {}", utils::SERVER_VERSION);
    39     info!("Hedgewars game server, protocol {}", utils::SERVER_VERSION);
    35 
    40 
    36     let address;
    41     let address;
    37     if matches.opt_present("p") {
    42     if matches.opt_present("p") {
    38         match matches.opt_str("p") {
    43         match matches.opt_str("p") {
    39             Some(x) => address = format!("0.0.0.0:{}", x).parse().unwrap(),
    44             Some(x) => address = format!("0.0.0.0:{}", x).parse().unwrap(),
    40             None => address = "0.0.0.0:46631".parse().unwrap(),
    45             None => address = "0.0.0.0:46631".parse().unwrap(),
    41         }
    46         }
    42     }
    47     } else {
    43     else {
       
    44         address = "0.0.0.0:46631".parse().unwrap();
    48         address = "0.0.0.0:46631".parse().unwrap();
    45     }
    49     }
    46 
    50 
    47     let listener = TcpListener::bind(&address).unwrap();
    51     let listener = TcpListener::bind(&address).unwrap();
    48 
    52