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