Raised This Month: $32 Target: $400
 8% 

Solved Question about nVault Timestamps


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 02-05-2020 , 13:29   Question about nVault Timestamps
Reply With Quote #1

Does nvault_pset literally update a key without a timestamp or does it still set a timestamp but a permanent one? I want to know whether I can update a key with nvault_pset which has been created (previously set) with nvault_set, but without touching its timestamp.

Last edited by redivcram; 02-05-2020 at 17:24.
redivcram is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-05-2020 , 13:33   Re: Question about nVault Timestamps
Reply With Quote #2

All pset does is set the timestamp to 0, so there is no timestamp on permanent records.
__________________
Bugsy is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 02-05-2020 , 13:36   Re: Question about nVault Timestamps
Reply With Quote #3

Really? Pity you couldn't do the opposite of nvault_touch; Updating the key's data without touching its timestamp...

Last edited by redivcram; 02-05-2020 at 13:37.
redivcram is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-05-2020 , 13:46   Re: Question about nVault Timestamps
Reply With Quote #4

The fact that the timestamp is 0 makes it a permanent record. There is no separate field in a vault record that would allow both a timestamp and permanent status. So you can make a set record permanent by touching it with 0.
__________________

Last edited by Bugsy; 02-05-2020 at 13:46.
Bugsy is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 02-05-2020 , 13:52   Re: Question about nVault Timestamps
Reply With Quote #5

I don't believe I've made myself clear enough. I want to update the key's data without changing its current timestamp. I assumed nvault_pset would not touch the key's timestamp at all instead of actually setting it to 0 making it permanent.

Last edited by redivcram; 02-05-2020 at 13:53.
redivcram is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-05-2020 , 14:09   Re: Question about nVault Timestamps
Reply With Quote #6

So what you need to do is use nvault_lookup() which allows you to get the current timestamp. Then call set or pset, followed by a touch using the timestamp retrieved with lookup.
__________________
Bugsy is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 02-05-2020 , 14:15   Re: Question about nVault Timestamps
Reply With Quote #7

Jeez, all this time no one really bothered turning all of that improvisation into one nvault_update ish method? Confusing at first glance, let alone never came to mind. As long as It's possible to achieve my goal, It's good. Thanks! Haven't tested it, yet.
redivcram is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-05-2020 , 14:49   Re: Question about nVault Timestamps
Reply With Quote #8

If you're touching the data the timestamp should theoretically reflect that.
__________________
Bugsy is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 02-05-2020 , 17:26   Re: Question about nVault Timestamps
Reply With Quote #9

PHP Code:
#include <amxmodx>
#include <nvault>

new gVault;

public 
plugin_init() {
    
    
register_plugin("nVault Update Test""1.0""Cram");
    
    
gVault nvault_open("nvault_update-test");
    
    
register_clcmd("nvault_set""CmdSet");
    
register_clcmd("nvault_get""CmdGet");
    
register_clcmd("nvault_update""CmdUpdate");
}

public 
plugin_end() {
    
    
nvault_close(gVault);
}

public 
CmdSet(id) {
    
    new 
szArgv[16];
    
read_argv(1szArgvcharsmax(szArgv));
    
    
SetVaultData(idszArgv);
    
    
console_print(id"^n[NVAULT SET]^nSaved data to nVault:^n%s^n"szArgv);
    
    return 
PLUGIN_HANDLED;
}

public 
CmdGet(id) {
    
    new 
szAuthID[32], szData[16], iTimeStamp;
    
    
get_user_authid(idszAuthIDcharsmax(szAuthID));
    
    if(
nvault_lookup(gVaultszAuthIDszDatacharsmax(szData), iTimeStamp))
        
console_print(id"^n[NVAULT GET]^nData: %s^nTimestamp: %d^n"szDataiTimeStamp);
    else
        
console_print(id"^n[NVAULT GET] No data found.^n");
        
    return 
PLUGIN_HANDLED;
}

public 
CmdUpdate(id) {
    
    new 
szAuthID[32], szData[16], iTimeStampszArgv[16];
    
    
get_user_authid(idszAuthIDcharsmax(szAuthID));
    
read_argv(1szArgvcharsmax(szArgv));
    
    if(
nvault_lookup(gVaultszAuthIDszDatacharsmax(szData), iTimeStamp)) {
        
        
nvault_pset(gVaultszAuthIDszArgv);
        
nvault_touch(gVaultszAuthIDiTimeStamp);
        
        
console_print(id"^n[NVAULT UPDATE]^nUpdated data in nVault:^nOld Value: %s^nNew Value: %s^n"szDataszArgv);
    }
    else {
        
        
SetVaultData(idszArgv);
        
        
console_print(id"^n[NVAULT UPDATE] No initial data found to update.^nSet new data instead.^n");
    }
    
    return 
PLUGIN_HANDLED;
}

SetVaultData(idszData[]) {
    
    new 
szAuthID[32];
    
    
get_user_authid(idszAuthIDcharsmax(szAuthID));
    
    
nvault_set(gVaultszAuthIDszData);
    
    return 
PLUGIN_HANDLED;

Worked fine for me. Timestamp remains the same when using Update instead of Set for the second time.

Last edited by redivcram; 02-05-2020 at 17:28.
redivcram 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 21:29.


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