12130
|
1 |
extern crate rand;
|
|
2 |
extern crate mio;
|
12131
|
3 |
extern crate slab;
|
12130
|
4 |
|
12131
|
5 |
//use std::io::*;
|
12130
|
6 |
//use rand::Rng;
|
|
7 |
//use std::cmp::Ordering;
|
|
8 |
use mio::tcp::*;
|
|
9 |
use mio::*;
|
|
10 |
|
|
11 |
mod utils;
|
12131
|
12 |
mod server;
|
12130
|
13 |
|
|
14 |
fn main() {
|
|
15 |
println!("Hedgewars game server, protocol {}", utils::PROTOCOL_VERSION);
|
|
16 |
|
|
17 |
let address = "0.0.0.0:46631".parse().unwrap();
|
12131
|
18 |
let listener = TcpListener::bind(&address).unwrap();
|
|
19 |
let mut server = server::HWServer::new(listener, 1024, 512);
|
12130
|
20 |
|
|
21 |
let poll = Poll::new().unwrap();
|
12131
|
22 |
server.register(&poll).unwrap();
|
12130
|
23 |
|
|
24 |
let mut events = Events::with_capacity(1024);
|
|
25 |
|
|
26 |
loop {
|
|
27 |
poll.poll(&mut events, None).unwrap();
|
|
28 |
|
|
29 |
for event in events.iter() {
|
|
30 |
match event.token() {
|
12131
|
31 |
utils::SERVER => server.accept(&poll).unwrap(),
|
12130
|
32 |
_ => unreachable!(),
|
|
33 |
}
|
|
34 |
}
|
|
35 |
}
|
|
36 |
}
|