AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Creating a banlist (optimizing) (https://forums.alliedmods.net/showthread.php?t=133509)

sphott 07-26-2010 07:42

Creating a banlist (optimizing)
 
I want to create a banlist for my plugin but I am lame for this
It's look like a crap, but working ... with some bug :D when I delete 10 player from the list and the list is 20 line long, the list will include 10 steam id and 10 endline and I cant remove they.
It's ok for me to show a plugin what is include a banlist and I can learn how it works, or just show me where need I modificate this...


this is only the banlist not the whole plugin:
PHP Code:

new banfile[16]
new 
configfolder[256]
new 
output[MAXIMUM][32]
new 
0
new path [64]
    
public 
plugin_init()
{
    
register_clcmd ("amx_rc_unban""unbancmd"ADMIN_KICK"Unban players from service")
    
banfile="rcban.ini"
    
get_configsdir (configfoldercharsmax(configfolder))
    
    
format (pathcharsmax(path), "%s/%s"configfolderbanfile)
    if(!
file_exists(path))
    {
        new 
writestr[101]
        
format(writestr,100,"banfile...DO NOT MODIFY")
        
write_file(path,writestr)
    } 
    new 
file_handle fopen (path"rt+")
    new 
file_text [256]
    while (!
feof (file_handle) && MAXIMUM) {
        
fgets (file_handlefile_text255)
        
trim (file_text)
        
copy (output [k], strlen (file_text), file_text)
        
k++
    }
    
fclose (file_handle)
}
public 
banid(id,id_cheater){
    if(
id && isuserbanned(id_cheater)){
        
client_print(id,print_chat,"Aleady baned!")
        return 
0
    
}
    new 
authid_cheater[32]
    
get_user_authid(id_cheater,authid_cheater,charsmax(authid_cheater))
    new 
writestr[32]
    
format(writestr,charsmax(writestr),"%s",authid_cheater)
    new 
nextline 0
    
new rstr[33], fnumb
    
while(read_file(path,fnum,rstr,32,b))
    {
        if(
<= 0)
        {
            
nextline fnum
            
break
        }
        
fnum++
    }
    if(!
nextline)
        
write_file(path,writestr)
    
    else
        
write_file(path,writestr,nextline)        
    
client_print(id,print_chat,"Player added to banlist!")
    new 
0
    
new file_handle fopen (path"rt+")
    new 
file_text [256]
    while (!
feof (file_handle) && MAXIMUM) {
        
fgets (file_handlefile_text255)
        
trim (file_text)
        
copy (output [k], strlen (file_text), file_text)
        
k++
    }
    
fclose (file_handle)
    return 
1
}
public 
unbanid(id,id_cheater,authid_ch[32]){
    if(
id && isuserbanned(id_cheater)){
        
client_print(id,print_chat,"Player can not be found on banlist!")
        return 
0
    
}
    
    new 
retstr[201], fnuma,removed=0,changed
    
new authid_cheater[32]
    new 
writestr[32]
    if(!
id){
        
authid_cheater=authid_ch    
    
}
    else
        
get_user_authid(id_cheater,authid_cheater,charsmax(authid_cheater))
    while(
read_file(path,fnum,retstr,200,a) != 0)
    {
        if(
changed){
            
removed++
            
changed=0
        
}
        new 
fuser[31]
        
parse(retstr,fuser,30)
        if(
equali(fuser,authid_cheater))
        {            
            
format(writestr,31,"")
            
write_file(path,writestr,fnum-removed)
            
changed++
        }
        if(
removed){
            
format(writestr,31,"%s",fuser)
            
write_file(path,writestr,fnum-removed)
        }
        
fnum++
    }    
    if(
removed){
            if(
idclient_print(id,print_chat,"Player removed from banlist!")
            
format(writestr,31,"")
            
write_file(path,writestr,fnum-removed)
            new 
0
            
new file_handle fopen (path"rt+")
            new 
file_text [256]
            while (!
feof (file_handle) && MAXIMUM) {
                
fgets (file_handlefile_text255)
                
trim (file_text)
                
copy (output [k], strlen (file_text), file_text)
                
k++
            }
            
fclose (file_handle)
            return 
1
    
}
    return 
0    
}
public 
unbancmd(id)
{
    new 
authid[32]
    
read_args(authid,1024)
    
remove_quotes(authid)
    if(
strlen(authid) <= 0){
        
client_print(id,print_console,"amx_irc_unban <steam_id>")
        return 
PLUGIN_HANDLED
    
}
    if(
unbanid(0,0,authid)) 
        
client_print(id,print_console,"Player removed from banlist!")
    else 
        
client_print(id,print_console,"Player can not be found on banlist!")    
    return 
PLUGIN_HANDLED




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

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