227 } |
225 } |
228 if let Some(id) = new_id { |
226 if let Some(id) = new_id { |
229 server.clients[id].set_is_master(true) |
227 server.clients[id].set_is_master(true) |
230 } |
228 } |
231 } |
229 } |
232 StartRoomGame(room_id) => { |
|
233 let (room_clients, room_nicks): (Vec<_>, Vec<_>) = server |
|
234 .clients |
|
235 .iter() |
|
236 .map(|(id, c)| (id, c.nick.clone())) |
|
237 .unzip(); |
|
238 let room = &mut server.rooms[room_id]; |
|
239 |
|
240 if !room.has_multiple_clans() { |
|
241 /*Warn( |
|
242 "The game can't be started with less than two clans!".to_string(), |
|
243 )*/ |
|
244 } else if room.protocol_number <= 43 && room.players_number != room.ready_players_number |
|
245 { |
|
246 /*Warn("Not all players are ready".to_string())*/ |
|
247 } else if room.game_info.is_some() { |
|
248 /*Warn("The game is already in progress".to_string())*/ |
|
249 } else { |
|
250 room.start_round(); |
|
251 for id in room_clients { |
|
252 let c = &mut server.clients[id]; |
|
253 c.set_is_in_game(false); |
|
254 c.team_indices = room.client_team_indices(c.id); |
|
255 } |
|
256 /*RunGame.send_all().in_room(room.id).action(),*/ |
|
257 //SendRoomUpdate(None), |
|
258 /*ClientFlags("+g".to_string(), room_nicks) |
|
259 .send_all() |
|
260 .in_room(room.id) |
|
261 .action(),*/ |
|
262 } |
|
263 } |
|
264 SendTeamRemovalMessage(team_name) => { |
230 SendTeamRemovalMessage(team_name) => { |
265 let mut actions = Vec::new(); |
|
266 if let Some(r) = server.room(client_id) { |
231 if let Some(r) = server.room(client_id) { |
267 if let Some(ref mut info) = r.game_info { |
232 if let Some(ref mut info) = r.game_info { |
268 let msg = once(b'F').chain(team_name.bytes()); |
233 let msg = once(b'F').chain(team_name.bytes()); |
269 /*actions.push( |
234 /*actions.push( |
270 ForwardEngineMessage(vec![to_engine_msg(msg)]) |
235 ForwardEngineMessage(vec![to_engine_msg(msg)]) |
273 .but_self() |
238 .but_self() |
274 .action(), |
239 .action(), |
275 );*/ |
240 );*/ |
276 info.teams_in_game -= 1; |
241 info.teams_in_game -= 1; |
277 if info.teams_in_game == 0 { |
242 if info.teams_in_game == 0 { |
278 actions.push(FinishRoomGame(r.id)); |
243 //actions.push(FinishRoomGame(r.id)); |
279 } |
244 } |
280 let remove_msg = to_engine_msg(once(b'F').chain(team_name.bytes())); |
245 let remove_msg = to_engine_msg(once(b'F').chain(team_name.bytes())); |
281 if let Some(m) = &info.sync_msg { |
246 if let Some(m) = &info.sync_msg { |
282 info.msg_log.push(m.clone()); |
247 info.msg_log.push(m.clone()); |
283 } |
248 } |
293 .action(), |
258 .action(), |
294 );*/ |
259 );*/ |
295 } |
260 } |
296 } |
261 } |
297 } |
262 } |
298 FinishRoomGame(room_id) => { |
263 } |
299 let mut actions = Vec::new(); |
264 } |
300 |
|
301 let r = &mut server.rooms[room_id]; |
|
302 r.ready_players_number = 1; |
|
303 //actions.push(SendRoomUpdate(None)); |
|
304 //actions.push(RoundFinished.send_all().in_room(r.id).action()); |
|
305 |
|
306 if let Some(info) = replace(&mut r.game_info, None) { |
|
307 for (_, c) in server.clients.iter() { |
|
308 if c.room_id == Some(room_id) && c.is_joined_mid_game() { |
|
309 actions.push(SendRoomData { |
|
310 to: c.id, |
|
311 teams: false, |
|
312 config: true, |
|
313 flags: false, |
|
314 }); |
|
315 for name in &info.left_teams { |
|
316 //actions.push(TeamRemove(name.clone()).send(c.id).action()); |
|
317 } |
|
318 } |
|
319 } |
|
320 } |
|
321 |
|
322 let nicks: Vec<_> = server |
|
323 .clients |
|
324 .iter_mut() |
|
325 .filter(|(_, c)| c.room_id == Some(room_id)) |
|
326 .map(|(_, c)| { |
|
327 c.set_is_ready(c.is_master()); |
|
328 c.set_is_joined_mid_game(false); |
|
329 c |
|
330 }) |
|
331 .filter_map(|c| { |
|
332 if !c.is_master() { |
|
333 Some(c.nick.clone()) |
|
334 } else { |
|
335 None |
|
336 } |
|
337 }) |
|
338 .collect(); |
|
339 |
|
340 if !nicks.is_empty() { |
|
341 let msg = if r.protocol_number < 38 { |
|
342 LegacyReady(false, nicks) |
|
343 } else { |
|
344 ClientFlags("-r".to_string(), nicks) |
|
345 }; |
|
346 //actions.push(msg.send_all().in_room(room_id).action()); |
|
347 } |
|
348 } |
|
349 } |
|
350 } |
|