gameServer2/src/main.rs
author unc0rr
Sun, 01 Jan 2017 22:13:35 +0300
changeset 12126 4348997e502b
parent 12125 858bf4d04c54
child 12127 36ac9c075d0d
permissions -rw-r--r--
Refactor code to add more structure to it

extern crate rand;
extern crate mio;
extern crate slab;

//use std::io::*;
//use rand::Rng;
//use std::cmp::Ordering;
use mio::tcp::*;
use mio::*;

mod utils;
mod server;

fn main() {
    println!("Hedgewars game server, protocol {}", utils::PROTOCOL_VERSION);

    let address = "0.0.0.0:46631".parse().unwrap();
    let listener = TcpListener::bind(&address).unwrap();
    let mut server = server::HWServer::new(listener, 1024, 512);

    let poll = Poll::new().unwrap();
    server.register(&poll).unwrap();

    let mut events = Events::with_capacity(1024);

    loop {
        poll.poll(&mut events, None).unwrap();

        for event in events.iter() {
            match event.token() {
                utils::SERVER => server.accept(&poll).unwrap(),
                _ => unreachable!(),
            }
        }
    }
}