fully implement KeepAlive behavior
This commit is contained in:
45
src/client/Client.cpp
Normal file
45
src/client/Client.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <client/Client.h>
|
||||
|
||||
#include <client/handlers/KeepAliveHandler.h>
|
||||
|
||||
namespace blitz {
|
||||
namespace client {
|
||||
|
||||
Client::Client() : m_World() {
|
||||
m_World.store(std::make_shared<Nz::EnttWorld>());
|
||||
}
|
||||
|
||||
Client::~Client() {
|
||||
Disconnect();
|
||||
}
|
||||
|
||||
void Client::BindHandlers() {
|
||||
m_Handlers.push_back(std::make_unique<KeepAliveHandler>(m_NetworkClient->GetConnection(), m_World));
|
||||
}
|
||||
|
||||
void Client::UnbindHandlers() {
|
||||
m_Handlers.clear();
|
||||
}
|
||||
|
||||
void Client::Connect(const Nz::IpAddress& a_Ip) {
|
||||
m_NetworkClient = std::make_unique<network::EnetClient>(a_Ip);
|
||||
BindHandlers();
|
||||
}
|
||||
|
||||
void Client::Disconnect() {
|
||||
if (!m_NetworkClient)
|
||||
return;
|
||||
m_NetworkClient->Disconnect();
|
||||
UnbindHandlers();
|
||||
m_NetworkClient.reset(nullptr);
|
||||
}
|
||||
|
||||
bool Client::IsConnected() {
|
||||
if (!m_NetworkClient)
|
||||
return false;
|
||||
|
||||
return m_NetworkClient->GetConnection().IsConnected();
|
||||
}
|
||||
|
||||
} // namespace client
|
||||
} // namespace blitz
|
||||
15
src/client/handlers/KeepAliveHandler.cpp
Normal file
15
src/client/handlers/KeepAliveHandler.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <client/handlers/KeepAliveHandler.h>
|
||||
|
||||
namespace blitz {
|
||||
namespace client {
|
||||
|
||||
KeepAliveHandler::KeepAliveHandler(network::EnetConnection& a_Connection, EnttWorld& a_World) :
|
||||
protocol::PacketHandler(a_Connection, a_World) {
|
||||
m_Slot.Connect(m_Connection.OnKeepAlive,
|
||||
[this](const blitz::protocol::data::KeepAlive& a_KeepAlive) { m_Connection.SendKeepAlive(a_KeepAlive); });
|
||||
}
|
||||
|
||||
KeepAliveHandler::~KeepAliveHandler() {}
|
||||
|
||||
} // namespace client
|
||||
} // namespace blitz
|
||||
Reference in New Issue
Block a user