ds@913: /** ds@913: * antiflood.sp ds@913: * Protects against chat flooding. ds@913: * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC ds@913: * ds@913: * This program is free software; you can redistribute it and/or ds@913: * modify it under the terms of the GNU General Public License ds@913: * as published by the Free Software Foundation; either version 2 ds@913: * of the License, or (at your option) any later version. ds@913: * ds@913: * This program is distributed in the hope that it will be useful, ds@913: * but WITHOUT ANY WARRANTY; without even the implied warranty of ds@913: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ds@913: * GNU General Public License for more details. ds@913: * ds@913: * You should have received a copy of the GNU General Public License ds@913: * along with this program; if not, write to the Free Software ds@913: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ds@913: * ds@913: * Version: $Id$ ds@913: */ ds@989: ds@989: #pragma semicolon 1 ds@913: ds@913: #include ds@913: ds@913: public Plugin:myinfo = ds@913: { ds@913: name = "Anti-Flood", ds@913: author = "AlliedModders LLC", ds@913: description = "Protects against chat flooding", ds@913: version = SOURCEMOD_VERSION, ds@913: url = "http://www.sourcemod.net/" ds@913: }; ds@913: ds@913: new Float:g_LastTime[MAXPLAYERS + 1] = {0.0, ...}; /* Last time player used say or say_team */ ds@913: new g_FloodTokens[MAXPLAYERS + 1] = {0, ...}; /* Number of flood tokens player has */ ds@913: ds@913: new Handle:sm_flood_time; /* Handle to sm_flood_time convar */ ds@913: ds@913: public OnPluginStart() ds@913: { dvander@1027: LoadTranslations("plugin.antiflood"); ds@913: ds@913: RegConsoleCmd("say", CheckChatFlood); ds@913: RegConsoleCmd("say_team", CheckChatFlood); ds@913: sm_flood_time = CreateConVar("sm_flood_time", "0.75", "Amount of time allowed between chat messages"); ds@913: } ds@913: ds@913: public Action:CheckChatFlood(client, args) ds@913: { ds@913: /* Chat from server console shouldn't be checked for flooding */ ds@913: if (client == 0) ds@913: { ds@913: return Plugin_Continue; ds@913: } ds@913: ds@913: new Float:maxChat = GetConVarFloat(sm_flood_time); ds@913: ds@913: if (maxChat > 0.0) ds@913: { ds@913: new Float:curTime = GetGameTime(); ds@913: ds@913: if (g_LastTime[client] > curTime) ds@913: { ds@913: /* If player has 3 or more flood tokens, block their message */ ds@913: if (g_FloodTokens[client] >= 3) ds@913: { ds@913: PrintToChat(client, "[SM] %t", "Flooding the server"); ds@913: g_LastTime[client] = curTime + maxChat + 3.0; ds@913: ds@913: return Plugin_Stop; ds@913: } ds@913: ds@913: /* Add one flood token when player goes over chat time limit */ ds@913: g_FloodTokens[client]++; ds@913: } else if (g_FloodTokens[client]) { ds@913: /* Remove one flood token when player chats within time limit (slow decay) */ ds@913: g_FloodTokens[client]--; ds@913: } ds@913: ds@913: /* Store last time of chat usage */ ds@913: g_LastTime[client] = curTime + maxChat; ds@913: } ds@913: ds@913: return Plugin_Continue; ds@913: }