2024-10-06 20:08:22 -07:00
|
|
|
#pragma once
|
|
|
|
|
2024-10-06 22:54:29 -07:00
|
|
|
#include "ehs/io/socket/ehc/NetEnc.h"
|
2024-10-06 20:08:22 -07:00
|
|
|
#include "ehs/Array.h"
|
|
|
|
#include "Socket.h"
|
|
|
|
#include "UDP.h"
|
|
|
|
|
|
|
|
namespace ehs
|
|
|
|
{
|
2025-01-26 21:43:17 -08:00
|
|
|
class NetServerCh;
|
|
|
|
class NetClientCh;
|
2024-10-06 20:08:22 -07:00
|
|
|
class NetEnd;
|
|
|
|
class EHC;
|
|
|
|
|
|
|
|
class EHC
|
|
|
|
{
|
|
|
|
private:
|
2024-10-06 22:54:29 -07:00
|
|
|
friend class NetEnc;
|
2025-01-26 21:43:17 -08:00
|
|
|
friend class NetChannel;
|
|
|
|
friend class NetServerCh;
|
|
|
|
friend class NetClientCh;
|
2024-10-06 20:08:22 -07:00
|
|
|
friend class NetEnd;
|
|
|
|
|
|
|
|
static const Version version;
|
|
|
|
|
|
|
|
UDP udp;
|
|
|
|
Byte* buffer;
|
|
|
|
UInt_32 bufferSize;
|
2025-01-26 21:43:17 -08:00
|
|
|
UInt_64 lastTSC;
|
|
|
|
float delta;
|
2024-10-06 22:54:29 -07:00
|
|
|
Array<NetEnc *> encryptions;
|
2025-01-26 21:43:17 -08:00
|
|
|
Array<NetServerCh *> servers;
|
|
|
|
Array<NetClientCh *> clients;
|
2024-10-06 20:08:22 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
~EHC();
|
|
|
|
|
2025-01-26 21:43:17 -08:00
|
|
|
EHC(IP version = IP::V6);
|
2024-10-06 20:08:22 -07:00
|
|
|
|
|
|
|
EHC(EHC &&sock) noexcept;
|
|
|
|
|
|
|
|
EHC(const EHC &sock);
|
|
|
|
|
|
|
|
EHC &operator=(EHC&& sock) noexcept;
|
|
|
|
|
|
|
|
EHC &operator=(const EHC &sock);
|
|
|
|
|
|
|
|
void Initialize();
|
|
|
|
|
|
|
|
void Release();
|
|
|
|
|
2025-01-26 21:43:17 -08:00
|
|
|
void Bind(const Endpoint &endpoint);
|
2024-10-06 20:08:22 -07:00
|
|
|
|
|
|
|
void Poll();
|
|
|
|
|
|
|
|
bool IsInitialized() const;
|
|
|
|
|
2025-01-26 21:43:17 -08:00
|
|
|
Endpoint GetLocalEndpoint() const;
|
2024-10-06 20:08:22 -07:00
|
|
|
|
|
|
|
bool IsBound() const;
|
|
|
|
|
|
|
|
static Version GetVersion();
|
|
|
|
|
2024-10-06 22:54:29 -07:00
|
|
|
bool AddEncryption(NetEnc *enc);
|
|
|
|
|
2025-01-26 21:43:17 -08:00
|
|
|
bool AddServer(NetServerCh *server);
|
2024-10-06 20:08:22 -07:00
|
|
|
|
2025-01-26 21:43:17 -08:00
|
|
|
bool AddClient(NetClientCh *channel);
|
2024-10-06 20:08:22 -07:00
|
|
|
|
2025-01-26 21:43:17 -08:00
|
|
|
private:
|
|
|
|
bool HasEncryption(UInt_64 encId) const;
|
2024-10-06 20:08:22 -07:00
|
|
|
|
2025-01-26 21:43:17 -08:00
|
|
|
bool HasEncryption(const Str_8& encName) const;
|
2024-10-06 20:08:22 -07:00
|
|
|
|
2025-01-26 21:43:17 -08:00
|
|
|
NetEnc* GetEncryption(UInt_64 encId) const;
|
2024-10-06 20:08:22 -07:00
|
|
|
|
2025-01-26 21:43:17 -08:00
|
|
|
NetEnc* GetEncryption(const Str_8& encName) const;
|
2024-10-06 20:08:22 -07:00
|
|
|
|
2025-01-26 21:43:17 -08:00
|
|
|
bool HasServer(UInt_64 serverId) const;
|
2024-10-06 20:08:22 -07:00
|
|
|
|
2025-01-26 21:43:17 -08:00
|
|
|
bool HasServer(const Str_8& serverName) const;
|
2024-10-06 20:08:22 -07:00
|
|
|
|
2025-01-26 21:43:17 -08:00
|
|
|
NetServerCh *GetServer(UInt_64 serverId) const;
|
2024-10-06 20:08:22 -07:00
|
|
|
|
2025-01-26 21:43:17 -08:00
|
|
|
NetServerCh *GetServer(const Str_8& serverName) const;
|
2024-10-06 20:08:22 -07:00
|
|
|
|
2025-01-26 21:43:17 -08:00
|
|
|
bool HasClient(UInt_64 clientId) const;
|
2024-10-06 20:08:22 -07:00
|
|
|
|
2025-01-26 21:43:17 -08:00
|
|
|
bool HasClient(const Str_8& clientName) const;
|
2024-10-06 20:08:22 -07:00
|
|
|
|
2025-01-26 21:43:17 -08:00
|
|
|
NetClientCh *GetClient(UInt_64 clientId) const;
|
2024-10-06 20:08:22 -07:00
|
|
|
|
2025-01-26 21:43:17 -08:00
|
|
|
NetClientCh *GetClient(const Str_8& clientName) const;
|
2024-10-06 20:08:22 -07:00
|
|
|
};
|
|
|
|
}
|