mirror of
https://github.com/rehlds/rehlds.git
synced 2025-01-16 16:48:13 +03:00
Cvars for command flood punishments (#230)
* Cvars for command flood punishments Could we get something like this in the next build? * Update rehlds_security.cpp
This commit is contained in:
parent
78213296fc
commit
383e805356
@ -5,6 +5,11 @@ cvar_t sv_rehlds_movecmdrate_max_burst = { "sv_rehlds_movecmdrate_max_burst", "2
|
||||
cvar_t sv_rehlds_stringcmdrate_max_avg = {"sv_rehlds_stringcmdrate_max_avg", "80", 0, 80.0f, NULL};
|
||||
cvar_t sv_rehlds_stringcmdrate_max_burst = {"sv_rehlds_stringcmdrate_max_burst", "400", 0, 400.0f, NULL};
|
||||
|
||||
cvar_t sv_rehlds_movecmdrate_avg_punish = { "sv_rehlds_movecmdrate_avg_punish", "5", 0, 5.0f, NULL };
|
||||
cvar_t sv_rehlds_movecmdrate_burst_punish = { "sv_rehlds_movecmdrate_burst_punish", "5", 0, 5.0f, NULL };
|
||||
cvar_t sv_rehlds_stringcmdrate_avg_punish = {"sv_rehlds_stringcmdrate_avg_punish", "5", 0, 5.0f, NULL};
|
||||
cvar_t sv_rehlds_stringcmdrate_burst_punish = {"sv_rehlds_stringcmdrate_burst_punish", "5", 0, 5.0f, NULL};
|
||||
|
||||
CMoveCommandRateLimiter g_MoveCommandRateLimiter;
|
||||
CStringCommandsRateLimiter g_StringCommandsRateLimiter;
|
||||
|
||||
@ -56,10 +61,15 @@ void CMoveCommandRateLimiter::CheckBurstRate(unsigned int clientId) {
|
||||
dt = 0.2; //small intervals may give too high rates
|
||||
}
|
||||
if ((m_CurrentMoveCmds[clientId] / dt) > sv_rehlds_movecmdrate_max_burst.value) {
|
||||
Cbuf_AddText(va("addip %i %s\n", 5, NET_BaseAdrToString(cl->netchan.remote_address)));
|
||||
if(sv_rehlds_movecmdrate_burst_punish.value < 0) {
|
||||
SV_DropClient(cl, false, "Kicked for move commands flooding (burst)");
|
||||
}
|
||||
else {
|
||||
Cbuf_AddText(va("addip %.1f %s\n", sv_rehlds_movecmdrate_burst_punish.value, NET_BaseAdrToString(cl->netchan.remote_address)));
|
||||
SV_DropClient(cl, false, "Banned for move commands flooding (burst)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CMoveCommandRateLimiter::CheckAverageRate(unsigned int clientId) {
|
||||
client_t* cl = &g_psvs.clients[clientId];
|
||||
@ -68,10 +78,15 @@ void CMoveCommandRateLimiter::CheckAverageRate(unsigned int clientId) {
|
||||
}
|
||||
|
||||
if (m_AverageMoveCmdRate[clientId] > sv_rehlds_movecmdrate_max_avg.value) {
|
||||
Cbuf_AddText(va("addip %i %s\n", 5, NET_BaseAdrToString(cl->netchan.remote_address)));
|
||||
if(sv_rehlds_movecmdrate_avg_punish.value < 0) {
|
||||
SV_DropClient(cl, false, "Kicked for move commands flooding (Avg)");
|
||||
}
|
||||
else {
|
||||
Cbuf_AddText(va("addip %.1f %s\n", sv_rehlds_movecmdrate_avg_punish.value, NET_BaseAdrToString(cl->netchan.remote_address)));
|
||||
SV_DropClient(cl, false, "Banned for move commands flooding (Avg)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CStringCommandsRateLimiter::CStringCommandsRateLimiter() {
|
||||
Q_memset(m_AverageStringCmdRate, 0, sizeof(m_AverageStringCmdRate));
|
||||
@ -121,10 +136,15 @@ void CStringCommandsRateLimiter::CheckBurstRate(unsigned int clientId) {
|
||||
dt = 0.2; //small intervals may give too high rates
|
||||
}
|
||||
if ((m_CurrentStringCmds[clientId] / dt) > sv_rehlds_stringcmdrate_max_burst.value) {
|
||||
Cbuf_AddText(va("addip %i %s\n", 5, NET_BaseAdrToString(cl->netchan.remote_address)));
|
||||
if(sv_rehlds_stringcmdrate_burst_punish.value < 0) {
|
||||
SV_DropClient(cl, false, "Kicked for string commands flooding (burst)");
|
||||
}
|
||||
else {
|
||||
Cbuf_AddText(va("addip %.1f %s\n", sv_rehlds_stringcmdrate_burst_punish.value, NET_BaseAdrToString(cl->netchan.remote_address)));
|
||||
SV_DropClient(cl, false, "Banned for string commands flooding (burst)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CStringCommandsRateLimiter::CheckAverageRate(unsigned int clientId) {
|
||||
client_t* cl = &g_psvs.clients[clientId];
|
||||
@ -133,10 +153,15 @@ void CStringCommandsRateLimiter::CheckAverageRate(unsigned int clientId) {
|
||||
}
|
||||
|
||||
if (m_AverageStringCmdRate[clientId] > sv_rehlds_stringcmdrate_max_avg.value) {
|
||||
Cbuf_AddText(va("addip %i %s\n", 5, NET_BaseAdrToString(cl->netchan.remote_address)));
|
||||
if(sv_rehlds_stringcmdrate_avg_punish.value < 0) {
|
||||
SV_DropClient(cl, false, "Kicked for string commands flooding (Avg)");
|
||||
}
|
||||
else {
|
||||
Cbuf_AddText(va("addip %.1f %s\n", sv_rehlds_stringcmdrate_avg_punish.value, NET_BaseAdrToString(cl->netchan.remote_address)));
|
||||
SV_DropClient(cl, false, "Banned for string commands flooding (Avg)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Rehlds_Security_Init() {
|
||||
#ifdef REHLDS_FIXES
|
||||
|
Loading…
x
Reference in New Issue
Block a user