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;
|
12130
|
14 |
|
|
15 |
fn main() {
|
|
16 |
println!("Hedgewars game server, protocol {}", utils::PROTOCOL_VERSION);
|
|
17 |
|
|
18 |
let address = "0.0.0.0:46631".parse().unwrap();
|
12131
|
19 |
let listener = TcpListener::bind(&address).unwrap();
|
12133
|
20 |
let mut server = server::server::HWServer::new(listener, 1024, 512);
|
12130
|
21 |
|
|
22 |
let poll = Poll::new().unwrap();
|
12131
|
23 |
server.register(&poll).unwrap();
|
12130
|
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() {
|
12132
|
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 |
}
|
12130
|
42 |
}
|
|
43 |
}
|
|
44 |
}
|
|
45 |
}
|