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