Raised This Month: $51 Target: $400
 12% 

Transfer vault information to SQL


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 12-27-2023 , 19:36   Transfer vault information to SQL
Reply With Quote #1

Hello, I am going to use sql, how to read the information of the vault file and enter it in the database?
__________________
amirwolf is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-27-2023 , 20:05   Re: Transfer vault information to SQL
Reply With Quote #2

I would assume you'd probably have to write a plugin or some other code that reads the vault and then runs the SQL queries to insert the data into the database. Fairly straight forward, especially since the vault code already exists and the SQL queries need to be written for the new method anyways. The only difference is that this is a one-time plugin.
__________________

Last edited by fysiks; 12-27-2023 at 20:05.
fysiks is offline
Old 12-27-2023, 20:23
amirwolf
This message has been deleted by amirwolf. Reason: Useless answer
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 12-27-2023 , 20:57   Re: Transfer vault information to SQL
Reply With Quote #3

All credits go to bugsy for his amazing work
Get example.vault at https://forums.alliedmods.net/showthread.php?t=66657
upload.sql

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>

#pragma ctrlchar '\'

new vault[] = "example"
new Array:g_aArray

const MaxKeyLen  255;     //Max 255
const MaxValLen  512;     //Max 65535
const DataBuffer 128;     //Make this the greater of (MaxKeyLen / 4) or (MaxValLen / 4)

enum _eData{
    
szString[32],
    
iValue[256],
    
iTime
}

public 
plugin_init()
{
    
register_srvcmd("f""srvcmd_f")
    
g_aArray ArrayCreateeData )
}

public 
srvcmd_f()
{
    new 
Data[eData], buffer_id[64], buffer_data[512]
    new 
total ReadVault(vault)
    new 
iSize ArraySize(g_aArray)
    new 
text[512]
    
    
server_print("%s - total entries: %d"vaulttotal)
    for (new 
iiSizei++)
    {
        
ArrayGetArrayg_aArrayiData );
        
SQL_QuoteStringFmt(Empty_Handlebuffer_idcharsmax(buffer_id), "%s"Data[szString])
        
SQL_QuoteStringFmt(Empty_Handlebuffer_datacharsmax(buffer_data), "%s"Data[iValue])
        
formatex(textcharsmax(text), "INSERT INTO `%s` VALUES (`id`, `data`, `timestamp`) VALUES \'%s\', \'%s\', %d)"vaultbuffer_idbuffer_dataData[iTime])
        
write_file("upload.sql"text)
    }
}

public 
ReadVault( const szVault[])
{
    new 
szFile128 ];
    new 
iVaultMagic iVaultVersion iVaultEntries;
    new 
iKeyLen iValLen iTimeStamp;
    new 
szKeyMaxKeyLen ] , szValMaxValLen ] , RawDataDataBuffer ];
    
    
formatexszFileget_datadirszFile charsmaxszFile ) ) ] , charsmaxszFile ) , "/vault/%s.vault" szVault );
    
    new const 
iFile fopenszFile "rb" );

    if ( 
iFile ){
        
// Vault Magic
        
fread_rawiFile RawData BLOCK_INT );
        
iVaultMagic RawData];
        
        
// Vault Version
        
fread_rawiFile RawData BLOCK_SHORT );
        
iVaultVersion RawData] & 0xFFFF;

        
// Vault Entries
        
fread_rawiFile RawData BLOCK_INT );
        
iVaultEntries RawData];

        for ( new 
iEntry iEntry iVaultEntries iEntry++ )
        {
            
// TimeStamp
            
fread_rawiFile RawData BLOCK_INT );
            
iTimeStamp RawData];
            
            
// Key Length
            
fread_rawiFile RawData BLOCK_BYTE );
            
iKeyLen RawData] & 0xFF;
            
            
// Val Length
            
fread_rawiFile RawData BLOCK_SHORT );
            
iValLen RawData] & 0xFFFF;
            
            
// Key Data
            
fread_rawiFile RawData iKeyLen BLOCK_CHAR );
            
ReadStringszKey iKeyLen charsmaxszKey ) , RawData );
        
            
// Val Data
            
fread_rawiFile RawData iValLen BLOCK_CHAR );
            
ReadStringszVal iValLen charsmaxszVal ) , RawData );

            
WrapItUp(szKeyszValiTimeStamp);
        }
        
        
fcloseiFile );
        return 
iVaultEntries;
    }
}

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

public 
WrapItUp(name[], value[], timestamp){
    new 
Data[eData];
    
copyDataszString ], charsmaxDataszString ] ), name );
    
copyDataiValue ], charsmaxDataiValue ] ), value );
    
DataiTime ] = timestamp;
    
ArrayPushArray(g_aArrayData);

__________________
bigdaddy424 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-28-2023 , 00:01   Re: Transfer vault information to SQL
Reply With Quote #4

nVault Utility
PHP Code:
#include <amxmodx>
#include <nvault_util>

new const Version[] = "0.1";

public 
plugin_init() 
{
    
register_plugin"nVault to SQL" Version "bugsy" );
    
nVault_to_SQL();
}

public 
nVault_to_SQL()
{
    new 
iVault nvault_util_open"yourVault" );

    
nvault_util_readalliVault "nVault_to_SQL_Result" );
    
    
nvault_util_closeiVault );
}

public 
nVault_to_SQL_ResultiCurrent iTotal , const szKey[] , const szVal[] , iTimeStamp , const Data[] , iSize )
{
    new 
szBuffer128 ];
    
formatexszBuffer charsmaxszBuffer ) , "INSERT INTO yourTable (%s) VALUES (%s)" szKey szVal );
    
    
//Execute SQL (szBuffer)

__________________
Bugsy is offline
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 12-28-2023 , 09:09   Re: Transfer vault information to SQL
Reply With Quote #5

Quote:
Originally Posted by bigdaddy424 View Post
All credits go to bugsy for his amazing work
Get example.vault at https://forums.alliedmods.net/showthread.php?t=66657
Warnings during compile
Code:
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2013 AMX Mod X Team

C:\Program Files (x86)\Steam\steamapps\common\Half-Life\cstrike\addons\amxmodx\scripting\test.sma(62) : warning 204: symbol is assigned a value that is never used: "iVaultVersion"
C:\Program Files (x86)\Steam\steamapps\common\Half-Life\cstrike\addons\amxmodx\scripting\test.sma(58) : warning 204: symbol is assigned a value that is never used: "iVaultMagic"
C:\Program Files (x86)\Steam\steamapps\common\Half-Life\cstrike\addons\amxmodx\scripting\test.sma(96) : warning 209: function "ReadVault" should return a value
Header size:            516 bytes
Code size:             2968 bytes
Data size:              716 bytes
Stack/heap size:      16384 bytes
Total requirements:   20584 bytes

3 Warnings.
Done.
<<< Process finished (PID=696). (Exit code 0)
================ READY ================
The file is created but I don't understand how to import it
I use this plagin
__________________
amirwolf is offline
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 12-28-2023 , 09:20   Re: Transfer vault information to SQL
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
nVault Utility
PHP Code:
#include <amxmodx>
#include <nvault_util>

new const Version[] = "0.1";

public 
plugin_init() 
{
    
register_plugin"nVault to SQL" Version "bugsy" );
    
nVault_to_SQL();
}

public 
nVault_to_SQL()
{
    new 
iVault nvault_util_open"yourVault" );

    
nvault_util_readalliVault "nVault_to_SQL_Result" );
    
    
nvault_util_closeiVault );
}

public 
nVault_to_SQL_ResultiCurrent iTotal , const szKey[] , const szVal[] , iTimeStamp , const Data[] , iSize )
{
    new 
szBuffer128 ];
    
formatexszBuffer charsmaxszBuffer ) , "INSERT INTO yourTable (%s) VALUES (%s)" szKey szVal );
    
    
//Execute SQL (szBuffer)

All information is displayed
Now I need to transfer everything to the database
__________________
amirwolf is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-28-2023 , 12:46   Re: Transfer vault information to SQL
Reply With Quote #7

Quote:
Originally Posted by amirwolf View Post
All information is displayed
Now I need to transfer everything to the database
Ok, I assumed you had the DB aspect covered. What are the table and field names?
__________________
Bugsy is offline
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 12-28-2023 , 16:41   Re: Transfer vault information to SQL
Reply With Quote #8

CRXRanks table name
It has 6 fields

Player
XP
Level
Next XP
Rank
Next Rank

But I want to add name to the fields
__________________

Last edited by amirwolf; 12-28-2023 at 16:46.
amirwolf is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-28-2023 , 20:06   Re: Transfer vault information to SQL
Reply With Quote #9

How is your data in nvault stored? I cannot write code for you without knowing these details.

key=Steamid
val=Player (is this name),XP,Level,NextXP,Rank,NextRank?

So ?
key="STEAM_0:0:123456"
val="'Bugsy',45,1,2,6,7"
__________________
Bugsy is offline
amirwolf
Senior Member
Join Date: Feb 2019
Location: Iran
Old 12-29-2023 , 09:46   Re: Transfer vault information to SQL
Reply With Quote #10

I'm sorry for the late reply, I thought it was in the general section
It's like this
Code:
INSERT INTO `crxranks` (`Player`, `XP`, `Level`, `Next XP`, `Rank`, `Next Rank`) VALUES
('Steam_12345', 471, 3, 500, 'KilleR', 'HitMAN'),
But the name has not been added for it yet
__________________

Last edited by amirwolf; 12-29-2023 at 10:21.
amirwolf 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 18:23.


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