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

105 lines
2.9 KiB
C++
Raw Normal View History

#define HEARTBEAT_DEADLINE 1000 * 60 * 10 // Invalidate servers after 10 minutes without heartbeat
#define HEARTBEAT_INTERVAL 1000 * 60 * 3 // Send heartbeats to each node every 3 minutes
2016-01-28 15:37:48 -05:00
#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
2016-02-01 15:59:45 -05:00
#define NODE_INVALID_DELETE 1000 * 60 * 10 // Delete invalidated nodes after 10 minutes
#define DEDI_INVALID_DELETE 1000 * 60 * 10 // Delete invalidated dedis after 10 minutes
2016-01-28 15:37:48 -05:00
#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-02-01 15:59:45 -05:00
#define NODE_PACKET_LIMIT 111 // Send 111 nodes per synchronization packet
#define DEDI_PACKET_LIMIT 111 // Send 111 dedis per synchronization packet
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);
static std::vector<Network::Address> GetDediList();
2016-01-28 10:19:43 -05:00
private:
enum EntryState
{
STATE_UNKNOWN,
STATE_QUERYING,
STATE_VALID,
2016-02-01 15:59:45 -05:00
STATE_INVALID,
2016-01-28 10:19:43 -05:00
};
struct NodeEntry
{
Network::Address address;
EntryState state;
2016-02-01 15:59:45 -05:00
int lastTime; // Last time we heard anything from the server itself
int lastHeartbeat; // Last time we got a heartbeat from it
int lastHeard; // Last time we heard something of the server at all (refs form other nodes)
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;
2016-01-28 21:49:51 -05:00
int lastTime;
2016-02-01 15:59:45 -05:00
int lastHeard;
2016-01-28 10:19:43 -05:00
};
#pragma pack(push, 1)
struct AddressEntry
{
Game::netIP_t ip;
unsigned short port;
Network::Address toNetAddress()
{
Network::Address address;
address.SetIP(this->ip);
2016-01-28 19:53:17 -05:00
address.SetPort(ntohs(this->port));
2016-01-28 10:19:43 -05:00
address.SetType(Game::netadrtype_t::NA_IP);
return address;
}
void fromNetAddress(Network::Address address)
{
this->ip = address.GetIP();
2016-01-28 19:53:17 -05:00
this->port = htons(address.GetPort());
2016-01-28 10:19:43 -05:00
}
};
#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);
static void DeleteInvalidNodes();
static void DeleteInvalidDedis();
static void FrameHandler();
static const char* GetStateName(EntryState state);
2016-01-28 10:19:43 -05:00
};
}