Files
Blitz2/src/server/handlers/KeepAliveHandler.cpp
2024-07-23 01:10:20 +02:00

30 lines
1.0 KiB
C++

#include <server/handlers/KeepAliveHandler.h>
#include <server/components/KeepAliveSession.h>
#include <Nazara/Core/Time.hpp>
namespace blitz {
namespace server {
KeepAliveHandler::KeepAliveHandler(network::EnetConnection& a_Connection, EnttWorld& a_World) :
protocol::PacketHandler(a_Connection, a_World) {
m_Slot.Connect(a_Connection.OnKeepAlive,
[this](const protocol::data::KeepAlive& a_KeepAlive) { Handle(m_Connection.GetPeerId(), a_KeepAlive); });
}
KeepAliveHandler::~KeepAliveHandler() {}
void KeepAliveHandler::Handle(std::uint16_t a_PeerId, const protocol::data::KeepAlive& a_KeepAlive) {
AtomicEnttWorld world = m_World;
world->GetRegistry().view<KeepAliveSessionComponent>().each([a_PeerId, &a_KeepAlive](auto& keepAliveSession) {
if (keepAliveSession.m_PeerId == a_PeerId && keepAliveSession.m_LastKeepAliveId == a_KeepAlive.m_KeepAliveId) {
keepAliveSession.m_LastTime = Nz::GetElapsedMilliseconds();
keepAliveSession.m_RecievedResponse = true;
}
});
}
} // namespace server
} // namespace blitz