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