ds@1952: /** ds@1952: * vim: set ts=4 : ds@1952: * ============================================================================= ds@1952: * SourceMod Anti-Flood Plugin ds@1952: * Protects against chat flooding. ds@1952: * ds@1952: * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. ds@1952: * ============================================================================= ds@1952: * ds@1952: * This program is free software; you can redistribute it and/or modify it under ds@1952: * the terms of the GNU General Public License, version 3.0, as published by the ds@1952: * Free Software Foundation. ds@1952: * ds@1952: * This program is distributed in the hope that it will be useful, but WITHOUT ds@1952: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ds@1952: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ds@1952: * details. ds@1952: * ds@1952: * You should have received a copy of the GNU General Public License along with ds@1952: * this program. If not, see . ds@1952: * ds@1952: * As a special exception, AlliedModders LLC gives you permission to link the ds@1952: * code of this program (as well as its derivative works) to "Half-Life 2," the ds@1952: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software ds@1952: * by the Valve Corporation. You must obey the GNU General Public License in ds@1952: * all respects for all other code used. Additionally, AlliedModders LLC grants ds@1952: * this exception to all derivative works. AlliedModders LLC defines further ds@1952: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), ds@1952: * or . ds@1952: * ds@1952: * Version: $Id$ ds@1952: */ ds@1952: ds@1952: #pragma semicolon 1 ds@1952: ds@1952: #include ds@1952: ds@1952: public Plugin:myinfo = ds@1952: { ds@1952: name = "Anti-Flood", ds@1952: author = "AlliedModders LLC", ds@1952: description = "Protects against chat flooding", ds@1952: version = SOURCEMOD_VERSION, ds@1952: url = "http://www.sourcemod.net/" ds@1952: }; ds@1952: ds@1952: new Float:g_LastTime[MAXPLAYERS + 1] = {0.0, ...}; /* Last time player used say or say_team */ ds@1952: new g_FloodTokens[MAXPLAYERS + 1] = {0, ...}; /* Number of flood tokens player has */ ds@1952: ds@1952: new Handle:sm_flood_time; /* Handle to sm_flood_time convar */ ds@1952: ds@1952: public OnPluginStart() ds@1952: { ds@1952: sm_flood_time = CreateConVar("sm_flood_time", "0.75", "Amount of time allowed between chat messages"); ds@1952: } ds@1952: ds@1952: public OnClientPutInServer(client) ds@1952: { ds@1952: g_LastTime[client] = 0.0; ds@1952: g_FloodTokens[client] = 0; ds@1952: } ds@1952: ds@1952: new Float:max_chat; ds@1952: ds@1952: public bool:OnClientFloodCheck(client) ds@1952: { ds@1952: max_chat = GetConVarFloat(sm_flood_time); ds@1952: ds@1952: if (max_chat <= 0.0 ds@1952: || (GetUserFlagBits(client) & ADMFLAG_ROOT) == ADMFLAG_ROOT) ds@1952: { ds@1952: return false; ds@1952: } ds@1952: ds@1952: if (g_LastTime[client] > GetGameTime()) ds@1952: { ds@1952: /* If player has 3 or more flood tokens, block their message */ ds@1952: if (g_FloodTokens[client] >= 3) ds@1952: { ds@1952: return true; ds@1952: } ds@1952: } ds@1952: ds@1952: return false; ds@1952: } ds@1952: ds@1952: public OnClientFloodResult(client, bool:blocked) ds@1952: { ds@1952: if (max_chat <= 0.0 ds@1952: || (GetUserFlagBits(client) & ADMFLAG_ROOT) == ADMFLAG_ROOT) ds@1952: { ds@1952: return; ds@1952: } ds@1952: ds@1952: new Float:curTime = GetGameTime(); ds@1952: new Float:newTime = curTime + max_chat; ds@1952: ds@1952: if (g_LastTime[client] > curTime) ds@1952: { ds@1952: /* If the last message was blocked, update their time limit */ ds@1952: if (blocked) ds@1952: { ds@1952: newTime += 3.0; ds@1952: } ds@1952: /* Add one flood token when player goes over chat time limit */ ds@1952: else if (g_FloodTokens[client] < 3) ds@1952: { ds@1952: g_FloodTokens[client]++; ds@1952: } ds@1952: } ds@1952: else if (g_FloodTokens[client] > 0) ds@1952: { ds@1952: /* Remove one flood token when player chats within time limit (slow decay) */ ds@1952: g_FloodTokens[client]--; ds@1952: } ds@1952: ds@1952: g_LastTime[client] = newTime; ds@1952: }