From 3944b58171627041baa1c10efdb60da1e0ba2351 Mon Sep 17 00:00:00 2001 From: Robbe Bryssinck Date: Wed, 4 May 2022 17:01:34 +0200 Subject: [PATCH] fix: destroy party on disconnect --- Code/client/Services/Generic/PartyService.cpp | 33 +++++++++++-------- Code/client/Services/PartyService.h | 10 ++++-- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Code/client/Services/Generic/PartyService.cpp b/Code/client/Services/Generic/PartyService.cpp index bd18717d8..fa1e8f745 100644 --- a/Code/client/Services/Generic/PartyService.cpp +++ b/Code/client/Services/Generic/PartyService.cpp @@ -1,13 +1,11 @@ -#include - - -#include -#include - #include + #include #include +#include +#include + #include #include #include @@ -24,6 +22,7 @@ PartyService::PartyService(entt::dispatcher& aDispatcher, TransportService& aTra : m_transportService(aTransportService) { m_updateConnection = aDispatcher.sink().connect<&PartyService::OnUpdate>(this); + m_disconnectConnection = aDispatcher.sink().connect<&PartyService::OnDisconnected>(this); m_playerListConnection = aDispatcher.sink().connect<&PartyService::OnPlayerList>(this); m_partyInfoConnection = aDispatcher.sink().connect<&PartyService::OnPartyInfo>(this); @@ -45,16 +44,17 @@ void PartyService::OnUpdate(const UpdateEvent& acEvent) noexcept while (itor != std::end(m_invitations)) { if (itor->second < cCurrentTick) - { itor = m_invitations.erase(itor); - } else - { ++itor; - } } } +void PartyService::OnDisconnected(const DisconnectedEvent& acEvent) noexcept +{ + DestroyParty(); +} + void PartyService::OnPlayerList(const NotifyPlayerList& acPlayerList) noexcept { m_players = acPlayerList.Players; @@ -80,10 +80,7 @@ void PartyService::OnPartyInvite(const NotifyPartyInvite& acPartyInvite) noexcep void PartyService::OnPartyLeft(const NotifyPartyLeft& acPartyLeft) noexcept { spdlog::debug("[PartyService]: Left party"); - m_inParty = false; - m_isLeader = false; - m_leaderPlayerId = -1; - m_partyMembers.clear(); + DestroyParty(); } void PartyService::OnPartyJoined(const NotifyPartyJoined& acPartyJoined) noexcept @@ -95,3 +92,11 @@ void PartyService::OnPartyJoined(const NotifyPartyJoined& acPartyJoined) noexcep m_leaderPlayerId = acPartyJoined.LeaderPlayerId; m_partyMembers = acPartyJoined.PlayerIds; } + +void PartyService::DestroyParty() noexcept +{ + m_inParty = false; + m_isLeader = false; + m_leaderPlayerId = -1; + m_partyMembers.clear(); +} diff --git a/Code/client/Services/PartyService.h b/Code/client/Services/PartyService.h index 8462c2e35..1cd4d8fb0 100644 --- a/Code/client/Services/PartyService.h +++ b/Code/client/Services/PartyService.h @@ -2,10 +2,11 @@ struct ImguiService; struct TransportService; +struct UpdateEvent; +struct DisconnectedEvent; struct NotifyPlayerList; struct NotifyPartyInfo; struct NotifyPartyInvite; -struct UpdateEvent; struct NotifyPartyJoined; struct NotifyPartyLeft; @@ -47,7 +48,8 @@ struct PartyService protected: - void OnUpdate(const UpdateEvent& acPlayerList) noexcept; + void OnUpdate(const UpdateEvent& acEvent) noexcept; + void OnDisconnected(const DisconnectedEvent& acEvent) noexcept; void OnPlayerList(const NotifyPlayerList& acPlayerList) noexcept; void OnPartyInfo(const NotifyPartyInfo& acPartyInfo) noexcept; void OnPartyInvite(const NotifyPartyInvite& acPartyInvite) noexcept; @@ -55,6 +57,9 @@ struct PartyService void OnPartyLeft(const NotifyPartyLeft& acPartyLeft) noexcept; private: + + void DestroyParty() noexcept; + Map m_players; Map m_invitations; uint64_t m_nextUpdate{0}; @@ -67,6 +72,7 @@ struct PartyService TransportService& m_transportService; entt::scoped_connection m_updateConnection; + entt::scoped_connection m_disconnectConnection; entt::scoped_connection m_playerListConnection; entt::scoped_connection m_partyInfoConnection; entt::scoped_connection m_partyInviteConnection;