author | unc0rr |
Thu, 26 Jan 2017 14:45:44 +0300 | |
changeset 12145 | a482c7a5f6e3 |
parent 12144 | 589a2d7d3dc5 |
child 12146 | 8d8fb85bc09c |
permissions | -rw-r--r-- |
12144 | 1 |
use mio; |
2 |
use std::io::Write; |
|
3 |
use std::io; |
|
4 |
||
5 |
use super::server::HWServer; |
|
6 |
use protocol::messages::HWProtocolMessage; |
|
7 |
use protocol::messages::HWServerMessage::*; |
|
8 |
use super::handlers; |
|
12138 | 9 |
|
10 |
pub enum Action { |
|
11 |
SendMe(String), |
|
12139 | 12 |
RemoveClient, |
13 |
ByeClient(String), |
|
12142
4d7d41be1993
Start refactoring path from getting message from client to reacting to it
unc0rr
parents:
12141
diff
changeset
|
14 |
ReactProtocolMessage(HWProtocolMessage), |
12145 | 15 |
CheckRegistered, |
16 |
JoinLobby, |
|
12138 | 17 |
} |
12144 | 18 |
|
19 |
use self::Action::*; |
|
20 |
||
21 |
pub fn run_action(server: &mut HWServer, token: mio::Token, poll: &mio::Poll, action: Action) { |
|
22 |
match action { |
|
23 |
SendMe(msg) => |
|
24 |
server.send(token, &msg), |
|
25 |
ByeClient(msg) => { |
|
26 |
server.react(token, poll, vec![ |
|
27 |
SendMe(Bye(&msg).to_raw_protocol()), |
|
28 |
RemoveClient, |
|
29 |
]); |
|
30 |
}, |
|
31 |
RemoveClient => { |
|
32 |
server.clients[token].deregister(poll); |
|
33 |
server.clients.remove(token); |
|
34 |
}, |
|
35 |
ReactProtocolMessage(msg) => |
|
36 |
handlers::handle(server, token, poll, msg), |
|
12145 | 37 |
CheckRegistered => |
38 |
if server.clients[token].protocolNumber > 0 && server.clients[token].nick != "" { |
|
39 |
server.react(token, poll, vec![ |
|
40 |
JoinLobby, |
|
41 |
]); |
|
42 |
}, |
|
43 |
JoinLobby => { |
|
44 |
let msg_string = LobbyJoined(&[&server.clients[token].nick]).to_raw_protocol(); |
|
45 |
server.react(token, poll, vec![ |
|
46 |
SendMe(msg_string), |
|
47 |
]); |
|
48 |
}, |
|
12144 | 49 |
//_ => unimplemented!(), |
50 |
} |
|
51 |
} |