Raised This Month: $32 Target: $400
 8% 

Ringlist iteration problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Silencer123
Veteran Member
Join Date: Jul 2006
Old 04-27-2010 , 16:38   Ringlist iteration problem
Reply With Quote #1

Hello. Long time no see.

I am making a small enhancement of the anitflood plugin.
The modified version shall block a chat message only when it is the nth
in a certain time frame. The server shall be able to set two such time
frames with limit value. My problem is, that my iteration will only work
for the timeframe with the greater limit. The other one won't do anything.
Now I know this code is a bit cumbersome, but a challenge should be
nice in a while, or not?

:p

I am using Float:g_FloodTime[33][MAX_FLOOD_COUNT] as a ringlist.
That means that when I reach its end, I go back to its start. The variable
contains a sort of log of every players' MAX_FLOOD_COUNT recent
messages' gametime.

The problematic loop is the one using static g down in public chkFlood(id).

Code:
/* Modified version of AMXModX Developer Team's Anti Flood Script by Silencer */ #include <amxmodx> new const VERSION[] = "1.0"; const MAX_FLOOD_COUNT = 32; const Float:WARNING_DECAY = 1.0; new Float:g_FloodTime[33][MAX_FLOOD_COUNT]; new Float:g_PreviousWarning[33] = {0.0, ...}; new g_LastFlood[33] = {0, ...}; new amx_flood_time; new amx_flood_count; new amx_flood_time2; new amx_flood_count2; public plugin_init() {     register_plugin("Anti Flood", VERSION, "Silencer");     register_clcmd("say", "chkFlood");     register_clcmd("say_team", "chkFlood");     amx_flood_time = register_cvar("amx_flood_time", "2.5");     amx_flood_count = register_cvar("amx_flood_count", "4");     amx_flood_time2 = register_cvar("amx_flood_time2", "30.0");     amx_flood_count2 = register_cvar("amx_flood_count2", "12");         for(new i = 0; i < 33; i++) {         for(new j = 0; j < MAX_FLOOD_COUNT; j++) {             g_FloodTime[i][j] = -1000.0;         }     } } public chkFlood(id) {     static maxCountCVAR[2];     maxCountCVAR[0] = min(get_pcvar_num(amx_flood_count), MAX_FLOOD_COUNT);     maxCountCVAR[1] = min(get_pcvar_num(amx_flood_count2), MAX_FLOOD_COUNT);         static Float:maxChatCVAR[2];     maxChatCVAR[0] = get_pcvar_float(amx_flood_time);     maxChatCVAR[1] = get_pcvar_float(amx_flood_time2);         g_LastFlood[id] = (g_LastFlood[id] == 0) ? (MAX_FLOOD_COUNT - 1) : (g_LastFlood[id] - 1);         static Float:currentTime;     currentTime = get_gametime();         g_FloodTime[id][g_LastFlood[id]] = currentTime;         static i;     static f;         static g;     for(g = 1; g >= 0; g--) {         f = 0;                 static stopChk;         stopChk = (g_LastFlood[id] + maxCountCVAR[g]) % (MAX_FLOOD_COUNT);                 static bool:firstIteration;         firstIteration = true;                 static bool:lastIteration;         lastIteration = false;                 for(i = g_LastFlood[id]; (firstIteration | lastIteration) ? (firstIteration) : ((i != stopChk) ? (true) : (lastIteration = true == true)); i = ((i + 1) % (MAX_FLOOD_COUNT))) {             if((g_FloodTime[id][i] + maxChatCVAR[g]) > currentTime) {                 f++;             } else {                 break;             }             firstIteration = false;         }                 if(f >= maxCountCVAR[g]) {             g_FloodTime[id][g_LastFlood[id]] = -1000.0;             g_LastFlood[id] = (g_LastFlood[id] + 1) % (MAX_FLOOD_COUNT);             if(g_PreviousWarning[id] + WARNING_DECAY < currentTime) {                 g_PreviousWarning[id] = currentTime;                 client_print(id, print_chat, "Stop spamming! Wait %.1f seconds.", maxChatCVAR[g] - (currentTime - g_FloodTime[id][(stopChk == 0) ? (stopChk = MAX_FLOOD_COUNT - 1) : (stopChk - 1)]));             }             return PLUGIN_HANDLED;         }     }         return PLUGIN_CONTINUE; }
__________________
EAT YOUR VEGGIES
Silencer123 is offline
vaevictus
New Member
Join Date: Jun 2005
Old 06-16-2010 , 22:50   Re: Ringlist iteration problem
Reply With Quote #2

What do you think about this?

Code:
public chkFlood(id) {   static maxCountCVAR[2];   maxCountCVAR[0] = min(get_pcvar_num(amx_flood_count), MAX_FLOOD_COUNT);   maxCountCVAR[1] = min(get_pcvar_num(amx_flood_count2), MAX_FLOOD_COUNT);       static Float:maxChatCVAR[2];   maxChatCVAR[0] = get_pcvar_float(amx_flood_time);   maxChatCVAR[1] = get_pcvar_float(amx_flood_time2);       /* increment last flood position */   g_LastFlood[id] = ((g_LastFlood[id] + 1) % MAX_FLOOD_COUNT);   static firstFlood;   firstFlood = ((g_LastFlood[id] + 1) % MAX_FLOOD_COUNT);       static Float:currentTime;   currentTime = get_gametime();     g_FloodTime[id][g_LastFlood[id]] = currentTime;       static i;   static f[2];   static g;   static h[2];   /* foreach piece of data in the array, count how many are above the time threshold (for each mode) */   for(i =  0; i < MAX_FLOOD_COUNT; i++ )   {     for(g = 0; g < 2; g++) {       if((g_FloodTime[id][((i + firstFlood)%MAX_FLOOD_COUNT)] + maxChatCVAR[g]) > currentTime) {         /* save oldest time for error message */         if(f[g] == 0) {           h[g] = currentTime;         }         f[g]++;       }     }   }   /* for each mode, check if quantity threshold has been crossed */   for(g = 0; g < 2; g++) {     if(f[g] >= maxCountCVAR[g]) {       if(g_PreviousWarning[id] + WARNING_DECAY < currentTime) {         g_PreviousWarning[id] = currentTime;         client_print(id, print_chat, "Stop spamming! Wait %.1f seconds.", maxChatCVAR[g] - (currentTime - h[g]) );       }       return PLUGIN_HANDLED;     }   }       return PLUGIN_CONTINUE; }

Last edited by vaevictus; 06-16-2010 at 22:51. Reason: code syntax update
vaevictus is offline
Send a message via ICQ to vaevictus Send a message via AIM to vaevictus
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:30.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode