Files
Blitz2/include/blitz/network/EnetServer.h
2024-08-07 11:50:07 +02:00

42 lines
927 B
C++

#pragma once
#include <Nazara/Core/ThreadExt.hpp>
#include <Nazara/Network/ENetHost.hpp>
#include <blitz/network/EnetConnection.h>
#include <cstdint>
#include <map>
#include <thread>
namespace blitz {
namespace network {
class EnetServer : private NonCopyable {
public:
EnetServer(std::uint16_t port);
~EnetServer();
void Destroy();
void CloseConnection(std::uint16_t a_PeerId);
EnetConnection* GetConnection(std::uint16_t a_PeerId);
NazaraSignal(OnClientConnect, EnetConnection& /*a_Peer*/);
NazaraSignal(OnClientDisconnect, EnetConnection& /*a_Peer*/);
NazaraSignal(OnClientDisconnectTimeout, EnetConnection& /*a_Peer*/);
private:
void Update();
void WorkerThread();
void RemoveConnection(std::uint16_t a_PeerId);
Nz::ENetHost m_Host;
bool m_Running;
std::jthread m_Thread;
std::map<std::uint16_t, std::unique_ptr<EnetConnection>> m_Connections;
};
} // namespace network
} // namespace blitz