AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with "Min player or ban" plugin (https://forums.alliedmods.net/showthread.php?t=63227)

Dann3 11-15-2007 08:54

Help with "Min player or ban" plugin
 
1 Attachment(s)
The plugin will ban players if they cannot get the minumum number of players on the server witin given time

Okey so this plugin was for amx but i complied it to amxx. But the main problem is that the players doesnt get banned after the 'Minimum player or ban' timer has gone off and if i look in the server console it says "No one with that userid or name" when the server tries to ban... Hope u could help me

Please take a time to atleast look at the code and tell me what is wrong :D Sorry for bad english

Here is the code:
PHP Code:

#include <amxmod>
#include <vault>
new num_checkedmpl_temp[4]

public 
check_sv_players() {
    
remove_task(1911)
    new 
players[32], curnum,steamid[32], stm[32], reason[128]
    
get_players(playerscurnum//get ALL players (bots +hltv)
//    server_print("[AMX:DEBUG:CHK] check_server num=%d, players=%d, req=%d, dealy=%d, checks=%d",num_checked,curnum,get_cvar_num("mpl_minplayers"), get_cvar_num("mpl_checkdelay"),get_cvar_num("mpl_checktimes"))

    
if(curnum)
    {
        if(
curnum<get_cvar_num("mpl_minplayers")) //if player number is lower than required, check num of checks 
        
{
                if(
num_checked>get_cvar_num("mpl_checktimes"))//if checks number is above maximum, ban them all :D
                
{            num_checked++
//                server_print("[AMX:DEBUG:CHK] BAN MUAHAAHAHAH")
                
server_print("[AMX] Players: %d, Requred: %d, kicking and banning for %d min after %d checks",curnum,get_cvar_num("mpl_minplayers"),get_cvar_num("mpl_bantime"),get_cvar_num("mpl_checktimes"))
                
format(reason,127,"Required minimum players (%d) not on server. Banning all. Be back in %d minutes",get_cvar_num("mpl_minplayers"),get_cvar_num("mpl_bantime"))
////////////////////////////////////////////////////////////
                
for(new i=0i<curnumi++) {
                    
                    
//ignore hltv, usually we do not want it to get banned
                    
if(!is_user_hltv(players[i]) && !is_user_bot(players[i]))
                    {
                        
console_print(players[i],reason)
                        if(
get_cvar_num("mpl_banbyip"))//if set to 1 then ban by ip (for lans)
                        

                            
get_user_ip(players[i], stm32)//here steamid is an ip
                            
copyc(steamid,32,stm,':')
//                            server_cmd( "banid %d ^"%s^"" , get_cvar_num("mpl_bantime"),steamid )
//                                                 amx_ban <name|#userid|authid|ip> [ip] <minutes> [reason]
//                            server_print( "[AMX:DEBUG] amx_ban %s %d ^"%s^"" , steamid, get_cvar_num("mpl_bantime"),reason )
                            
server_cmd"amx_ban %s %d ^"%s^"" steamidget_cvar_num("mpl_bantime"),reason )
                        }
                        else
                        {
                            
get_user_authid(players[i], steamid32)
//                            server_cmd( "banid %d ^"%s^"" , get_cvar_num("mpl_bantime"),steamid )
                            
server_cmd"amx_ban %s %d ^"%s^"" steamidget_cvar_num("mpl_bantime"),reason )
                        }
                    }
                    else
                    {
                        if(
is_user_hltv(players[i])){
                            
get_user_ip(players[i], stm32)//ban HLTV
                            
copyc(steamid,32,stm,':')
//                            server_print( "[AMX:DEBUG] hltv found at #%d %s" ,get_user_userid(players[i]),steamid )
                            
if(get_cvar_num("mpl_banhltv"))
                            {
//                              server_print( "[AMX:DEBUG] addip %d %s" , get_cvar_num("mpl_bantime"),steamid )
                                
server_cmd"addip %d %s" get_cvar_num("mpl_bantime"),steamid )
                            }
                        }else{
//kick bots
                            
if(get_cvar_num("mpl_banbots"))
                            {
                            
server_print"[AMX:DEBUG] bot found at #%d %s" ,get_user_userid(players[i]),steamid )
                            
server_cmd"kick # %d"get_user_userid(players[i]))
                            new 
banbotscmd[256]
                            
get_cvar_string("mpl_banbotscmd",banbotscmd,255//exec server extra console command, in example addiitonal bot commands
                            
server_cmd"%s"banbotscmd)
                            }
                        }
                    
                    } 


                    
server_cmd"writeid;writeip")//saves on server restarts
                    
new bancmd[256]
                    
get_cvar_string("mpl_bancmd",bancmd,255//exec server extra console command, in example map change
                    
server_cmd"%s"bancmd)
                    if(
get_cvar_num("mpl_vault"))
                        if(
vaultdata_exists("mpl_checks")) 
                            
remove_vaultdata("mpl_checks"//they are banned, so no need to store info in vault

        
}
////////////////////////////////////////////////////////////
                
}
                else
                { 
//warn message, cause the check number is below requred count
                
num_checked++
                
set_hudmessage(200200200, -1.00.2006.024.00.10.14)
                
show_hudmessage(0,"[AMX] Players: %d, Required: %d^n%d checks left to obtain requred number^nor all current players will get banned for %d min",curnum,get_cvar_num("mpl_minplayers"),(get_cvar_num("mpl_checktimes") - num_checked+1),get_cvar_num("mpl_bantime"))
                
client_print(0,print_console,"[AMX] Players: %d, Required: %d; %d checks left to obtain requred number or all current players will get banned for %d min",curnum,get_cvar_num("mpl_minplayers"),(get_cvar_num("mpl_checktimes") - num_checked+1),get_cvar_num("mpl_bantime"))
    
//          server_print("[AMX:DEBUG:WRN] check_server num=%d, players=%d, req=%d, dealy=%d, checks=%d",num_checked,curnum,get_cvar_num("mpl_minplayers"), get_cvar_num("mpl_checkdelay"),get_cvar_num("mpl_checktimes"))
        
                
if(get_cvar_num("mpl_vault")){
                    if(
vaultdata_exists("mpl_checks"))
                        
remove_vaultdata("mpl_checks"
                    
num_to_str(num_checked,mpl_temp,3)
                    
set_vaultdata("mpl_checks",mpl_temp//save vault info on every check
                
}


                }

        }
        else
        {
//reset counter to default if achieved the number of minimum players
        
num_checked=1
        
if(get_cvar_num("mpl_vault"))
            if(
vaultdata_exists("mpl_checks")) 
                
remove_vaultdata("mpl_checks"//remove the vault info cause there is enough number of players
        
}

    }
    else
    {
//reset counter to default if no players on server
    
num_checked=1
    
if(get_cvar_num("mpl_vault"))
        if(
vaultdata_exists("mpl_checks")) 
            
remove_vaultdata("mpl_checks"//remove the vault info, cause there is noone on server
    
}
    new 
Float:freq=get_cvar_float("mpl_checkdelay")
    if (
freq>0.0set_task(freq"check_sv_players"1911)
    return 
PLUGIN_CONTINUE
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


public plugin_init() {
    
register_plugin("Minimum Players Or Ban""0.5""_KaszpiR_")
    
register_cvar("mpl_checkdelay""60"//seconds, so total check time will be checkdelay * checktimes
    
register_cvar("mpl_checktimes""10")    //times
    
register_cvar("mpl_bantype""1")    // 1 = ban + kick (default), 0 = ban only (so they can still be on serer but after leaving cannot return till ban expires
    
register_cvar("mpl_banbyip""0")    //default 0 = authid(steamind/wonid), 1 = ip (for lans)
    
register_cvar("mpl_banbots""0")    //actually kick
    
register_cvar("mpl_banbotscmd""pb removebots")    //default example for podbot, 255 chars max (thats a lot)
    
register_cvar("mpl_bancmd""")    //default empty
    
register_cvar("mpl_banhltv""0")    //ban hltv that can be left after a match
    
register_cvar("mpl_bantime""45")    
    
register_cvar("mpl_minplayers""0")    
    
register_cvar("mpl_vault""1")    
    
register_cvar("mpl_skipchecks""1")    

    if(
get_cvar_num("mpl_vault")){
        if(
vaultdata_exists("mpl_checks")) //get data from vault
            
get_vaultdata("mpl_checks",mpl_temp,3)
        
num_checked strtonum(mpl_temp// if the data is not in vault then we get 0 or something like this
        
num_checked -= get_cvar_num("mpl_skipchecks"//decrease counter, so they get extra checks
    
}
    if(!
num_checkednum_checked=// make sure it is a proper value
    
new Float:freq=get_cvar_float("mpl_checkdelay")
    if (
freq>0.0set_task(freq"check_sv_players"1911)
    return 
PLUGIN_CONTINUE
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public plugin_end() {
    if(
get_cvar_num("mpl_vault")){
        if(
vaultdata_exists("mpl_checks"))
            
remove_vaultdata("mpl_checks"
        
num_to_str(num_checked,mpl_temp,3)
        
set_vaultdata("mpl_checks",mpl_temp//save vault info on plugin unload/map change
    
}
    return 
PLUGIN_CONTINUE
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// end of file 

I think the problem is here but dont know how to fix it
PHP Code:

get_user_ip(players[i], stm32)//here steamid is an ip
copyc(steamid,32,stm,':')
//server_cmd( "banid %d ^"%s^"" , get_cvar_num("mpl_bantime"),steamid )
//amx_ban <name|#userid|authid|ip> [ip] <minutes> [reason]
//server_print( "[AMX:DEBUG] amx_ban %s %d ^"%s^"" , steamid, get_cvar_num("mpl_bantime"),reason )
server_cmd"amx_ban %s %d ^"%s^"" steamidget_cvar_num("mpl_bantime"),reason )
}
else
{
get_user_authid(players[i], steamid32)
//server_cmd( "banid %d ^"%s^"" , get_cvar_num("mpl_bantime"),steamid )
server_cmd"amx_ban %s %d ^"%s^"" steamidget_cvar_num("mpl_bantime"),reason 


Dann3 12-03-2007 15:59

Re: Help with "Min player or ban" plugin
 
I know that someone can help me..i really need this plugin for a project

Vet 12-04-2007 22:47

Re: Help with "Min player or ban" plugin
 
The amx_ban command won't recognize SteamIDs. So either convert it to a UserID or change the command to amx_addban.

Dann3 12-05-2007 06:13

Re: Help with "Min player or ban" plugin
 
So just replace all steamid with userid?

Dann3 12-06-2007 12:14

Re: Help with "Min player or ban" plugin
 
I changed amx_ban to amx_addban and it worked quite well but i can only ban by ip becouse when the server add the steamid the steamid is STEAM_ID_PENDING for some reason :/

Vet 12-06-2007 14:26

Re: Help with "Min player or ban" plugin
 
I'm not certain, but I think that's caused by using cracked (illegal) Steam accounts.

Dann3 12-06-2007 15:24

Re: Help with "Min player or ban" plugin
 
I read some where that i should use public client_authorized to avoid the steam_id_pending but i dont know where to use it ;P

Vet 12-06-2007 18:41

Re: Help with "Min player or ban" plugin
 
That function will run automatically when the player 1st joins the server. And only then. So it can be put anywhere. If your plan is to kick them right away, then you could use it. But if you just want to keep the plugin from acting on them, use the get_user_authid() function wherever the plugin checks the player.

Dann3 12-07-2007 05:29

Re: Help with "Min player or ban" plugin
 
The plugin is working now i think :P

I changed
PHP Code:

get_user_ip(players[i], stm32)//here steamid is an ip
copyc(steamid,32,stm,':')
//server_cmd( "banid %d ^"%s^"" , get_cvar_num("mpl_bantime"),steamid )
//amx_ban <name|#userid|authid|ip> [ip] <minutes> [reason]
//server_print( "[AMX:DEBUG] amx_ban %s %d ^"%s^"" , steamid, get_cvar_num("mpl_bantime"),reason )
server_cmd"amx_ban %s %d ^"%s^"" steamidget_cvar_num("mpl_bantime"),reason )
}
else
{
get_user_authid(players[i], steamid32)
//server_cmd( "banid %d ^"%s^"" , get_cvar_num("mpl_bantime"),steamid )
server_cmd"amx_ban %s %d ^"%s^"" steamidget_cvar_num("mpl_bantime"),reason 

To

PHP Code:

get_user_ip(players[i], stm32)//here steamid is an ip
copyc(steamid,32,stm,':')
//server_cmd( "banid %d ^"%s^"" , get_cvar_num("mpl_bantime"),steamid )
//amx_ban <name|#userid|authid|ip> [ip] <minutes> [reason]
//server_print( "[AMX:DEBUG] amx_ban %s %d ^"%s^"" , steamid, get_cvar_num("mpl_bantime"),reason )
server_cmd"amx_ban %s %d ^"%s^"" steamidget_cvar_num("mpl_bantime"),reason )
}
else
{
//server_cmd( "banid %d ^"%s^"" , get_cvar_num("mpl_bantime"),steamid )
server_cmd"amx_ban #%d %d ^"%s^"" get_user_userid(players[i]),get_cvar_num("mpl_bantime") ,reason )


Its working but i dont know if that is 'clean/good' coding :P

purple_pixie 12-07-2007 05:42

Re: Help with "Min player or ban" plugin
 
It's not terrible.

Apart from the lines:
Code:
get_user_ip(players[i], stm, 32)//here steamid is an ip copyc(steamid,32,stm,':')

Which should either be 31 or sizeof stm - 1


All times are GMT -4. The time now is 01:23.

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