aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/shared/exploit_fixes/ns_limits.h
blob: a2cc431fcbf4b4ad33e3bf9b99b8c7785d136134 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once
#include "engine/r2engine.h"
#include "core/convar/convar.h"
#include <unordered_map>

struct PlayerLimitData
{
	double lastClientCommandQuotaStart = -1.0;
	int numClientCommandsInQuota = 0;

	double lastNetChanProcessingLimitStart = -1.0;
	double netChanProcessingLimitTime = 0.0;

	double lastSayTextLimitStart = -1.0;
	int sayTextLimitCount = 0;

	float flFrameUserCmdBudget = 0.0;
};

struct UnconnectedPlayerLimitData
{
	char ip[16];
	double lastQuotaStart = 0.0;
	int packetCount = 0;
	double timeoutEnd = -1.0;
};

class ServerLimitsManager
{
  public:
	ConVar* CVar_sv_quota_stringcmdspersecond;
	ConVar* Cvar_net_chan_limit_mode;
	ConVar* Cvar_net_chan_limit_msec_per_sec;
	ConVar* Cvar_sv_querylimit_per_sec;
	ConVar* Cvar_sv_max_chat_messages_per_sec;
	ConVar* Cvar_sv_antispeedhack_enable;
	ConVar* Cvar_sv_antispeedhack_maxtickbudget;
	ConVar* Cvar_sv_antispeedhack_budgetincreasemultiplier;

	std::unordered_map<CBaseClient*, PlayerLimitData> m_PlayerLimitData;
	std::vector<UnconnectedPlayerLimitData> m_UnconnectedPlayerLimitData;

  public:
	void RunFrame(double flCurrentTime, float flFrameTime);
	void AddPlayer(CBaseClient* player);
	void RemovePlayer(CBaseClient* player);
	bool CheckStringCommandLimits(CBaseClient* player);
	bool CheckChatLimits(CBaseClient* player);
	bool CheckConnectionlessPacketLimits(netpacket_t* packet);
};

extern ServerLimitsManager* g_pServerLimits;