author | Wuzzy <almikes@aol.com> |
Fri, 22 Sep 2017 19:17:06 +0200 | |
changeset 12490 | b4eb289b5913 |
parent 12137 | 193dfdcb0620 |
child 12852 | bd35cb2302b3 |
permissions | -rw-r--r-- |
12125 | 1 |
extern crate rand; |
2 |
extern crate mio; |
|
12126 | 3 |
extern crate slab; |
12127 | 4 |
extern crate netbuf; |
12133 | 5 |
#[macro_use] |
6 |
extern crate nom; |
|
12137
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
7 |
#[macro_use] |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
8 |
extern crate log; |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
9 |
extern crate env_logger; |
12125 | 10 |
|
12126 | 11 |
//use std::io::*; |
12125 | 12 |
//use rand::Rng; |
13 |
//use std::cmp::Ordering; |
|
14 |
use mio::tcp::*; |
|
15 |
use mio::*; |
|
16 |
||
17 |
mod utils; |
|
12126 | 18 |
mod server; |
12129 | 19 |
mod protocol; |
12125 | 20 |
|
21 |
fn main() { |
|
12137
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
22 |
env_logger::init().unwrap(); |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
23 |
|
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
24 |
info!("Hedgewars game server, protocol {}", utils::PROTOCOL_VERSION); |
12125 | 25 |
|
26 |
let address = "0.0.0.0:46631".parse().unwrap(); |
|
12126 | 27 |
let listener = TcpListener::bind(&address).unwrap(); |
12128 | 28 |
let mut server = server::server::HWServer::new(listener, 1024, 512); |
12125 | 29 |
|
30 |
let poll = Poll::new().unwrap(); |
|
12126 | 31 |
server.register(&poll).unwrap(); |
12125 | 32 |
|
33 |
let mut events = Events::with_capacity(1024); |
|
34 |
||
35 |
loop { |
|
36 |
poll.poll(&mut events, None).unwrap(); |
|
37 |
||
38 |
for event in events.iter() { |
|
12127 | 39 |
if event.kind().is_readable() { |
40 |
match event.token() { |
|
41 |
utils::SERVER => server.accept(&poll).unwrap(), |
|
42 |
tok => server.client_readable(&poll, tok).unwrap(), |
|
43 |
} |
|
44 |
} |
|
45 |
if event.kind().is_writable() { |
|
46 |
match event.token() { |
|
47 |
utils::SERVER => unreachable!(), |
|
48 |
tok => server.client_writable(&poll, tok).unwrap(), |
|
49 |
} |
|
12125 | 50 |
} |
12137
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
51 |
if event.kind().is_hup() || event.kind().is_error() { |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
52 |
match event.token() { |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
53 |
utils::SERVER => unreachable!(), |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
54 |
tok => server.client_error(&poll, tok).unwrap(), |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
55 |
} |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
56 |
} |
12125 | 57 |
} |
58 |
} |
|
59 |
} |