AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help about SQL timestamp and banning system. (https://forums.alliedmods.net/showthread.php?t=105795)

Marcoux 10-08-2009 12:59

Help about SQL timestamp and banning system.
 
Well, I need something like a ban sistem, where the plugin can realize weather If the time specified in a timestamp (or wichever format you may want to use and you think it's convenient) is previous than now, or not, In simple words, it checks if you are still banned.

I have knowledge about MySQL, and plugins, though I don't really realise how to handle well with strings to manage with time, which is pretty hard since of the different sizes of months and else.

Thanks in advance.

Exolent[jNr] 10-08-2009 13:00

Re: Help about SQL timestamp and banning system.
 
Tell me what you want to do and I can write you a simple script showing how to do it.

10101010 10-08-2009 13:23

Re: Help about SQL timestamp and banning system.
 
Why would you want that? You can ban players normally

EDIT: This may help you


http://www.google.com.ar/codesearch?...title&resnum=4

Marcoux 10-08-2009 13:51

Re: Help about SQL timestamp and banning system.
 
Well, lets supose somehow I set a timestamp in a MySQL. Something like this:

----AuthID-----Unban timestamp

Then, when a player connect, it retrieves the unban timestamp from his AuthID.

Up to here, I know how to everything,it's pretty easy.

Now, I want to know if the date and time of the timestamp, is before or after now. In other words, if the player is still banned, or if his ban has ended.

Thats just the thing I want to know.

Exolent[jNr] 10-08-2009 13:54

Re: Help about SQL timestamp and banning system.
 
Here is an example code of how it would be done with timestamps.

PHP Code:

#include < amxmodx >
#include < amxmisc >
#include < sqlx >
#include < fakemeta >

#define ENCODE_TEXT(%1) engfunc( EngFunc_AllocString, %1 )
#define DECODE_TEXT(%1,%2,%3) global_get( glb_pStringBase, %1, %2, %3 )

new Handle:g_hSqlTuple;

public 
plugin_init( ) {
    
g_hSqlTuple SQL_MakeStdTuple( );
}

CheckBanclient ) {
    static 
szAuthid35 ];
    
get_user_authidclientszAuthid34 );
    
    if( 
containiszAuthid"STEAM_0:" ) == -) {
        return;
    }
    
    static 
szQuery128 ];
    
formatexszQuery127"SELECT `timestamp` FROM `bantable` WHERE `authid` = '%s';"szAuthid );
    
    static 
iData];
    
iData] = ENCODE_TEXTszAuthid );
    
    
SQL_ThreadQueryg_hSqlTuple"QueryCheckBan"szQueryiData);
}

public 
QueryCheckBaniFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:fQueueTime ) {
    switch( 
iFailState ) {
        case 
TQUERY_CONNECT_FAILED: {
            
log_amx"Connection failed: %s"szError);
        }
        case 
TQUERY_QUERY_FAILED: {
            
log_amx"Query failed: %s"szError );
        }
        default: {
            new 
iTimeStamp SQL_ReadResulthQuery);
            
            if( 
get_systime( ) >= iTimeStamp ) {
                
// ban time expired
                
                
static szAuthid35 ];
                
DECODE_TEXTiData], szAuthid34 );
                
                static 
szQuery128 ];
                
formatexszQuery127"DELETE FROM `bantable` WHERE `authid` = '%s';"szAuthid );
                
                
SQL_ThreadQueryg_hSqlTuple"QueryDeleteBan"szQuery );
            }
        }
    }
}

public 
QueryDeleteBaniFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:fQueueTime ) {
    switch( 
iFailState ) {
        case 
TQUERY_CONNECT_FAILED: {
            
log_amx"Connection failed: %s"szError);
        }
        case 
TQUERY_QUERY_FAILED: {
            
log_amx"Query failed: %s"szError );
        }
        default: {
            
// successfully deleted ban
        
}
    }
}

AddBanclientiBanMinutes ) {
    static 
szAuthid35 ];
    
get_user_authidclientszAuthid34 );
    
    if( 
containiszAuthid"STEAM_0:" ) == -) {
        return;
    }
    
    new 
iUnbanTime get_systime( ) + ( iBanMinutes 60 );
    
    static 
szQuery128 ];
    
formatexszQuery127"INSERT INTO `bantable` ( `authid`, `timestamp` ) VALUES ( '%s', %i );"szAuthidiUnbanTime );
    
    
SQL_ThreadQueryg_hSqlTuple"QueryAddBan"szQuery );
}

public 
QueryAddBaniFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:fQueueTime ) {
    switch( 
iFailState ) {
        case 
TQUERY_CONNECT_FAILED: {
            
log_amx"Connection failed: %s"szError);
        }
        case 
TQUERY_QUERY_FAILED: {
            
log_amx"Query failed: %s"szError );
        }
        default: {
            
// successfully added ban
        
}
    }



Marcoux 10-08-2009 13:57

Re: Help about SQL timestamp and banning system.
 
Will try, In a few minutes I answer you :D

Thanks you very much

Marcoux 10-08-2009 14:07

Re: Help about SQL timestamp and banning system.
 
Ok I don't know If this is double post, but, It's needed.

Your code worked really fine, I just didin't know about get_systime, which is really usefull since I can manage easily with time in just an integer.

Now what I would like, if you now any API, por getting a more user-friendly time format, from sys time.

Like

128937189273 ---> 02-08-09 14:23:45 (just an example)

Exolent[jNr] 10-08-2009 14:36

Re: Help about SQL timestamp and banning system.
 
http://forums.alliedmods.net/showthread.php?t=91915

Marcoux 10-08-2009 15:27

Re: Help about SQL timestamp and banning system.
 
Genius!
Karmageddon!


All times are GMT -4. The time now is 22:33.

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