From 8598179f26889f7ee878f307fdd8064a9fc8fc23 Mon Sep 17 00:00:00 2001 From: BotoX Date: Mon, 5 Dec 2016 18:51:28 +0100 Subject: [PATCH] New plugin: AntiFlood Kick players who are flooding the server --- AntiFlood/scripting/AntiFlood.sp | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 AntiFlood/scripting/AntiFlood.sp diff --git a/AntiFlood/scripting/AntiFlood.sp b/AntiFlood/scripting/AntiFlood.sp new file mode 100644 index 00000000..c2754266 --- /dev/null +++ b/AntiFlood/scripting/AntiFlood.sp @@ -0,0 +1,71 @@ +#include + +#pragma semicolon 1 +#pragma newdecls required + +int g_Client_CommandCount[MAXPLAYERS + 1]; +float g_Client_LastFlood[MAXPLAYERS + 1]; + +#define MAX_COMMANDS 100 +#define INTERVAL 1.0 + +public Plugin myinfo = +{ + name = "AntiFlood", + author = "BotoX", + description = "", + version = "0.1", + url = "" +}; + +public void OnPluginStart() +{ + /* Late load */ + for(int client = 1; client <= MaxClients; client++) + { + if(IsClientInGame(client)) + OnClientConnected(client); + } + + AddCommandListener(OnAnyCommand, ""); +} + +public void OnClientConnected(int client) +{ + g_Client_CommandCount[client] = 0; + g_Client_LastFlood[client] = 0.0; +} + +//public Action OnClientCommand(int client, int args) +public Action OnAnyCommand(int client, const char[] command, int argc) +{ + if(FloodCheck(client)) + return Plugin_Handled; + + return Plugin_Continue; +} + +public void OnClientSettingsChanged(int client) +{ + FloodCheck(client); +} + +bool FloodCheck(int client) +{ + if(client <= 0 || client > MaxClients) + return false; + + if(++g_Client_CommandCount[client] <= MAX_COMMANDS) + return false; + + float Time = GetGameTime(); + if(Time >= g_Client_LastFlood[client] + INTERVAL) + { + g_Client_LastFlood[client] = Time; + g_Client_CommandCount[client] = 0; + return false; + } + + KickClientEx(client, "STOP FLOODING THE SERVER!!!"); + return true; +}