Raised This Month: $ Target: $400
 0% 

Help about SQL timestamp and banning system.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Marcoux
Junior Member
Join Date: Oct 2009
Old 10-08-2009 , 12:59   Help about SQL timestamp and banning system.
Reply With Quote #1

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.
Marcoux is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-08-2009 , 13:00   Re: Help about SQL timestamp and banning system.
Reply With Quote #2

Tell me what you want to do and I can write you a simple script showing how to do it.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
10101010
BANNED
Join Date: Oct 2009
Old 10-08-2009 , 13:23   Re: Help about SQL timestamp and banning system.
Reply With Quote #3

Why would you want that? You can ban players normally

EDIT: This may help you


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

Last edited by 10101010; 10-08-2009 at 13:53.
10101010 is offline
Marcoux
Junior Member
Join Date: Oct 2009
Old 10-08-2009 , 13:51   Re: Help about SQL timestamp and banning system.
Reply With Quote #4

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.
Marcoux is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-08-2009 , 13:54   Re: Help about SQL timestamp and banning system.
Reply With Quote #5

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
        
}
    }

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Marcoux
Junior Member
Join Date: Oct 2009
Old 10-08-2009 , 13:57   Re: Help about SQL timestamp and banning system.
Reply With Quote #6

Will try, In a few minutes I answer you

Thanks you very much
Marcoux is offline
Marcoux
Junior Member
Join Date: Oct 2009
Old 10-08-2009 , 14:07   Re: Help about SQL timestamp and banning system.
Reply With Quote #7

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)
Marcoux is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-08-2009 , 14:36   Re: Help about SQL timestamp and banning system.
Reply With Quote #8

http://forums.alliedmods.net/showthread.php?t=91915
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Marcoux
Junior Member
Join Date: Oct 2009
Old 10-08-2009 , 15:27   Re: Help about SQL timestamp and banning system.
Reply With Quote #9

Genius!
Karmageddon!
Marcoux 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 15:14.


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