implement server and client player join/leave notifications

This commit is contained in:
2024-07-22 12:58:40 +02:00
parent cbb2f5005e
commit 392eaeab83
23 changed files with 422 additions and 25 deletions

View File

@@ -0,0 +1,29 @@
#include <client/handlers/PlayerLeaveHandler.h>
namespace blitz {
namespace client {
PlayerLeaveHandler::PlayerLeaveHandler(network::EnetConnection& a_Connection, EnttWorld& a_World) :
protocol::PacketHandler(a_Connection, a_World) {
m_Slot.Connect(m_Connection.OnPlayerLeave, this, &PlayerLeaveHandler::Handle);
}
void PlayerLeaveHandler::Handle(const protocol::data::PlayerLeave& a_PlayerLeave) {
auto world = m_World.load();
entt::entity playerLeft;
for (auto [player, playerInfo] : world->GetRegistry().view<PlayerInfoComponent>().each()) {
if (playerInfo.m_PlayerId == a_PlayerLeave.m_PlayerId) {
playerLeft = player;
break;
}
}
world->GetRegistry().destroy(playerLeft);
}
PlayerLeaveHandler::~PlayerLeaveHandler() {}
} // namespace client
} // namespace blitz