1.1 --- a/plugins/antiflood.sp Wed Mar 12 02:13:08 2008 +0000
1.2 +++ b/plugins/antiflood.sp Wed Mar 12 03:33:52 2008 +0000
1.3 @@ -51,10 +51,6 @@
1.4
1.5 public OnPluginStart()
1.6 {
1.7 - LoadTranslations("antiflood.phrases");
1.8 -
1.9 - RegConsoleCmd("say", CheckChatFlood);
1.10 - RegConsoleCmd("say_team", CheckChatFlood);
1.11 sm_flood_time = CreateConVar("sm_flood_time", "0.75", "Amount of time allowed between chat messages");
1.12 }
1.13
1.14 @@ -64,41 +60,63 @@
1.15 g_FloodTokens[client] = 0;
1.16 }
1.17
1.18 -public Action:CheckChatFlood(client, args)
1.19 +new Float:max_chat;
1.20 +
1.21 +public bool:OnClientFloodCheck(client)
1.22 {
1.23 - /* Chat from server console shouldn't be checked for flooding */
1.24 - if (client == 0)
1.25 + max_chat = GetConVarFloat(sm_flood_time);
1.26 +
1.27 + if (max_chat <= 0.0
1.28 + || (GetUserFlagBits(client) & ADMFLAG_ROOT) == ADMFLAG_ROOT)
1.29 {
1.30 - return Plugin_Continue;
1.31 + return false;
1.32 + }
1.33 +
1.34 + PrintToServer("OCFC: %f %f %d", g_LastTime[client], GetGameTime(), g_FloodTokens[client]);
1.35 +
1.36 + if (g_LastTime[client] > GetGameTime())
1.37 + {
1.38 + /* If player has 3 or more flood tokens, block their message */
1.39 + if (g_FloodTokens[client] >= 3)
1.40 + {
1.41 + return true;
1.42 + }
1.43 }
1.44
1.45 - new Float:maxChat = GetConVarFloat(sm_flood_time);
1.46 -
1.47 - if (maxChat > 0.0)
1.48 + return false;
1.49 +}
1.50 +
1.51 +public OnClientFloodResult(client, bool:blocked)
1.52 +{
1.53 + if (max_chat <= 0.0
1.54 + || (GetUserFlagBits(client) & ADMFLAG_ROOT) == ADMFLAG_ROOT)
1.55 {
1.56 - new Float:curTime = GetGameTime();
1.57 -
1.58 - if (g_LastTime[client] > curTime)
1.59 - {
1.60 - /* If player has 3 or more flood tokens, block their message */
1.61 - if (g_FloodTokens[client] >= 3)
1.62 - {
1.63 - PrintToChat(client, "[SM] %t", "Flooding the server");
1.64 - g_LastTime[client] = curTime + maxChat + 3.0;
1.65 -
1.66 - return Plugin_Stop;
1.67 - }
1.68 -
1.69 - /* Add one flood token when player goes over chat time limit */
1.70 - g_FloodTokens[client]++;
1.71 - } else if (g_FloodTokens[client]) {
1.72 - /* Remove one flood token when player chats within time limit (slow decay) */
1.73 - g_FloodTokens[client]--;
1.74 - }
1.75 -
1.76 - /* Store last time of chat usage */
1.77 - g_LastTime[client] = curTime + maxChat;
1.78 + return;
1.79 }
1.80
1.81 - return Plugin_Continue;
1.82 + new Float:curTime = GetGameTime();
1.83 + new Float:newTime = curTime + max_chat;
1.84 +
1.85 + PrintToServer("OCFR: %f, %f", g_LastTime[client], GetGameTime());
1.86 +
1.87 + if (g_LastTime[client] > curTime)
1.88 + {
1.89 + /* If the last message was blocked, update their time limit */
1.90 + if (blocked)
1.91 + {
1.92 + newTime += 3.0;
1.93 + }
1.94 + /* Add one flood token when player goes over chat time limit */
1.95 + else if (g_FloodTokens[client] < 3)
1.96 + {
1.97 + g_FloodTokens[client]++;
1.98 + }
1.99 + }
1.100 + else if (g_FloodTokens[client] > 0)
1.101 + {
1.102 + /* Remove one flood token when player chats within time limit (slow decay) */
1.103 + g_FloodTokens[client]--;
1.104 + }
1.105 +
1.106 + g_LastTime[client] = newTime;
1.107 }