iw4x-client/src/Components/Modules/Node.hpp

63 lines
1.1 KiB
C++
Raw Normal View History

2018-10-09 04:53:15 -04:00
#pragma once
#define NODE_HALFLIFE (3 * 60 * 1000) //3min
#define NODE_MAX_NODES_TO_SEND 64
#define NODE_SEND_RATE 500ms
2018-10-09 04:53:15 -04:00
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;
2018-10-09 04:53:15 -04:00
};
Node();
~Node();
static void Add(Network::Address address);
2018-12-02 12:17:45 -05:00
static std::vector<Entry> GetNodes();
2018-10-09 04:53:15 -04:00
static void RunFrame();
static void Synchronize();
static void LoadNodeRemotePreset();
private:
static std::recursive_mutex Mutex;
static std::vector<Entry> Nodes;
static bool wasIngame;
2018-12-17 08:29:18 -05:00
static void HandleResponse(Network::Address address, const std::string& data);
2018-10-09 04:53:15 -04:00
2022-06-16 10:15:26 -04:00
static void SendList(const Network::Address& address);
2018-10-09 04:53:15 -04:00
static void LoadNodePreset();
static void LoadNodes();
static void StoreNodes(bool force);
static unsigned short GetPort();
};
}