Merge branch 'configurable-spam-protection' into 'next'

Make chat spam protection more configurable

See merge request STJr/SRB2!2127
This commit is contained in:
Logan Aerl Arias 2023-12-25 23:59:07 +00:00
commit 8e86cf6a5c
4 changed files with 33 additions and 14 deletions

View file

@ -308,7 +308,9 @@ consvar_t cv_chatheight= CVAR_INIT ("chatheight", "8", CV_SAVE, chatheight_cons_
consvar_t cv_chatnotifications= CVAR_INIT ("chatnotifications", "On", CV_SAVE, CV_OnOff, NULL);
// chat spam protection (why would you want to disable that???)
consvar_t cv_chatspamprotection= CVAR_INIT ("chatspamprotection", "On", CV_SAVE, CV_OnOff, NULL);
consvar_t cv_chatspamprotection= CVAR_INIT ("chatspamprotection", "On", CV_SAVE|CV_NETVAR, CV_OnOff, NULL);
consvar_t cv_chatspamspeed= CVAR_INIT ("chatspamspeed", "35", CV_SAVE|CV_NETVAR, CV_Unsigned, NULL);
consvar_t cv_chatspamburst= CVAR_INIT ("chatspamburst", "3", CV_SAVE|CV_NETVAR, CV_Unsigned, NULL);
// minichat text background
consvar_t cv_chatbacktint = CVAR_INIT ("chatbacktint", "On", CV_SAVE, CV_OnOff, NULL);

View file

@ -53,7 +53,7 @@ extern consvar_t cv_instantretry;
// used in game menu
extern consvar_t cv_tutorialprompt;
extern consvar_t cv_chatwidth, cv_chatnotifications, cv_chatheight, cv_chattime, cv_consolechat, cv_chatbacktint, cv_chatspamprotection, cv_compactscoreboard;
extern consvar_t cv_chatwidth, cv_chatnotifications, cv_chatheight, cv_chattime, cv_consolechat, cv_chatbacktint, cv_chatspamprotection, cv_chatspamspeed, cv_chatspamburst, cv_compactscoreboard;
extern consvar_t cv_crosshair, cv_crosshair2;
extern consvar_t cv_invertmouse, cv_alwaysfreelook, cv_chasefreelook, cv_mousemove;
extern consvar_t cv_invertmouse2, cv_alwaysfreelook2, cv_chasefreelook2, cv_mousemove2;

View file

@ -619,7 +619,9 @@ static void Command_CSay_f(void)
DoSayCommand(0, 1, HU_CSAY);
}
static tic_t stop_spamming[MAXPLAYERS];
static tic_t spam_tokens[MAXPLAYERS];
static tic_t spam_tics[MAXPLAYERS];
/** Receives a message, processing an ::XD_SAY command.
* \sa DoSayCommand
@ -671,14 +673,14 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum)
// before we do anything, let's verify the guy isn't spamming, get this easier on us.
//if (stop_spamming[playernum] != 0 && cv_chatspamprotection.value && !(flags & HU_CSAY))
if (stop_spamming[playernum] != 0 && consoleplayer != playernum && cv_chatspamprotection.value && !(flags & HU_CSAY))
if (spam_tokens[playernum] <= 0 && cv_chatspamprotection.value && !(flags & HU_CSAY))
{
CONS_Debug(DBG_NETPLAY,"Received SAY cmd too quickly from Player %d (%s), assuming as spam and blocking message.\n", playernum+1, player_names[playernum]);
stop_spamming[playernum] = 4;
spam_tics[playernum] = 0;
spam_eatmsg = 1;
}
else
stop_spamming[playernum] = 4; // you can hold off for 4 tics, can you?
spam_tokens[playernum] -= 1;
// run the lua hook even if we were supposed to eat the msg, netgame consistency goes first.
@ -858,6 +860,25 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum)
//
void HU_Ticker(void)
{
// do this server-side, too
if (netgame)
{
size_t i = 0;
// handle spam while we're at it:
for(; (i<MAXPLAYERS); i++)
{
if (spam_tokens[i] < (tic_t)cv_chatspamburst.value)
{
if (++spam_tics[i] >= (tic_t)cv_chatspamspeed.value)
{
spam_tokens[i]++;
spam_tics[i] = 0;
}
}
}
}
if (dedicated)
return;
@ -880,13 +901,6 @@ void HU_Ticker(void)
{
size_t i = 0;
// handle spam while we're at it:
for(; (i<MAXPLAYERS); i++)
{
if (stop_spamming[i] > 0)
stop_spamming[i]--;
}
// handle chat timers
for (i=0; (i<chat_nummsg_min); i++)
{

View file

@ -620,6 +620,10 @@ void D_RegisterServerCommands(void)
CV_RegisterVar(&cv_addons_folder);
CV_RegisterVar(&cv_dummyconsvar);
CV_RegisterVar(&cv_chatspamprotection);
CV_RegisterVar(&cv_chatspamspeed);
CV_RegisterVar(&cv_chatspamburst);
}
// =========================================================================
@ -763,7 +767,6 @@ void D_RegisterClientCommands(void)
CV_RegisterVar(&cv_chatheight);
CV_RegisterVar(&cv_chatwidth);
CV_RegisterVar(&cv_chattime);
CV_RegisterVar(&cv_chatspamprotection);
CV_RegisterVar(&cv_chatbacktint);
CV_RegisterVar(&cv_consolechat);
CV_RegisterVar(&cv_chatnotifications);