reworked antiflood. it now has some logic in core to take care of loading order nastiness, and to fully prevent trigger spamming

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401931
This commit is contained in:
David Anderson
2008-03-12 03:33:52 +00:00
parent b10bf9d31a
commit aed775162c
7 changed files with 219 additions and 52 deletions
+49 -31
View File
@@ -51,10 +51,6 @@ new Handle:sm_flood_time; /* Handle to sm_flood_time convar */
public OnPluginStart()
{
LoadTranslations("antiflood.phrases");
RegConsoleCmd("say", CheckChatFlood);
RegConsoleCmd("say_team", CheckChatFlood);
sm_flood_time = CreateConVar("sm_flood_time", "0.75", "Amount of time allowed between chat messages");
}
@@ -64,41 +60,63 @@ public OnClientPutInServer(client)
g_FloodTokens[client] = 0;
}
public Action:CheckChatFlood(client, args)
new Float:max_chat;
public bool:OnClientFloodCheck(client)
{
/* Chat from server console shouldn't be checked for flooding */
if (client == 0)
max_chat = GetConVarFloat(sm_flood_time);
if (max_chat <= 0.0
|| (GetUserFlagBits(client) & ADMFLAG_ROOT) == ADMFLAG_ROOT)
{
return Plugin_Continue;
return false;
}
new Float:maxChat = GetConVarFloat(sm_flood_time);
PrintToServer("OCFC: %f %f %d", g_LastTime[client], GetGameTime(), g_FloodTokens[client]);
if (maxChat > 0.0)
if (g_LastTime[client] > GetGameTime())
{
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)
{
/* 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]--;
return true;
}
/* Store last time of chat usage */
g_LastTime[client] = curTime + maxChat;
}
return Plugin_Continue;
return false;
}
public OnClientFloodResult(client, bool:blocked)
{
if (max_chat <= 0.0
|| (GetUserFlagBits(client) & ADMFLAG_ROOT) == ADMFLAG_ROOT)
{
return;
}
new Float:curTime = GetGameTime();
new Float:newTime = curTime + max_chat;
PrintToServer("OCFR: %f, %f", g_LastTime[client], GetGameTime());
if (g_LastTime[client] > curTime)
{
/* If the last message was blocked, update their time limit */
if (blocked)
{
newTime += 3.0;
}
/* Add one flood token when player goes over chat time limit */
else if (g_FloodTokens[client] < 3)
{
g_FloodTokens[client]++;
}
}
else if (g_FloodTokens[client] > 0)
{
/* Remove one flood token when player chats within time limit (slow decay) */
g_FloodTokens[client]--;
}
g_LastTime[client] = newTime;
}
+26
View File
@@ -505,6 +505,32 @@ native Handle:ReadMapList(Handle:array=INVALID_HANDLE,
*/
native SetMapListCompatBind(const String:name[], const String:file[]);
/**
* Called when a client has sent chat text. This must return either true or
* false to indicate that a client is or is not spamming the server.
*
* The return value is a hint only. Core or another plugin may decide
* otherwise.
*
* @param client Client index. The server (0) will never be passed.
* @return True if client is spamming the server, false otherwise.
*/
forward bool:OnClientFloodCheck(client);
/**
* Called after a client's flood check has been computed. This can be used
* by antiflood algorithms to decay/increase flooding weights.
*
* Since the result from "OnClientFloodCheck" isn't guaranteed to be the
* final result, it is generally a good idea to use this to play with other
* algorithms nicely.
*
* @param client Client index. The server (0) will never be passed.
* @param blocked True if client flooded last "say", false otherwise.
* @noreturn
*/
forward OnClientFloodResult(client, bool:blocked);
#include <helpers>
#include <entity>
#include <entity_prop_stocks>