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

60 lines
1.0 KiB
C++
Raw Normal View History

2017-01-20 08:36:52 -05:00
#pragma once
2017-06-26 17:23:08 -04:00
#define NODE_HALFLIFE (3 * 60 * 1000) //3min
2017-06-25 15:54:35 -04:00
#define NODE_REQUEST_LIMIT 3
2017-01-19 16:23:59 -05:00
namespace Components
{
class Node : public Component
{
public:
2017-06-25 15:54:35 -04:00
class Data
2017-01-19 16:23:59 -05:00
{
2017-06-25 15:54:35 -04:00
public:
uint64_t protocol;
2017-01-19 16:23:59 -05:00
};
2017-06-25 15:54:35 -04:00
class Entry
2017-01-19 16:23:59 -05:00
{
public:
Network::Address address;
2017-06-25 15:54:35 -04:00
Data data;
2017-01-19 16:23:59 -05:00
2017-06-25 15:54:35 -04:00
std::optional<Utils::Time::Point> lastRequest;
std::optional<Utils::Time::Point> lastResponse;
Utils::Time::Point creationPoint;
2017-01-19 16:23:59 -05:00
2017-06-25 15:54:35 -04:00
bool isValid();
bool isDead();
2017-01-19 16:23:59 -05:00
2017-06-25 15:54:35 -04:00
bool requiresRequest();
void sendRequest();
2017-06-25 06:44:09 -04:00
2017-06-25 15:54:35 -04:00
void reset();
2017-01-19 16:23:59 -05:00
};
2017-06-25 15:54:35 -04:00
Node();
~Node();
2017-01-19 16:23:59 -05:00
2017-06-25 15:54:35 -04:00
static void Add(Network::Address address);
static void RunFrame();
static void Synchronize();
2017-01-19 16:23:59 -05:00
2017-06-25 15:54:35 -04:00
static void LoadNodeRemotePreset();
2017-01-19 16:23:59 -05:00
2017-06-25 15:54:35 -04:00
private:
static std::recursive_mutex Mutex;
static std::vector<Entry> Nodes;
2017-01-19 16:23:59 -05:00
2017-06-25 15:54:35 -04:00
static void HandleResponse(Network::Address address, std::string data);
2017-01-19 16:23:59 -05:00
2017-06-25 15:54:35 -04:00
static void SendList(Network::Address address);
2017-01-19 16:23:59 -05:00
2017-06-25 15:54:35 -04:00
static void LoadNodePreset();
static void LoadNodes();
static void StoreNodes(bool force);
2017-05-31 17:45:30 -04:00
2017-06-25 15:54:35 -04:00
static unsigned short GetPort();
2017-01-19 16:23:59 -05:00
};
}