fully implement KeepAlive behavior

This commit is contained in:
2024-07-21 20:59:13 +02:00
parent 36a2e67ac4
commit 92a2e53036
25 changed files with 513 additions and 61 deletions

View File

@@ -1,7 +1,7 @@
#pragma once
#include <Nazara/Network/ENetHost.hpp>
#include <blitz/network/EnetConnexion.h>
#include <blitz/network/EnetConnection.h>
#include <thread>
namespace blitz {
@@ -18,12 +18,12 @@ class EnetClient : private NonCopyable {
NazaraSignal(OnDisconnect);
NazaraSignal(OnDisconnectTimeout);
const EnetConnexion& GetConnexion() const {
return m_Connexion;
EnetConnection& GetConnection() {
return m_Connection;
}
private:
EnetConnexion m_Connexion;
EnetConnection m_Connection;
Nz::ENetHost m_Host;
Nz::ENetPeer* m_Peer;
std::thread m_Thread;

View File

@@ -1,8 +1,8 @@
#pragma once
/**
* \file EnetConnexion.h
* \brief File containing the blitz::network::EnetConnexion class
* \file EnetConnection.h
* \brief File containing the blitz::network::EnetConnection class
*/
#include <Nazara/Core/ByteArray.hpp>
@@ -35,12 +35,14 @@ class EnetServer;
class EnetConnexion : private NonCopyable {
class EnetConnection : private NonCopyable {
public:
EnetConnexion(Nz::ENetPeer* a_Peer = nullptr);
EnetConnection(Nz::ENetPeer* a_Peer = nullptr);
bool IsConnected() const;
std::uint16_t GetPeerId() const;
DeclareAllPacket();
private:

View File

@@ -2,7 +2,7 @@
#include <Nazara/Core/ThreadExt.hpp>
#include <Nazara/Network/ENetHost.hpp>
#include <blitz/network/EnetConnexion.h>
#include <blitz/network/EnetConnection.h>
#include <cstdint>
#include <map>
#include <thread>
@@ -17,24 +17,24 @@ class EnetServer : private NonCopyable {
void Destroy();
// void BroadcastPacket(const protocol::Packet& a_Packet, Nz::ENetPacketFlags a_Flags);
void CloseConnection(std::uint16_t a_PeerId);
EnetConnexion* GetConnexion(std::uint16_t a_PeerId);
EnetConnection* GetConnection(std::uint16_t a_PeerId);
NazaraSignal(OnClientConnect, EnetConnexion& /*a_Peer*/);
NazaraSignal(OnClientDisconnect, EnetConnexion& /*a_Peer*/);
NazaraSignal(OnClientDisconnectTimeout, EnetConnexion& /*a_Peer*/);
NazaraSignal(OnClientConnect, EnetConnection& /*a_Peer*/);
NazaraSignal(OnClientDisconnect, EnetConnection& /*a_Peer*/);
NazaraSignal(OnClientDisconnectTimeout, EnetConnection& /*a_Peer*/);
private:
void Update();
void WorkerThread();
void RemoveConnexion(std::uint16_t a_PeerId);
void RemoveConnection(std::uint16_t a_PeerId);
Nz::ENetHost m_Host;
bool m_Running;
std::thread m_Thread;
std::map<std::uint16_t, std::unique_ptr<EnetConnexion>> m_Connexion;
std::map<std::uint16_t, std::unique_ptr<EnetConnection>> m_Connections;
};
} // namespace network

View File

@@ -0,0 +1,23 @@
#pragma once
#include <Nazara/Core/EnttWorld.hpp>
#include <blitz/network/EnetConnection.h>
namespace blitz {
using EnttWorld = std::atomic<std::shared_ptr<Nz::EnttWorld>>;
namespace protocol {
class PacketHandler : private NonCopyable {
public:
PacketHandler(network::EnetConnection& a_Connection, EnttWorld& a_World);
virtual ~PacketHandler();
protected:
network::EnetConnection& m_Connection;
EnttWorld& m_World;
};
} // namespace protocol
} // namespace blitz