1 use mio; |
1 use mio; |
2 |
2 |
3 use super::common::rnd_reply; |
3 use super::common::rnd_reply; |
|
4 use crate::utils::to_engine_msg; |
4 use crate::{ |
5 use crate::{ |
5 protocol::messages::{server_chat, HWProtocolMessage, HWServerMessage::*}, |
6 protocol::messages::{server_chat, HWProtocolMessage, HWServerMessage::*}, |
6 server::{ |
7 server::{ |
7 actions::{Action, Action::*}, |
8 actions::{Action, Action::*}, |
8 core::HWServer, |
9 core::HWServer, |
549 } |
551 } |
550 } |
552 } |
551 } |
553 } |
552 } |
554 } |
553 RoundFinished => { |
555 RoundFinished => { |
554 if let (c, Some(r)) = server.client_and_room(client_id) { |
556 let mut game_ended = false; |
555 if c.is_in_game() { |
557 let client = &mut server.clients[client_id]; |
556 c.set_is_in_game(false); |
558 if client.is_in_game() { |
557 response.add( |
559 let room = &mut server.rooms[room_id]; |
558 ClientFlags("-g".to_string(), vec![c.nick.clone()]) |
560 |
559 .send_all() |
561 client.set_is_in_game(false); |
560 .in_room(r.id), |
562 response.add( |
561 ); |
563 ClientFlags("-g".to_string(), vec![client.nick.clone()]) |
562 if r.game_info.is_some() { |
564 .send_all() |
563 for team in r.client_teams(c.id) { |
565 .in_room(room.id), |
564 //SendTeamRemovalMessage(team.name.clone()); |
566 ); |
565 } |
567 let team_names: Vec<_> = room |
566 } |
568 .client_teams(client_id) |
567 } |
569 .map(|t| t.name.clone()) |
|
570 .collect(); |
|
571 |
|
572 if let Some(ref mut info) = room.game_info { |
|
573 info.teams_in_game -= team_names.len() as u8; |
|
574 if info.teams_in_game == 0 { |
|
575 game_ended = true; |
|
576 } |
|
577 |
|
578 for team_name in team_names { |
|
579 let msg = once(b'F').chain(team_name.bytes()); |
|
580 response.add( |
|
581 ForwardEngineMessage(vec![to_engine_msg(msg)]) |
|
582 .send_all() |
|
583 .in_room(room_id) |
|
584 .but_self(), |
|
585 ); |
|
586 |
|
587 let remove_msg = to_engine_msg(once(b'F').chain(team_name.bytes())); |
|
588 if let Some(m) = &info.sync_msg { |
|
589 info.msg_log.push(m.clone()); |
|
590 } |
|
591 if info.sync_msg.is_some() { |
|
592 info.sync_msg = None |
|
593 } |
|
594 info.msg_log.push(remove_msg.clone()); |
|
595 response.add( |
|
596 ForwardEngineMessage(vec![remove_msg]) |
|
597 .send_all() |
|
598 .in_room(room_id) |
|
599 .but_self(), |
|
600 ); |
|
601 } |
|
602 } |
|
603 } |
|
604 if game_ended { |
|
605 super::common::end_game(server, room_id, response) |
568 } |
606 } |
569 } |
607 } |
570 Rnd(v) => { |
608 Rnd(v) => { |
571 let result = rnd_reply(&v); |
609 let result = rnd_reply(&v); |
572 let mut echo = vec!["/rnd".to_string()]; |
610 let mut echo = vec!["/rnd".to_string()]; |