diff --git a/plugins/antiflood.sp b/plugins/antiflood.sp new file mode 100644 index 00000000..1ecc2179 --- /dev/null +++ b/plugins/antiflood.sp @@ -0,0 +1,87 @@ +/** + * antiflood.sp + * Protects against chat flooding. + * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Version: $Id$ + */ + +#include + +#pragma semicolon 1 + +public Plugin:myinfo = +{ + name = "Anti-Flood", + author = "AlliedModders LLC", + description = "Protects against chat flooding", + version = SOURCEMOD_VERSION, + url = "http://www.sourcemod.net/" +}; + +new Float:g_LastTime[MAXPLAYERS + 1] = {0.0, ...}; /* Last time player used say or say_team */ +new g_FloodTokens[MAXPLAYERS + 1] = {0, ...}; /* Number of flood tokens player has */ + +new Handle:sm_flood_time; /* Handle to sm_flood_time convar */ + +public OnPluginStart() +{ + LoadTranslations("core.cfg"); + + RegConsoleCmd("say", CheckChatFlood); + RegConsoleCmd("say_team", CheckChatFlood); + sm_flood_time = CreateConVar("sm_flood_time", "0.75", "Amount of time allowed between chat messages"); +} + +public Action:CheckChatFlood(client, args) +{ + /* Chat from server console shouldn't be checked for flooding */ + if (client == 0) + { + return Plugin_Continue; + } + + new Float:maxChat = GetConVarFloat(sm_flood_time); + + if (maxChat > 0.0) + { + new Float:curTime = GetGameTime(); + + if (g_LastTime[client] > curTime) + { + /* If player has 3 or more flood tokens, block their message */ + if (g_FloodTokens[client] >= 3) + { + PrintToChat(client, "[SM] %t", "Flooding the server"); + g_LastTime[client] = curTime + maxChat + 3.0; + + return Plugin_Stop; + } + + /* Add one flood token when player goes over chat time limit */ + g_FloodTokens[client]++; + } else if (g_FloodTokens[client]) { + /* Remove one flood token when player chats within time limit (slow decay) */ + g_FloodTokens[client]--; + } + + /* Store last time of chat usage */ + g_LastTime[client] = curTime + maxChat; + } + + return Plugin_Continue; +} diff --git a/plugins/basecommands.sp b/plugins/basecommands.sp index 7f3e4f3c..d273b9e1 100644 --- a/plugins/basecommands.sp +++ b/plugins/basecommands.sp @@ -1,6 +1,6 @@ /** - * admincmds-basic.sp - * Manages the standard flat files for admins. This is the file to compile. + * basecommands.sp + * Implements basic admin commands. * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC * * This program is free software; you can redistribute it and/or @@ -16,10 +16,14 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Version: $Id$ */ #include +#pragma semicolon 1 + public Plugin:myinfo = { name = "Basic Commands", @@ -63,7 +67,7 @@ public Action:Command_Kick(client, args) GetClientName(clients[0], name, sizeof(name)); - decl String:reason[256] + decl String:reason[256]; if (args < 2) { /* Safely null terminate */ diff --git a/plugins/include/keyvalues.inc b/plugins/include/keyvalues.inc index bfead33c..cb7b283a 100644 --- a/plugins/include/keyvalues.inc +++ b/plugins/include/keyvalues.inc @@ -332,4 +332,4 @@ native KvSetEscapeSequences(Handle:kv, bool:useEscapes); * @return Number of non-root nodes in the jump stack. * @error Invalid Handle. */ -native KvNodesInStack(Handle:kv); \ No newline at end of file +native KvNodesInStack(Handle:kv); diff --git a/plugins/include/sourcemod.inc b/plugins/include/sourcemod.inc index 1f88c681..f40b78e2 100644 --- a/plugins/include/sourcemod.inc +++ b/plugins/include/sourcemod.inc @@ -39,14 +39,16 @@ struct Plugin #include #include #include +#include #include +#include #include #include #include #include #include +#include #include -#include #include /** diff --git a/translations/core.cfg b/translations/core.cfg index 43289a25..43841207 100644 --- a/translations/core.cfg +++ b/translations/core.cfg @@ -36,4 +36,9 @@ "#format" "{1:s}" "en" "Kicked player '{1}'" } + + "Flooding the server" + { + "en" "You are flooding the server!" + } }