3 * Protects against chat flooding.
4 * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 public Plugin:myinfo =
30 author = "AlliedModders LLC",
31 description = "Protects against chat flooding",
32 version = SOURCEMOD_VERSION,
33 url = "http://www.sourcemod.net/"
36 new Float:g_LastTime[MAXPLAYERS + 1] = {0.0, ...}; /* Last time player used say or say_team */
37 new g_FloodTokens[MAXPLAYERS + 1] = {0, ...}; /* Number of flood tokens player has */
39 new Handle:sm_flood_time; /* Handle to sm_flood_time convar */
41 public OnPluginStart()
43 LoadTranslations("plugin.antiflood");
45 RegConsoleCmd("say", CheckChatFlood);
46 RegConsoleCmd("say_team", CheckChatFlood);
47 sm_flood_time = CreateConVar("sm_flood_time", "0.75", "Amount of time allowed between chat messages");
50 public Action:CheckChatFlood(client, args)
52 /* Chat from server console shouldn't be checked for flooding */
55 return Plugin_Continue;
58 new Float:maxChat = GetConVarFloat(sm_flood_time);
62 new Float:curTime = GetGameTime();
64 if (g_LastTime[client] > curTime)
66 /* If player has 3 or more flood tokens, block their message */
67 if (g_FloodTokens[client] >= 3)
69 PrintToChat(client, "[SM] %t", "Flooding the server");
70 g_LastTime[client] = curTime + maxChat + 3.0;
75 /* Add one flood token when player goes over chat time limit */
76 g_FloodTokens[client]++;
77 } else if (g_FloodTokens[client]) {
78 /* Remove one flood token when player chats within time limit (slow decay) */
79 g_FloodTokens[client]--;
82 /* Store last time of chat usage */
83 g_LastTime[client] = curTime + maxChat;
86 return Plugin_Continue;