3 * =============================================================================
4 * SourceMod Anti-Flood Plugin
5 * Protects against chat flooding.
7 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
8 * =============================================================================
10 * This program is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License, version 3.0, as published by the
12 * Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
22 * As a special exception, AlliedModders LLC gives you permission to link the
23 * code of this program (as well as its derivative works) to "Half-Life 2," the
24 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
25 * by the Valve Corporation. You must obey the GNU General Public License in
26 * all respects for all other code used. Additionally, AlliedModders LLC grants
27 * this exception to all derivative works. AlliedModders LLC defines further
28 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
29 * or <http://www.sourcemod.net/license.php>.
38 public Plugin:myinfo =
41 author = "AlliedModders LLC",
42 description = "Protects against chat flooding",
43 version = SOURCEMOD_VERSION,
44 url = "http://www.sourcemod.net/"
47 new Float:g_LastTime[MAXPLAYERS + 1] = {0.0, ...}; /* Last time player used say or say_team */
48 new g_FloodTokens[MAXPLAYERS + 1] = {0, ...}; /* Number of flood tokens player has */
50 new Handle:sm_flood_time; /* Handle to sm_flood_time convar */
52 public OnPluginStart()
54 LoadTranslations("antiflood.phrases");
56 RegConsoleCmd("say", CheckChatFlood);
57 RegConsoleCmd("say_team", CheckChatFlood);
58 sm_flood_time = CreateConVar("sm_flood_time", "0.75", "Amount of time allowed between chat messages");
61 public OnClientPutInServer(client)
63 g_LastTime[client] = 0.0;
64 g_FloodTokens[client] = 0;
67 public Action:CheckChatFlood(client, args)
69 /* Chat from server console shouldn't be checked for flooding */
72 return Plugin_Continue;
75 new Float:maxChat = GetConVarFloat(sm_flood_time);
79 new Float:curTime = GetGameTime();
81 if (g_LastTime[client] > curTime)
83 /* If player has 3 or more flood tokens, block their message */
84 if (g_FloodTokens[client] >= 3)
86 PrintToChat(client, "[SM] %t", "Flooding the server");
87 g_LastTime[client] = curTime + maxChat + 3.0;
92 /* Add one flood token when player goes over chat time limit */
93 g_FloodTokens[client]++;
94 } else if (g_FloodTokens[client]) {
95 /* Remove one flood token when player chats within time limit (slow decay) */
96 g_FloodTokens[client]--;
99 /* Store last time of chat usage */
100 g_LastTime[client] = curTime + maxChat;
103 return Plugin_Continue;