|
ds@913
|
1 |
/** |
|
ds@913
|
2 |
* antiflood.sp |
|
ds@913
|
3 |
* Protects against chat flooding. |
|
ds@913
|
4 |
* This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC |
|
ds@913
|
5 |
* |
|
ds@913
|
6 |
* This program is free software; you can redistribute it and/or |
|
ds@913
|
7 |
* modify it under the terms of the GNU General Public License |
|
ds@913
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
ds@913
|
9 |
* of the License, or (at your option) any later version. |
|
ds@913
|
10 |
* |
|
ds@913
|
11 |
* This program is distributed in the hope that it will be useful, |
|
ds@913
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
ds@913
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
ds@913
|
14 |
* GNU General Public License for more details. |
|
ds@913
|
15 |
* |
|
ds@913
|
16 |
* You should have received a copy of the GNU General Public License |
|
ds@913
|
17 |
* along with this program; if not, write to the Free Software |
|
ds@913
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
ds@913
|
19 |
* |
|
ds@913
|
20 |
* Version: $Id$ |
|
ds@913
|
21 |
*/ |
|
ds@989
|
22 |
|
|
ds@989
|
23 |
#pragma semicolon 1 |
|
ds@913
|
24 |
|
|
ds@913
|
25 |
#include <sourcemod> |
|
ds@913
|
26 |
|
|
ds@913
|
27 |
public Plugin:myinfo = |
|
ds@913
|
28 |
{ |
|
ds@913
|
29 |
name = "Anti-Flood", |
|
ds@913
|
30 |
author = "AlliedModders LLC", |
|
ds@913
|
31 |
description = "Protects against chat flooding", |
|
ds@913
|
32 |
version = SOURCEMOD_VERSION, |
|
ds@913
|
33 |
url = "http://www.sourcemod.net/" |
|
ds@913
|
34 |
}; |
|
ds@913
|
35 |
|
|
ds@913
|
36 |
new Float:g_LastTime[MAXPLAYERS + 1] = {0.0, ...}; /* Last time player used say or say_team */ |
|
ds@913
|
37 |
new g_FloodTokens[MAXPLAYERS + 1] = {0, ...}; /* Number of flood tokens player has */ |
|
ds@913
|
38 |
|
|
ds@913
|
39 |
new Handle:sm_flood_time; /* Handle to sm_flood_time convar */ |
|
ds@913
|
40 |
|
|
ds@913
|
41 |
public OnPluginStart() |
|
ds@913
|
42 |
{ |
|
ferret99gt@1187
|
43 |
LoadTranslations("antiflood.phrases"); |
|
ds@913
|
44 |
|
|
ds@913
|
45 |
RegConsoleCmd("say", CheckChatFlood); |
|
ds@913
|
46 |
RegConsoleCmd("say_team", CheckChatFlood); |
|
ds@913
|
47 |
sm_flood_time = CreateConVar("sm_flood_time", "0.75", "Amount of time allowed between chat messages"); |
|
ds@913
|
48 |
} |
|
ds@913
|
49 |
|
|
faluco@1128
|
50 |
public OnClientPutInServer(client) |
|
faluco@1128
|
51 |
{ |
|
faluco@1128
|
52 |
g_LastTime[client] = 0.0; |
|
faluco@1128
|
53 |
g_FloodTokens[client] = 0; |
|
faluco@1128
|
54 |
} |
|
faluco@1128
|
55 |
|
|
ds@913
|
56 |
public Action:CheckChatFlood(client, args) |
|
ds@913
|
57 |
{ |
|
ds@913
|
58 |
/* Chat from server console shouldn't be checked for flooding */ |
|
ds@913
|
59 |
if (client == 0) |
|
ds@913
|
60 |
{ |
|
ds@913
|
61 |
return Plugin_Continue; |
|
ds@913
|
62 |
} |
|
ds@913
|
63 |
|
|
ds@913
|
64 |
new Float:maxChat = GetConVarFloat(sm_flood_time); |
|
ds@913
|
65 |
|
|
ds@913
|
66 |
if (maxChat > 0.0) |
|
ds@913
|
67 |
{ |
|
ds@913
|
68 |
new Float:curTime = GetGameTime(); |
|
ds@913
|
69 |
|
|
ds@913
|
70 |
if (g_LastTime[client] > curTime) |
|
ds@913
|
71 |
{ |
|
ds@913
|
72 |
/* If player has 3 or more flood tokens, block their message */ |
|
ds@913
|
73 |
if (g_FloodTokens[client] >= 3) |
|
ds@913
|
74 |
{ |
|
ds@913
|
75 |
PrintToChat(client, "[SM] %t", "Flooding the server"); |
|
ds@913
|
76 |
g_LastTime[client] = curTime + maxChat + 3.0; |
|
ds@913
|
77 |
|
|
ds@913
|
78 |
return Plugin_Stop; |
|
ds@913
|
79 |
} |
|
ds@913
|
80 |
|
|
ds@913
|
81 |
/* Add one flood token when player goes over chat time limit */ |
|
ds@913
|
82 |
g_FloodTokens[client]++; |
|
ds@913
|
83 |
} else if (g_FloodTokens[client]) { |
|
ds@913
|
84 |
/* Remove one flood token when player chats within time limit (slow decay) */ |
|
ds@913
|
85 |
g_FloodTokens[client]--; |
|
ds@913
|
86 |
} |
|
ds@913
|
87 |
|
|
ds@913
|
88 |
/* Store last time of chat usage */ |
|
ds@913
|
89 |
g_LastTime[client] = curTime + maxChat; |
|
ds@913
|
90 |
} |
|
ds@913
|
91 |
|
|
ds@913
|
92 |
return Plugin_Continue; |
|
ds@913
|
93 |
} |