Raised This Month: $ Target: $400
 0% 

addip/banid implementation


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
facuq
Junior Member
Join Date: Feb 2007
Old 02-06-2007 , 15:08   Re: addip/banid implementation
Reply With Quote #4

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.

Last edited by facuq; 02-06-2007 at 15:18.
facuq is offline
 



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 00:38.


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