Raised This Month: $ Target: $400
 0% 

Nvault data -> Mysql


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
csoldjb
Member
Join Date: Dec 2010
Old 02-08-2013 , 10:57   Re: Nvault data -> Mysql
Reply With Quote #2

PHP Code:
// Here is an exampe.(The code about reading nvault data is copied from Bugsy)
#include <amxmodx>
#include <amxmisc>
#include <nvault>
#include <sqlx>

#define PLUGIN_NAME    "nVault2MySQL"
#define PLUGIN_VERSION    "1.0"
#define PLUGIN_AUTHOR    "Csoldjb"


new const szNURL[]="addons/amxmodx/data/vault/blacklist.vault" 


// BlackList
// Sheet format
/*
    BlackName    Info
    
    sbbaobao    sb123
    hzqst        456
    ...        ...
*/


new Handle:hDbTuple

new g_ERROR[512



const 
MaxKeyLen  50
const MaxValLen  110
const DataBuffer 128  



public plugin_init()
{
    
register_plugin(PLUGIN_NAMEPLUGIN_VERSIONPLUGIN_AUTHOR);
    
register_concmd("test","test"
    
    
hDbTuple=SQL_MakeDbTuple("127.0.0.1","root","12345","cssql"
    
    new 
iErrorCode
    
new Handle:hSqlConnection SQL_Connect(hDbTuple,iErrorCode,g_ERROR,511
    
    if(
hSqlConnection == Empty_Handle)
    {
        
console_print(1,"[SQL]SQL Connect Failed!")
        
set_fail_state("SQL Connect Failed!")
    }
    
    new 
Handle:hQuery 
    hQuery
=SQL_PrepareQuery(hSqlConnection,"CREATE TABLE IF NOT EXISTS BlackList (BlackName char(40),Info CHAR(100))")
    
    if(!
SQL_Execute(hQuery))
    {
        
SQL_QueryError(hQuery,g_ERROR,511)
        
console_print(1,"[SQL]SQL TABLE QUERY Failed For Reason:%s",g_ERROR)
        
set_fail_state("[SQL]SQL TABLE QUERY Failed!")
    }
    
    
SQL_FreeHandle(hQuery)
    
SQL_FreeHandle(hSqlConnection)    
}
public 
test(id)
{
    
client_print(1,print_chat,"[ID:%i] MySQL Test Started",id)
    
    new 
iErrorCode
    
new Handle:hSqlConnection SQL_Connect(hDbTuple,iErrorCode,g_ERROR,511)
    
    if(
hSqlConnection == Empty_Handle)
    {
        
console_print(1,"[SQL]SQL Connect Failed!")
        
set_fail_state("SQL Connect Failed!")
    }
    
    new 
iFile
    
new iVaultMagic iVaultVersion iVaultEntries
    
new iKeyLen iValLen iTimeStamp
    
new szKeyMaxKeyLen ] , szValMaxValLen ] , RawDataDataBuffer ]
    
    
iFile fopen(szNURL,"rb")
    if ( !
iFile )
    {
        
client_print(1,print_chat,"[nVault]File Read Failed!")
        return
    }
    

    
fread_rawiFile RawData BLOCK_INT)
    
    
iVaultMagic RawData[0]
    if ( 
iVaultMagic != 0x6E564C54 )
    {
        
client_print(1,print_chat,"[nVault]Magic Vault!")
        return
    }
    
    
fread_rawiFile RawData BLOCK_SHORT )
    
iVaultVersion RawData[0] & 0xFFFF
    
if ( iVaultVersion != 0x0200 )
    {
        
client_print(1,print_chat,"[nVault]Vault Version!")
        return
    }
    
    
    
fread_rawiFile RawData BLOCK_INT )
    
iVaultEntries RawData[0]
    
    
client_print(1,print_chat,"[nVault] Entries Found:%d",iVaultEntries)
    
    for ( new 
iEntry iEntry iVaultEntries iEntry++ )
    {
        
fread_rawiFile RawData BLOCK_INT )
        
iTimeStamp RawData]
        
        
fread_rawiFile RawData BLOCK_BYTE )
        
iKeyLen RawData] & 0xFF
        
        fread_raw
iFile RawData BLOCK_SHORT )
        
iValLen RawData] & 0xFFFF
        
        fread_raw
iFile RawData iKeyLen BLOCK_CHAR )
        
ReadStringszKey iKeyLen charsmaxszKey ) , RawData )
    
        
fread_rawiFile RawData iValLen BLOCK_CHAR );
        
ReadStringszVal iValLen charsmaxszVal ) , RawData )

        
//server_print( "Entry=%d KeyLen=%d ValLen=%d TimeStamp=%d" , iEntry , iKeyLen , iValLen , iTimeStamp )
        
        
client_print(1,print_chat,"[DATA][Key:%s][Value:%s]",szKey,szVal)
        
        new 
Handle:Query
        
new szQuery[256]
        
format(szQuery,255,"INSERT BlackList VALUES (^'%s^',^'%s^')",szKey,szVal)
        
Query SQL_PrepareQuery(hSqlConnection,szQuery)
        
        if(!
SQL_Execute(Query))
        {
            
client_print(1,print_chat,"[DATA] Convery Failed!")
            continue
        }
        
client_print(1,print_chat,"[DATA] Convery Success!")
        
        
SQL_FreeHandle(Query)
    }
    
    
fcloseiFile )
}
stock ReadStringszDestString[] , iLen iMaxLen SourceData[] )
{
    new 
iStrPos = -1;
    new 
iRawPos 0;
    
    while ( ( ++
iStrPos iLen ) && ( iStrPos iMaxLen ) && ( iRawPos DataBuffer ) )
    {
        
szDestStringiStrPos ] = ( SourceDataiRawPos ] >> ( ( iStrPos ) * ) ) & 0xFF;
        
        if ( 
iStrPos && ( ( iStrPos ) == ) ) iRawPos++
    }
    
    
szDestStringiStrPos ] = EOS


Last edited by csoldjb; 02-08-2013 at 11:14.
csoldjb is offline
 



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 20:38.


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