220 c.is_ready = true; |
220 c.is_ready = true; |
221 } else { |
221 } else { |
222 c.is_ready = false; |
222 c.is_ready = false; |
223 c.is_master = false; |
223 c.is_master = false; |
224 } |
224 } |
225 let flags_msg = ClientFlags("+i".to_string(), vec![c.nick.clone()]); |
|
226 |
225 |
227 let mut v = vec![ |
226 let mut v = vec![ |
228 RoomJoined(vec![c.nick.clone()]).send_all().in_room(room_id).action(), |
227 RoomJoined(vec![c.nick.clone()]).send_all().in_room(room_id).action(), |
229 flags_msg.send_all().action(), |
228 ClientFlags("+i".to_string(), vec![c.nick.clone()]).send_all().action(), |
230 SendRoomUpdate(None)]; |
229 SendRoomUpdate(None)]; |
231 if !c.is_master { |
230 if !c.is_master { |
|
231 let team_names: Vec<_>; |
|
232 if let Some(ref mut info) = r.game_info { |
|
233 c.is_in_game = true; |
|
234 c.is_joined_mid_game = true; |
|
235 |
|
236 { |
|
237 let teams = info.client_teams(c.id); |
|
238 c.teams_in_game = teams.clone().count() as u8; |
|
239 c.clan = teams.clone().next().map(|t| t.color); |
|
240 team_names = teams.map(|t| t.name.clone()).collect(); |
|
241 } |
|
242 |
|
243 if !team_names.is_empty() { |
|
244 info.left_teams.retain(|name| |
|
245 !team_names.contains(&name)); |
|
246 info.teams_in_game += team_names.len() as u8; |
|
247 r.teams = info.teams_at_start.iter() |
|
248 .filter(|(_, t)| !team_names.contains(&t.name)) |
|
249 .cloned().collect(); |
|
250 } |
|
251 } else { |
|
252 team_names = Vec::new(); |
|
253 } |
|
254 |
232 v.push(SendRoomData{ to: client_id, teams: true, config: true, flags: true}); |
255 v.push(SendRoomData{ to: client_id, teams: true, config: true, flags: true}); |
|
256 |
|
257 if let Some(ref info) = r.game_info { |
|
258 v.push(RunGame.send_self().action()); |
|
259 v.push(ClientFlags("+g".to_string(), vec![c.nick.clone()]) |
|
260 .send_all().in_room(r.id).action()); |
|
261 v.push(ForwardEngineMessage( |
|
262 to_engine_msg("e$spectate 1".bytes()) + &info.msg_log) |
|
263 .send_self().action()); |
|
264 |
|
265 for name in team_names.iter() { |
|
266 v.push(ForwardEngineMessage( |
|
267 to_engine_msg(once(b'G').chain(name.bytes()))) |
|
268 .send_all().in_room(r.id).action()); |
|
269 } |
|
270 if info.is_paused { |
|
271 v.push(ForwardEngineMessage(to_engine_msg(once(b'I'))) |
|
272 .send_all().in_room(r.id).action()) |
|
273 } |
|
274 } |
233 } |
275 } |
234 v |
276 v |
235 }; |
277 }; |
236 server.react(client_id, actions); |
278 server.react(client_id, actions); |
237 } |
279 } |
245 for cfg in r.game_config().into_iter() { |
287 for cfg in r.game_config().into_iter() { |
246 actions.push(cfg.into_server_msg().send(to).action()); |
288 actions.push(cfg.into_server_msg().send(to).action()); |
247 } |
289 } |
248 } |
290 } |
249 if teams { |
291 if teams { |
250 for (owner_id, team) in r.teams.iter() { |
292 let current_teams = match r.game_info { |
|
293 Some(ref info) => &info.teams_at_start, |
|
294 None => &r.teams |
|
295 }; |
|
296 for (owner_id, team) in current_teams.iter() { |
251 actions.push(TeamAdd(HWRoom::team_info(&server.clients[*owner_id], &team)) |
297 actions.push(TeamAdd(HWRoom::team_info(&server.clients[*owner_id], &team)) |
|
298 .send(to).action()); |
|
299 actions.push(TeamColor(team.name.clone(), team.color) |
|
300 .send(to).action()); |
|
301 actions.push(HedgehogsNumber(team.name.clone(), team.hedgehogs_number) |
252 .send(to).action()); |
302 .send(to).action()); |
253 } |
303 } |
254 } |
304 } |
255 if flags { |
305 if flags { |
256 if let Some(id) = r.master_id { |
306 if let Some(id) = r.master_id { |
366 if !room.has_multiple_clans() { |
416 if !room.has_multiple_clans() { |
367 vec![Warn("The game can't be started with less than two clans!".to_string())] |
417 vec![Warn("The game can't be started with less than two clans!".to_string())] |
368 } else if room.game_info.is_some() { |
418 } else if room.game_info.is_some() { |
369 vec![Warn("The game is already in progress".to_string())] |
419 vec![Warn("The game is already in progress".to_string())] |
370 } else { |
420 } else { |
371 room.game_info = Some(GameInfo::new(room.teams.len() as u8)); |
421 room.start_round(); |
372 for id in room_clients { |
422 for id in room_clients { |
373 let c = &mut server.clients[id]; |
423 let c = &mut server.clients[id]; |
374 c.is_in_game = true; |
424 c.is_in_game = true; |
375 c.team_indices = room.client_team_indices(c.id); |
425 c.team_indices = room.client_team_indices(c.id); |
376 } |
426 } |
391 send_all().in_room(r.id).but_self().action()); |
441 send_all().in_room(r.id).but_self().action()); |
392 info.teams_in_game -= 1; |
442 info.teams_in_game -= 1; |
393 if info.teams_in_game == 0 { |
443 if info.teams_in_game == 0 { |
394 actions.push(FinishRoomGame(r.id)); |
444 actions.push(FinishRoomGame(r.id)); |
395 } |
445 } |
|
446 let remove_msg = to_engine_msg(once(b'F').chain(team_name.bytes())); |
|
447 match &info.last_msg { |
|
448 Some(m) => info.msg_log.push_str(&m), |
|
449 None => info.msg_log.push_str(&remove_msg) |
|
450 } |
|
451 actions.push(ForwardEngineMessage(remove_msg) |
|
452 .send_all().in_room(r.id).but_self().action()); |
396 } |
453 } |
397 } |
454 } |
398 server.react(client_id, actions); |
455 server.react(client_id, actions); |
399 } |
456 } |
400 FinishRoomGame(room_id) => { |
457 FinishRoomGame(room_id) => { |