12147
|
1 |
use mio;
|
|
2 |
|
|
3 |
use server::server::HWServer;
|
|
4 |
use server::actions::Action;
|
|
5 |
use server::actions::Action::*;
|
|
6 |
use protocol::messages::HWProtocolMessage;
|
|
7 |
use protocol::messages::HWServerMessage::*;
|
|
8 |
|
12852
|
9 |
pub fn handle(server: &mut HWServer, token: usize, poll: &mio::Poll, message: HWProtocolMessage) {
|
12147
|
10 |
match message {
|
|
11 |
HWProtocolMessage::Chat(msg) => {
|
|
12 |
let chat_msg = ChatMsg(&server.clients[token].nick, &msg).to_raw_protocol();
|
|
13 |
server.react(token, poll, vec![SendAllButMe(chat_msg)]);
|
|
14 |
},
|
|
15 |
HWProtocolMessage::CreateRoom(name, password) => {
|
12852
|
16 |
let room_exists = server.rooms.iter().find(|&(_, r)| r.name == name).is_some();
|
12147
|
17 |
if room_exists {
|
|
18 |
server.react(token, poll, vec![Warn("Room exists".to_string())]);
|
|
19 |
} else {
|
|
20 |
let flags_msg = ClientFlags("+hr", &[&server.clients[token].nick]).to_raw_protocol();
|
|
21 |
{
|
|
22 |
let c = &mut server.clients[token];
|
|
23 |
c.is_master = true;
|
|
24 |
c.is_ready = true;
|
|
25 |
c.is_joined_mid_game = false;
|
|
26 |
}
|
|
27 |
server.react(token, poll, vec![
|
|
28 |
AddRoom(name, password)
|
|
29 |
, SendMe(flags_msg)
|
|
30 |
]);
|
|
31 |
}
|
|
32 |
},
|
|
33 |
HWProtocolMessage::Join(name, password) => {
|
|
34 |
|
|
35 |
},
|
|
36 |
HWProtocolMessage::List => warn!("Deprecated LIST message received"),
|
|
37 |
_ => warn!("Incorrect command in lobby state"),
|
|
38 |
}
|
|
39 |
}
|