summaryrefslogtreecommitdiff
path: root/src/game/g_cmds.c
diff options
context:
space:
mode:
authorBen Millwood <thebenmachine@gmail.com>2009-10-03 12:04:16 +0000
committerTim Angus <tim@ngus.net>2013-01-03 00:15:39 +0000
commitc29de5a7d5984c27fd85305aaab69e8d88db6d71 (patch)
tree73393543e9eda6247b9238f9ea8e96a98db931c3 /src/game/g_cmds.c
parent33a2c3494a0be2050c8a2e4757764fd55056480c (diff)
* Flood protection in chat and admin commands
(thanks to Phil Bordelon, Chris "Lakitu7" Schwarz, and M. Kristall)
Diffstat (limited to 'src/game/g_cmds.c')
-rw-r--r--src/game/g_cmds.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c
index 57b43c85..86a26483 100644
--- a/src/game/g_cmds.c
+++ b/src/game/g_cmds.c
@@ -3025,6 +3025,41 @@ void Cmd_Damage_f( gentity_t *ent )
( nonloc ? DAMAGE_NO_LOCDAMAGE : 0 ), MOD_TARGET_LASER );
}
+/*
+==================
+G_FloodLimited
+
+Determine whether a user is flood limited, and adjust their flood demerits
+Notify them if this is the first time they were over the limit
+==================
+*/
+qboolean G_FloodLimited( gentity_t *ent )
+{
+ int deltatime = level.time - ent->client->pers.floodTime;
+ int flooding;
+
+ if( g_floodMinTime.integer <= 0 )
+ return qfalse;
+
+ if( G_admin_permission( ent, ADMF_NOCENSORFLOOD ) )
+ return qfalse;
+
+ ent->client->pers.floodDemerits += g_floodMinTime.integer - deltatime;
+ if( ent->client->pers.floodDemerits < 0 )
+ ent->client->pers.floodDemerits = 0;
+ ent->client->pers.floodTime = level.time;
+
+ flooding = ent->client->pers.floodDemerits - g_floodMaxDemerits.integer;
+ if( flooding <= 0 )
+ return qfalse;
+ // seconds (rounded up)
+ flooding = ( flooding + 999 ) / 1000;
+ trap_SendServerCommand( ent - g_entities, va( "print \"You are flooding: "
+ "please wait %d second%s before trying again\n",
+ flooding, ( flooding != 1 ) ? "s" : "" ) );
+ return qtrue;
+}
+
commands_t cmds[ ] = {
// normal commands
{ "team", 0, Cmd_Team_f },
@@ -3125,7 +3160,8 @@ void ClientCommand( int clientNum )
return;
}
- if( cmds[ i ].cmdFlags & CMD_MESSAGE && ent->client->pers.muted )
+ if( cmds[ i ].cmdFlags & CMD_MESSAGE && ( ent->client->pers.muted ||
+ G_FloodLimited( ent ) ) )
return;
if( cmds[ i ].cmdFlags & CMD_TEAM &&