From add62fb24a3d5698ae19f264c3b04fd1862d0edb Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Sat, 12 Aug 2023 14:48:38 +0200 Subject: [PATCH] fix Lobby timer --- src/game/server/Lobby.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/game/server/Lobby.cpp b/src/game/server/Lobby.cpp index 1a3e7c3..05f8eb7 100644 --- a/src/game/server/Lobby.cpp +++ b/src/game/server/Lobby.cpp @@ -46,20 +46,26 @@ void Lobby::Tick() { } void Lobby::SendTimeRemaining() { - protocol::UpdateLobbyTimePacket packet(m_StartTime); // converting second to millis + protocol::UpdateLobbyTimePacket packet(m_StartTime); m_Server->BroadcastPacket(&packet); } void Lobby::OnPlayerJoin(std::uint8_t playerID) { if (m_GameStarted) return; + utils::LOG("(Server) Player Joined Lobby !"); m_Players.push_back(playerID); + if (m_Players.size() == MIN_PLAYER_WAITING) { // start timer if a second player join the match m_StartTime = utils::GetTime() + static_cast(LobbyWaitingTime); m_Timer.Reset(); SendTimeRemaining(); } + + // notify player that just arrived + protocol::UpdateLobbyTimePacket packet(m_StartTime); + m_Server->GetConnexions().at(playerID).SendPacket(&packet); } void Lobby::OnPlayerLeave(std::uint8_t playerID) {