gameServer2/src/main.rs
author unc0rr
Sun, 01 Jan 2017 22:13:35 +0300
changeset 12131 4348997e502b
parent 12130 858bf4d04c54
child 12132 36ac9c075d0d
permissions -rw-r--r--
Refactor code to add more structure to it
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12130
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
     1
extern crate rand;
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
     2
extern crate mio;
12131
4348997e502b Refactor code to add more structure to it
unc0rr
parents: 12130
diff changeset
     3
extern crate slab;
12130
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
     4
12131
4348997e502b Refactor code to add more structure to it
unc0rr
parents: 12130
diff changeset
     5
//use std::io::*;
12130
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
     6
//use rand::Rng;
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
     7
//use std::cmp::Ordering;
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
     8
use mio::tcp::*;
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
     9
use mio::*;
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    10
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    11
mod utils;
12131
4348997e502b Refactor code to add more structure to it
unc0rr
parents: 12130
diff changeset
    12
mod server;
12130
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    13
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    14
fn main() {
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    15
    println!("Hedgewars game server, protocol {}", utils::PROTOCOL_VERSION);
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    16
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    17
    let address = "0.0.0.0:46631".parse().unwrap();
12131
4348997e502b Refactor code to add more structure to it
unc0rr
parents: 12130
diff changeset
    18
    let listener = TcpListener::bind(&address).unwrap();
4348997e502b Refactor code to add more structure to it
unc0rr
parents: 12130
diff changeset
    19
    let mut server = server::HWServer::new(listener, 1024, 512);
12130
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    20
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    21
    let poll = Poll::new().unwrap();
12131
4348997e502b Refactor code to add more structure to it
unc0rr
parents: 12130
diff changeset
    22
    server.register(&poll).unwrap();
12130
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    23
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    24
    let mut events = Events::with_capacity(1024);
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    25
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    26
    loop {
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    27
        poll.poll(&mut events, None).unwrap();
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    28
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    29
        for event in events.iter() {
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    30
            match event.token() {
12131
4348997e502b Refactor code to add more structure to it
unc0rr
parents: 12130
diff changeset
    31
                utils::SERVER => server.accept(&poll).unwrap(),
12130
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    32
                _ => unreachable!(),
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    33
            }
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    34
        }
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    35
    }
858bf4d04c54 Start server implementation in rust
unc0rr
parents:
diff changeset
    36
}