author | nemo |
Tue, 21 Aug 2018 15:11:28 -0400 | |
branch | 0.9.24 |
changeset 13682 | f60b3998ba56 |
parent 13119 | 1e39b8749072 |
child 13416 | cdf69667593b |
permissions | -rw-r--r-- |
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 |
||
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
9 |
pub fn handle(server: &mut HWServer, token: usize, message: HWProtocolMessage) { |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
10 |
use protocol::messages::HWProtocolMessage::*; |
12147 | 11 |
match message { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
12 |
Chat(msg) => { |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
13 |
let chat_msg = ChatMsg(server.clients[token].nick.clone(), msg); |
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
14 |
server.react(token, vec![SendAllButMe(chat_msg)]); |
12147 | 15 |
}, |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
16 |
CreateRoom(name, password) => { |
12852 | 17 |
let room_exists = server.rooms.iter().find(|&(_, r)| r.name == name).is_some(); |
12147 | 18 |
if room_exists { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
19 |
server.react(token, vec![Warn("Room exists".to_string())]); |
12147 | 20 |
} else { |
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
21 |
let flags_msg = ClientFlags("+hr".to_string(), vec![server.clients[token].nick.clone()]); |
12147 | 22 |
{ |
23 |
let c = &mut server.clients[token]; |
|
24 |
c.is_master = true; |
|
25 |
c.is_ready = true; |
|
26 |
c.is_joined_mid_game = false; |
|
27 |
} |
|
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
28 |
server.react(token, vec![ |
12147 | 29 |
AddRoom(name, password) |
30 |
, SendMe(flags_msg) |
|
31 |
]); |
|
32 |
} |
|
33 |
}, |
|
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
34 |
Join(name, password) => { |
12147 | 35 |
|
36 |
}, |
|
13119
1e39b8749072
separated the server logic from all the async io mess.
alfadur
parents:
12852
diff
changeset
|
37 |
List => warn!("Deprecated LIST message received"), |
12147 | 38 |
_ => warn!("Incorrect command in lobby state"), |
39 |
} |
|
40 |
} |