fully implement KeepAlive behavior
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
@@ -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
|
||||
|
||||
23
include/blitz/protocol/PacketHandler.h
Normal file
23
include/blitz/protocol/PacketHandler.h
Normal 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
|
||||
Reference in New Issue
Block a user