gameServer2/src/main.rs
author unc0rr
Tue, 03 Jan 2017 00:19:47 +0300
changeset 12134 07972a8c2433
parent 12133 f50876f3eff8
child 12138 81df2e1f9ae9
permissions -rw-r--r--
- Start protocol parser implementation - Small fixes

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

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

mod utils;
mod server;
mod protocol;

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::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() {
            if event.kind().is_readable() {
                match event.token() {
                    utils::SERVER => server.accept(&poll).unwrap(),
                    tok => server.client_readable(&poll, tok).unwrap(),
                }
            }
            if event.kind().is_writable() {
                match event.token() {
                    utils::SERVER => unreachable!(),
                    tok => server.client_writable(&poll, tok).unwrap(),
                }
            }
        }
    }
}