Raised This Month: $ Target: $400
 0% 

Not working get_systime


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
monolit
Junior Member
Join Date: May 2011
Old 05-14-2011 , 05:31   Not working get_systime
Reply With Quote #1

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.

Last edited by monolit; 05-14-2011 at 06:17.
monolit is offline
Nyuszy
Senior Member
Join Date: Apr 2009
Old 05-14-2011 , 07:00   Re: Not working get_systime
Reply With Quote #2

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...
Nyuszy is offline
monolit
Junior Member
Join Date: May 2011
Old 05-14-2011 , 07:09   Re: Not working get_systime
Reply With Quote #3

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()
monolit is offline
Nyuszy
Senior Member
Join Date: Apr 2009
Old 05-14-2011 , 12:47   Re: Not working get_systime
Reply With Quote #4

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) ) 
Nyuszy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-14-2011 , 14:43   Re: Not working get_systime
Reply With Quote #5

Quote:
Originally Posted by monolit View Post
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.
__________________
fysiks is offline
monolit
Junior Member
Join Date: May 2011
Old 05-14-2011 , 15:29   Re: Not working get_systime
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
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 is offline
monolit
Junior Member
Join Date: May 2011
Old 05-14-2011 , 15:44   Re: Not working get_systime
Reply With Quote #7

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'


Last edited by monolit; 05-14-2011 at 16:15.
monolit is offline
Reply



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 04:18.


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