implement server and client player join/leave notifications
This commit is contained in:
29
src/client/handlers/PlayerLeaveHandler.cpp
Normal file
29
src/client/handlers/PlayerLeaveHandler.cpp
Normal 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
|
||||
Reference in New Issue
Block a user