iw4x-client/src/Components/Modules/Node.hpp
Louve f3c15f2cda
Json11 => NlohmannJson (#393)
* Json11 => NlohmannJson

* Fix release build

* Updated gitmodulie

* Address review

* Update .gitmodules

Co-authored-by: rackover <roxanne@thegamebakers.com>
Co-authored-by: Edo <edoardo.sanguineti222@gmail.com>
2022-07-29 21:54:18 +02:00

63 lines
1.1 KiB
C++

#pragma once
#define NODE_HALFLIFE (3 * 60 * 1000) //3min
#define NODE_MAX_NODES_TO_SEND 64
#define NODE_SEND_RATE 500ms
namespace Components
{
class Node : public Component
{
public:
class Data
{
public:
uint64_t protocol;
};
class Entry
{
public:
Network::Address address;
Data data;
std::optional<Utils::Time::Point> lastRequest;
std::optional<Utils::Time::Point> lastResponse;
bool isValid();
bool isDead();
bool requiresRequest();
void sendRequest();
void reset();
nlohmann::json to_json() const;
};
Node();
~Node();
static void Add(Network::Address address);
static std::vector<Entry> GetNodes();
static void RunFrame();
static void Synchronize();
static void LoadNodeRemotePreset();
private:
static std::recursive_mutex Mutex;
static std::vector<Entry> Nodes;
static bool wasIngame;
static void HandleResponse(Network::Address address, const std::string& data);
static void SendList(const Network::Address& address);
static void LoadNodePreset();
static void LoadNodes();
static void StoreNodes(bool force);
static unsigned short GetPort();
};
}