author | Wuzzy <almikes@aol.com> |
Wed, 26 Apr 2017 02:28:13 +0200 | |
changeset 12339 | 0bc8c5fcd08c |
parent 12142 | 193dfdcb0620 |
child 12857 | bd35cb2302b3 |
permissions | -rw-r--r-- |
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; |
|
12142
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
7 |
#[macro_use] |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
8 |
extern crate log; |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
9 |
extern crate env_logger; |
12130 | 10 |
|
12131 | 11 |
//use std::io::*; |
12130 | 12 |
//use rand::Rng; |
13 |
//use std::cmp::Ordering; |
|
14 |
use mio::tcp::*; |
|
15 |
use mio::*; |
|
16 |
||
17 |
mod utils; |
|
12131 | 18 |
mod server; |
12134 | 19 |
mod protocol; |
12130 | 20 |
|
21 |
fn main() { |
|
12142
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
22 |
env_logger::init().unwrap(); |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
23 |
|
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
24 |
info!("Hedgewars game server, protocol {}", utils::PROTOCOL_VERSION); |
12130 | 25 |
|
26 |
let address = "0.0.0.0:46631".parse().unwrap(); |
|
12131 | 27 |
let listener = TcpListener::bind(&address).unwrap(); |
12133 | 28 |
let mut server = server::server::HWServer::new(listener, 1024, 512); |
12130 | 29 |
|
30 |
let poll = Poll::new().unwrap(); |
|
12131 | 31 |
server.register(&poll).unwrap(); |
12130 | 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() { |
|
12132 | 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 |
} |
|
12130 | 50 |
} |
12142
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
51 |
if event.kind().is_hup() || event.kind().is_error() { |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
52 |
match event.token() { |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
53 |
utils::SERVER => unreachable!(), |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
54 |
tok => server.client_error(&poll, tok).unwrap(), |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
55 |
} |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
56 |
} |
12130 | 57 |
} |
58 |
} |
|
59 |
} |