<reponame>JulianBiancardi/Wolfenstein-Taller1
#include "match_start_handler.h"

#include "../../../../common/src/main/packets/packing.h"
#include "../managers/match.h"

MatchStartHandler::MatchStartHandler() {}

MatchStartHandler::~MatchStartHandler() {}

void MatchStartHandler::handle(Packet& packet, ClientManager& client_manager,
                               MatchManager& match_manager) {
  unsigned char type;
  unsigned int player_id;
  unsigned char match_id;
  unpack(packet.get_data(), "CIC", &type, &player_id, &match_id);

  Match& match = match_manager.get_match(match_id);

  if (match.start(player_id, client_manager.get_reception_queue())) {
    const std::unordered_set<unsigned int>& client_ids =
        match.get_players_ids();
    client_manager.send_to_all(client_ids, packet);
  }
}
