AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   addip/banid implementation (https://forums.alliedmods.net/showthread.php?t=50841)

facuq 02-05-2007 00:31

addip/banid implementation
 
I've been trying to do my own [efficient, meaning usable] implementation of these commands using a plugin, and i wanted to know if any of you had ideas for it. What first comes to mind is simple creating an array or similar data structure with all the temporarily banned players, and use a task to decrease remaining ban time by one every minute, but i'm not sure this would work well as i've read task should be used little and carefully.
So, the main question is: Does anyone see any problem with this, or could this create problems with the server if i had too many banned players? (too many ~= 15?)
If so, any suggestions for an alternative way of doing this would be appreciated.

PS: the mininum ban time could be raised so the task is executed less often, or to decrease remaining ban time on every map change.

[ --<-@ ] Black Rose 02-05-2007 09:05

Re: addip/banid implementation
 
Don't.
The way it is is fine.
And if you really have to do it use nvault, not an array.

facuq 02-05-2007 11:54

Re: addip/banid implementation
 
I know it's fine the way it is, but i need my own :).
Why nvault? since i need to lower every banned player's remaining time by one minute, an array is perfect because i can do it in O(n) time.
Else i'd have to use a data structure to store banned keys to lookup in the vault, which would be kinda the same thing, given that i need to know every key that's in the vault. Or do you mean i should use a vault for "permanent" storage?

Thanks Black Rose!

The only problem i see with using an array is how task's and events are implemented; if they use interrupts, i'd be having a sincronization problem, because when a player is banned, the player's id would be added to the array, but if in the middle of this, the task (which could delete an array member when remaining time reaches zero) gets executed, it would make a mess. Or viceversa, if the task is begin executed and a ban comes through and interrupts..

I need help :(!!!

facuq 02-06-2007 15:08

Re: addip/banid implementation
 
ok i'll post some pseudo code so you can better see what i mean:
Code:
// info on players new playersId[MAXPLAYERS]; new playerIsBanned[MAXPLAYERS]; new numberOfPlayers=0; // info on banned players new bannedPlayerIndex[MAXBANNEDPLAYERS]; new remainingBanTime[MAXBANNEDPLAYERS]; new numberOfBannedPlayers=0; task decreaseRemainingTime() {     new i;     // for every banned player     for (i=(numberOfBannedPlayers-1); i>=0; i--)     {  // decrease ban time and check if it's reached zero        if (--remainingBanTime[i]==0){            // unban the player            playerIsBanned[ bannedPlayerIndex[i] ]=0;            // remove it from array by putting the last element in it's place            numberOfBannedPlayers--;                  bannedPlayerIndex[i]=bannedPlayerIndex[numberOfBannedPlayers];            remainingBanTime[i]=remainingBanTime[numberOfBannedPlayers];        }     } } public banPlayer(playerId,banTime){         new index= searchPlayerIndex(playerId);     // if id exists     if (index!=-1){         // mark as banned         playerIsBanned[index]=1;         // if its not a permanent ban         if (banTime != 0){             // add to banned array             bannedPlayerIndex[numberOfBannedPlayers]=index;             remainingBanTime[numberOfBannedPlayers]=banTime;             numberOfBannedPlayers++;         }     } } public unbanPlayer(playerId){     //     new index= searchPlayerIndex(playerId);     // if id exists     if (index!=-1){         // mark as unbanned         playerIsBanned[index]=0;                 // search player's entry in banned array         new banIndex= searchPlayerIndex(bannedPlayerIndex);         // if player had a temporary ban         if (banIndex!=-1){             // remove it from array by putting the last element in it's place             numberOfBannedPlayers--;                   bannedPlayerIndex[banIndex]=bannedPlayerIndex[numberOfBannedPlayers];             remainingBanTime[banIndex]=remainingBanTime[numberOfBannedPlayers];         }     }   }


As you can see, i can't have one function interrupting the execution of another one, since the array would be left in an inconsistent state.


All times are GMT -4. The time now is 00:38.

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