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