# HG changeset patch # User nemo # Date 1555083695 14400 # Node ID 38e66519e5851064a9fc53d23e8cf2d33c27d2ad # Parent b889d9e1115f7a1b135cbdd00990c7b2a78c8015 ugly hacked in argument for port to remove unc0rr's excuse diff -r b889d9e1115f -r 38e66519e585 rust/hedgewars-server/Cargo.toml --- a/rust/hedgewars-server/Cargo.toml Fri Apr 12 02:48:16 2019 +0300 +++ b/rust/hedgewars-server/Cargo.toml Fri Apr 12 11:41:35 2019 -0400 @@ -10,6 +10,7 @@ default = [] [dependencies] +getopts = "0.2.18" rand = "0.6" mio = "0.6" mio-extras = "2.0.5" diff -r b889d9e1115f -r 38e66519e585 rust/hedgewars-server/src/main.rs --- a/rust/hedgewars-server/src/main.rs Fri Apr 12 02:48:16 2019 +0300 +++ b/rust/hedgewars-server/src/main.rs Fri Apr 12 11:41:35 2019 -0400 @@ -1,6 +1,10 @@ +#![feature(self_struct_ctor)] #![allow(unused_imports)] #![deny(bare_trait_objects)] +extern crate getopts; +use getopts::Options; +use std::env; use log::*; use mio::net::*; use mio::*; @@ -15,9 +19,32 @@ fn main() { env_logger::init(); + let args: Vec = env::args().collect(); + let mut opts = Options::new(); + + opts.optopt("p", "port", "port - defaults to 46631", "PORT"); + opts.optflag("h", "help", "help"); + let matches = match opts.parse(&args[1..]) { + Ok(m) => { m } + Err(f) => { panic!(f.to_string()) } + }; + if matches.opt_present("h") { + println!("-p/--port - defaults to 46631"); + return; + } info!("Hedgewars game server, protocol {}", utils::SERVER_VERSION); - let address = "0.0.0.0:46631".parse().unwrap(); + let address; + if matches.opt_present("p") { + match matches.opt_str("p") { + Some(x) => address = format!("0.0.0.0:{}", x).parse().unwrap(), + None => address = "0.0.0.0:46631".parse().unwrap(), + } + } + else { + address = "0.0.0.0:46631".parse().unwrap(); + } + let listener = TcpListener::bind(&address).unwrap(); let poll = Poll::new().unwrap();