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

90 lines
2.2 KiB
C++
Raw Normal View History

2016-01-28 15:37:48 -05:00
#define HEARTBEAT_DEADLINE 1000 * 3 * 10 // Invalidate servers after 10 minutes without heartbeat
#define HEARTBEAT_INTERVAL 1000 * 10 * 1 // Send heartbeats to each node every 3 minutes
#define NODE_VALIDITY_EXPIRE 1000 * 60 * 2 // Revalidate nodes after 2 minutes
#define DEDI_VALIDITY_EXPIRE 1000 * 60 * 2 // Revalidate dedis after 2 minutes
#define NODE_QUERY_TIMEOUT 1000 * 30 * 1 // Invalidate nodes after 30 seconds without query response
#define DEDI_QUERY_TIMEOUT 1000 * 10 * 1 // Invalidate dedis after 10 seconds without query response
#define HEARTBEATS_FRAME_LIMIT 1 // Limit of heartbeats sent to nodes per frame
#define NODE_FRAME_QUERY_LIMIT 1 // Limit of nodes to be queried per frame
#define DEDI_FRAME_QUERY_LIMIT 1 // Limit of dedis to be queried per frame
2016-01-28 10:19:43 -05:00
namespace Components
{
class Node : public Component
{
public:
Node();
~Node();
const char* GetName() { return "Node"; };
2016-01-28 15:37:48 -05:00
static void ValidateDedi(Network::Address address, Utils::InfoString info);
2016-01-28 10:19:43 -05:00
private:
enum EntryState
{
STATE_UNKNOWN,
STATE_QUERYING,
STATE_VALID,
STATE_INVALID
};
struct NodeEntry
{
Network::Address address;
EntryState state;
int startTime;
int endTime;
2016-01-28 15:37:48 -05:00
int lastHeartbeat;
2016-01-28 10:19:43 -05:00
};
struct DediEntry
{
Network::Address address;
2016-01-28 15:37:48 -05:00
std::string challenge;
2016-01-28 10:19:43 -05:00
EntryState state;
int startTime;
int endTime;
};
#pragma pack(push, 1)
struct AddressEntry
{
Game::netIP_t ip;
unsigned short port;
Network::Address toNetAddress()
{
Network::Address address;
address.SetIP(this->ip);
address.SetPort(ntohs(this->port));
address.SetType(Game::netadrtype_t::NA_IP);
return address;
}
void fromNetAddress(Network::Address address)
{
this->ip = address.GetIP();
this->port = htons(address.GetPort());
}
};
#pragma pack(pop)
static std::vector<NodeEntry> Nodes;
static std::vector<DediEntry> Dedis;
static void LoadNodes();
static void StoreNodes();
static void AddNode(Network::Address address, bool valid = false);
2016-01-28 15:37:48 -05:00
static void AddDedi(Network::Address address, bool dirty = false);
2016-01-28 10:19:43 -05:00
static void SendNodeList(Network::Address target);
static void SendDediList(Network::Address target);
};
}