plugins/antiflood.sp
author Phong Dang <teame06@gmail.com>
Wed Aug 01 07:29:40 2007 +0000 (2007-08-01)
changeset 1241 2e8046793bc9
parent 1187 85c0934305bd
child 1330 ab94316bb52b
permissions -rw-r--r--
Added check to make sure player are alive to perform sm_slap, sm_burn, sm_slay.
     1 /**
     2  * antiflood.sp
     3  * Protects against chat flooding.
     4  * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC
     5  *
     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.
    10  *
    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.
    15  * 
    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.
    19  *
    20  * Version: $Id$
    21  */
    22  
    23 #pragma semicolon 1
    24 
    25 #include <sourcemod>
    26 
    27 public Plugin:myinfo = 
    28 {
    29 	name = "Anti-Flood",
    30 	author = "AlliedModders LLC",
    31 	description = "Protects against chat flooding",
    32 	version = SOURCEMOD_VERSION,
    33 	url = "http://www.sourcemod.net/"
    34 };
    35 
    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 */
    38 
    39 new Handle:sm_flood_time;								/* Handle to sm_flood_time convar */
    40 
    41 public OnPluginStart()
    42 {
    43 	LoadTranslations("antiflood.phrases");
    44 	
    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");
    48 }
    49 
    50 public OnClientPutInServer(client)
    51 {
    52 	g_LastTime[client] = 0.0;
    53 	g_FloodTokens[client] = 0;
    54 }
    55 
    56 public Action:CheckChatFlood(client, args)
    57 {
    58 	/* Chat from server console shouldn't be checked for flooding */
    59 	if (client == 0)
    60 	{
    61 		return Plugin_Continue;
    62 	}
    63 	
    64 	new Float:maxChat = GetConVarFloat(sm_flood_time);
    65 	
    66 	if (maxChat > 0.0)
    67 	{
    68 		new Float:curTime = GetGameTime();
    69 		
    70 		if (g_LastTime[client] > curTime)
    71 		{
    72 			/* If player has 3 or more flood tokens, block their message */
    73 			if (g_FloodTokens[client] >= 3)
    74 			{
    75 				PrintToChat(client, "[SM] %t", "Flooding the server");
    76 				g_LastTime[client] = curTime + maxChat + 3.0;
    77 				
    78 				return Plugin_Stop;	
    79 			}
    80 			
    81 			/* Add one flood token when player goes over chat time limit */
    82 			g_FloodTokens[client]++;
    83 		} else if (g_FloodTokens[client]) {
    84 			/* Remove one flood token when player chats within time limit (slow decay) */
    85 			g_FloodTokens[client]--;
    86 		}
    87 		
    88 		/* Store last time of chat usage */
    89 		g_LastTime[client] = curTime + maxChat;
    90 	}
    91 	
    92 	return Plugin_Continue;
    93 }