AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Not working get_systime (https://forums.alliedmods.net/showthread.php?t=156941)

monolit 05-14-2011 05:31

Not working get_systime
 
Hey, So I've made my own Ban system, and It's not working, I don't know why, could someone check it up ?

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#include <cstrike>
#include <colorchat>

#define PLUGIN "Tutorial"
#define VERSION "1.0"
#define AUTHOR "Grim"

new Host[]     = "127.0.0.1"
new User[]    = "root"
new Pass[]     = "nsth"
new Db[]     = "amx"


new Handle:g_SqlTuple
new g_Error[512]


new 
iBan[33];
new 
iReason[33][255];
new 
iAdmin[33][32];

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
        
    
set_task(1.0"MySql_Init")
    
    
register_clcmd("say ""said")
}

public 
said(id) {
    if(~
get_user_flags(id) & ADMIN_BAN)
        return 
PLUGIN_CONTINUE;
        
    new 
szArg[45]
    
read_args(szArgcharsmax(szArg))
    
remove_quotes(szArg)
    new 
szCmd[12], szTarget[12], szTime[4], szReason[20]
    
strbreak(szArgszCmdcharsmax(szCmd), szArgcharsmax(szArg))
    if(
equali(szCmd"!ban"))
    {
        
strbreak(szArgszTargetcharsmax(szTarget), szArgcharsmax(szArg))
        
strbreak(szArgszTimecharsmax(szTime), szReasoncharsmax(szReason))
        
        if(!
szTarget[0] || !szTime[0] || !szReason[0])
        {
            
client_print_color(idDontChange"^4[ INFO ]^1 Usage: ^3!ban player_name ban_time ban_reason")
            return 
PLUGIN_HANDLED_MAIN;
        }
        
        new 
szAdminName[33];
        
get_user_name(idszAdminName32)
        
        new 
player cmd_target(idszTargetCMDTARGET_OBEY_IMMUNITY);
        
        if(!
player)
            return 
PLUGIN_HANDLED;
            
        new 
bantime;
        
        if(
containi(szTime"m") != -1)
        {
            
replace_all(szTimecharsmax(szTime), "m""")
            
bantime str_to_num(szTime) * 60;
        }else if(
containi(szTime"h") != -1)
        {
            
replace_all(szTimecharsmax(szTime), "h""")
            
bantime str_to_num(szTime) * 60 60;
        }else if(
containi(szTime"d") != -1)
        {
            
replace_all(szTimecharsmax(szTime), "d""")
            
bantime str_to_num(szTime) * 60 60 24;
        }
        
        if(
bantime 604800)
        {
            
client_print_color(idDontChange"^4[ INFO ]^1 ban_time can not exceed more than 7 days")
            return 
PLUGIN_HANDLED_MAIN;
        }
                
        new 
szTargetName[33];
        
get_user_name(playerszTargetName32)
        
        switch(
cs_get_user_team(player))
        {
            case 
CS_TEAM_CTclient_print_color(0BLUE"^4[ INFO ]^1 Player ^3%s^1 banned ( %s )"szTargetNameszReason)
            case 
CS_TEAM_Tclient_print_color(0RED"^4[ INFO ]^1 Player ^3%s^1 banned ( %s )"szTargetNameszReason)
            case 
CS_TEAM_SPECTATORclient_print_color(0GREY"^4[ INFO ]^1 Player ^3%s^1 banned ( %s )"szTargetNameszReason)
        }
        
        
client_cmd(player"echo ^"---- You are banned ----^nbanned by: %s^nreason: %s^n---- You are banned ----^""iAdmin[id], iReason[id])
        
server_cmd("kick #%d ^"You are banned,^ncheck your console^""get_user_userid(player) )
        
        new 
szTargetAuth[33];
        
get_user_authid(playerszTargetAuth32)
        
        new 
szTemp[512]
        
format(szTemp,charsmax(szTemp),"INSERT INTO `bans` ( `auth` , `ban_time`, `ban_reason`, `ban_admin`)VALUES ('%s','%d', '%s', '%s');"szTargetAuthget_systime() + bantimeszReasonszAdminName)
        
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
        return 
PLUGIN_HANDLED_MAIN;
    }
    return 
PLUGIN_CONTINUE;
}

public 
MySql_Init()
{
    
g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db)
    
    new 
ErrorCode,Handle:SqlConnection SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
    if(
SqlConnection == Empty_Handle)
        
set_fail_state(g_Error)
       
    new 
Handle:Queries
    Queries 
SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS bans (ip varchar(32),ban_time INT(20), ban_reason varchar(50), ban_admin varchar(32) )")

    if(!
SQL_Execute(Queries))
    {
        
SQL_QueryError(Queries,g_Error,charsmax(g_Error))
        
set_fail_state(g_Error)
       
    }
    
    
SQL_FreeHandle(Queries)
   
    
SQL_FreeHandle(SqlConnection)   
}

public 
plugin_end()
{
    
SQL_FreeHandle(g_SqlTuple)
}

public 
Load_MySql(id)
{
    new 
szAuthID[32], szTemp[512]
    
get_user_authid(idszAuthIDcharsmax(szAuthID))
    
    new 
Data[1]
    
Data[0] = id
    
    format
(szTemp,charsmax(szTemp),"SELECT * FROM `bans` WHERE (`bans`.`auth` = '%s')"szAuthID)
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
}

public 
register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
    {
        
log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError)
    }
    else if(
FailState == TQUERY_QUERY_FAILED)
    {
        
log_amx("Load Query failed. [%d] %s"ErrcodeError)
    }

    new 
id
    id 
Data[0]
    
    if(
SQL_NumResults(Query) > 1
    {
        
iBan[id]    = SQL_ReadResult(Query1)
        
SQL_ReadResultQuery2iReason[id], charsmaxiReason[ ] ) )
        
SQL_ReadResultQuery3iAdmin[id], charsmaxiAdmin[ ] ) )
    }
    
    
set_task(0.1"CheckBan"id)
    
    return 
PLUGIN_HANDLED
}

public 
CheckBan(id)
{
    if( 
iBan[id] > get_systime() )
    {
        
client_cmd(id"echo ^"---- You are banned ----^nbanned by: %s^nreason: %s^n---- You are banned ----^""iAdmin[id], iReason[id])
        
server_cmd("kick #%d ^"You are banned,^ncheck your console^""get_user_userid(id) )
    }
}

public 
client_disconnect(id)
{
    
iBan[id] = 0;
    
iReason[id][0] = '^0'
    
iAdmin[id][0] = '^0'
}

/*public Save_MySql(id)
{
    new szIp[32], szName[32], szTemp[512]
    get_user_ip(id, szIp, charsmax(szIp), 1)
    
    format(szTemp,charsmax(szTemp),"UPDATE `bans` SET `ban` = '%d' WHERE `bans`.`ip` = '%s';",iExp[id], szSteamId)
    SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}*/

public IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    
SQL_FreeHandle(Query)
    
    return 
PLUGIN_HANDLED
}

public 
client_putinserver(id)
{
    
Load_MySql(id)


I Ban a player then he disconnects, and he can connect again.

Nyuszy 05-14-2011 07:00

Re: Not working get_systime
 
this is because you don't write the player's authid to the database: you kick the player and you want to get the authid of a disconnected player. so the authid row remains blank...

monolit 05-14-2011 07:09

Re: Not working get_systime
 
I do,

PHP Code:

format(szTemp,charsmax(szTemp),"INSERT INTO `bans` ( `auth` , `ban_time`, `ban_reason`, `ban_admin`)VALUES ('%s','%d', '%s', '%s');"szTargetAuthget_systime() + bantimeszReasonszAdminName

Also I can see everything in my phpmyadmin, everything looks perfect, I think the issue is with get_systime()

Nyuszy 05-14-2011 12:47

Re: Not working get_systime
 
try this:

PHP Code:

        server_cmd("kick #%d ^"You are banned,^ncheck your console^""get_user_userid(player) )
        
        new 
szTargetAuth[33];
        
get_user_authid(playerszTargetAuth32

--->

PHP Code:

        new szTargetAuth[33];
        
get_user_authid(playerszTargetAuth32)

        
server_cmd("kick #%d ^"You are banned,^ncheck your console^""get_user_userid(player) ) 


fysiks 05-14-2011 14:43

Re: Not working get_systime
 
Quote:

Originally Posted by monolit (Post 1469099)
Also I can see everything in my phpmyadmin, everything looks perfect, I think the issue is with get_systime()

Then you need to check the value of both iBan[id] and get_systime() and see if either are correct.

monolit 05-14-2011 15:29

Re: Not working get_systime
 
Quote:

Originally Posted by fysiks (Post 1469345)
Then you need to check the value of both iBan[id] and get_systime() and see if either are correct.

Like I've to get systime and compare it with systime + bantime ?

monolit 05-14-2011 15:44

Re: Not working get_systime
 
Ok I've got this working, the problem was in say event, it checked if is user admin, and if not it returned PLUGIN_CONTINUE; only after that I checked mutetime > systime. so it didn't reach that check.

Also I've got one more problem, when I reconnect, mute dissapears, and I again can talk, even if the mute time is still in sql, I think the problem is in loading.

PHP Code:

public client_putinserver(id)
{
    
Load_MySql(id)


PHP Code:

public Load_MySql(id)
{
    new 
szAuthID[33], szTemp[512]
    
get_user_authid(idszAuthID32)
    
    new 
Data[1]
    
Data[0] = id
    
    format
(szTemp,charsmax(szTemp),"SELECT * FROM `bans` WHERE (`bans`.`auth` = '%s')"szAuthID)
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
}

public 
register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
    {
        
log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError)
    }
    else if(
FailState == TQUERY_QUERY_FAILED)
    {
        
log_amx("Load Query failed. [%d] %s"ErrcodeError)
    }

    new 
id
    id 
Data[0]
    
    if(
SQL_NumResults(Query) >= 1
    {
        
iMute[id]    = SQL_ReadResult(Query1)
        
SQL_ReadResultQuery2iMuteReason[id], charsmaxiMuteReason[ ] ) )
        
SQL_ReadResultQuery3iMuteAdmin[id], charsmaxiMuteAdmin[ ] ) )
        
        
iBan[id]    = SQL_ReadResult(Query4)
        
SQL_ReadResultQuery5iBanReason[id], charsmaxiBanReason[ ] ) )
        
SQL_ReadResultQuery6iBanAdmin[id], charsmaxiBanAdmin[ ] ) )
    }
    
    if( 
iBan[id] > get_systime() )
    {
        
client_print(idprint_console"*------* *------------* *------*")
        
client_print(idprint_console"*------* You are banned *------*")
        
client_print(idprint_console"*** by: %s"iBanAdmin[id])
        
client_print(idprint_console"*** for: %s"iBanReason[id])
        
client_print(idprint_console"*------* You are banned *------*")
        
client_print(idprint_console"*------* *------------* *------*")
        
client_cmd(id"disconnect")
    }
    return 
PLUGIN_HANDLED
}

public 
client_disconnect(id)
{
    
iMute[id] = 0;
    
iMuteReason[id][0] = '^0'
    
iMuteAdmin[id][0] = '^0'
    
iBan[id] = 0;
    
iBanReason[id][0] = '^0'
    
iBanAdmin[id][0] = '^0'




All times are GMT -4. The time now is 04:17.

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