View Single Post
Author Message
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-24-2008 , 17:23   FVault - A new vault system!
Reply With Quote #1

I created this for a few reasons:
  • This does not require any special modules. All that is required is:
    Code:
    #include <amxmodx> #include <fvault>
  • Has the ability to iterate through all vault names and all vault keys within each vault.
  • Keeps the original functionality of nvault with more features.

Functions:
  • PHP Code:
    /** 
     * Retrieves a key name specified by its number
     * 
     * @param vaultname    Vault name to look in
     * @param keynum    Key number within the vault to find key name
     * @param key        String which key name will be copied to
     * @param len        Length of key name
     * @return        Returns 1 on success, 0 on failue.
     */
    fvault_get_keyname(const vaultname[], const keynumkey[], len
  • PHP Code:
    /** 
     * Retrieves a key number specified by its name
     * 
     * @param vaultname    Vault name to look in
     * @param key        Key name to search for
     * @return        Returns key number on success, -1 on failure
     */
    fvault_get_keynum(const vaultname[], const key[]) 
  • PHP Code:
    /** 
     * Retrieves data specified by a key
     * 
     * @param vaultname    Vault name to look in
     * @param key        Key name to look for the data
     * @param data        String which data will be copied to
     * @param len        Length of data
     * @param timestamp    The unix time of when the data was last set ( -1 if permanent data, 0 if old fvault version ) ( optional param )
     * @return        Returns 1 on success, 0 on failue.
     */
    fvault_get_data(const vaultname[], const key[], data[], len, &timestamp=0
  • PHP Code:
    /** 
     * Sets data of a key with current timestamp
     * 
     * @param vaultname    Vault name to look in
     * @param key        Key name to which data will be set
     * @param data        Data to set to key
     * @return        Does not return a value.
     */
    fvault_set_data(const vaultname[], const key[], const data[]) 
  • PHP Code:
    /** 
     * Sets data of a key permanently (can't be removed with fvault_prune)
     * 
     * @param vaultname    Vault name to look in
     * @param key        Key name to which data will be set
     * @param data        Data to set to key
     * @return        Does not return a value.
     */
    fvault_pset_data(const vaultname[], const key[], const data[]) 
  • PHP Code:
    /** 
     * Removes a key from a vault
     * 
     * @param vaultname    Vault name to look in
     * @param key        Key to remove
     * @return        No return
     */
    fvault_remove_key(const vaultname[], const key[]) 
  • PHP Code:
    /**
     * Prunes the vault for keys that are within the given timestamps
     * 
     * @param vaultname    Vault name to look in
     * @param start        If timestamp is after this Unix Time (set -1 to prune from very start)
     * @param end        If timestamp is before this Unix Time (set -1 to prune to most time)
     * @return        Returns number of keys pruned
     */
    fvault_prune(const vaultname[], const start=-1, const end=-1
  • PHP Code:
    /**
     * Updates the timestamp on a key located within the vault
     * 
     * @param vaultname    Vault name to look in
     * @param key        Key to update timestamp (if it doesn't exist, a blank value will be set)
     * @param timestamp    Unix Time to set for the key (-1 for current time)
     * @return        Returns 2 on new entry, 1 on success, 0 on failure for the key having a permanent timestamp
     */
    fvault_touch(const vaultname[], const key[], const timestamp=-1
  • PHP Code:
    /** 
     * Retrieves total keys located within the vault
     * 
     * @param vaultname    Vault name to look in
     * @return        Returns amount of keys in vault
     */
    fvault_size(const vaultname[]) 
  • PHP Code:
    /** 
     * Clears all key entries for a vault
     * 
     * @param vaultname    Vault name to erase
     * @return        No return
     */
    fvault_clear(const vaultname[]) 
  • PHP Code:
    /** 
     * Retrieves a vault name specified by its number
     * 
     * @param vaultnum    Vault number to find the vault name
     * @param vaultname    String which vault name will be copied to
     * @param len        Length of vault name
     * @return        Returns 1 on success, 0 on failue.
     */
    fvault_get_vaultname(const vaultnumvaultname[], len
  • PHP Code:
    /** 
     * Retrieves a vault number specified by its name
     * 
     * @param vaultname    Vault name to find the number
     * @return        Returns vault number on success, -1 on failure
     */
    fvault_get_vaultnum(const vaultname[]) 
  • PHP Code:
    /** 
     * Retrieves total vaults ever created
     * 
     * @return        Returns amount of vaults
     */
    fvault_total() 
  • PHP Code:
    /**
     * Gets all vault keys, data, and timestamps
     * 
     * @param        vaultname - Vault name to look in
     * @param        keys - cellarray holding all of the keys
     * @param        datas - cellarray holding all of the data values
     * @param        timestamps - cellarray holding all of the timestamps
     * 
     * @return        Returns total number of entries in vault
     * 
     * @note        keys needs to be created like this: ArrayCreate(64)
     *             datas needs to be created like this: ArrayCreate(512)
     *             timestamps need to be created like this: ArrayCreate()
     */
    fvault_load(const vaultname[], Array:keys=Invalid_Array, Array:datas=Invalid_Array, Array:timestamps=Invalid_Array

Some examples:
  • Code:
    // How to find all vaults created: new total = fvault_total(); new vaultname[32]; for( new i = 0; i < total; i++ ) {     fvault_get_vaultname(i, vaultname, sizeof(vaultname) - 1);     server_print("Vault [%i]: %s", i, vaultname); }
  • Code:
    // How to find all keys within a vault: new const vaultname[] = "myvault"; new total = fvault_size(vaultname); new key[32], data[64]; for( new i = 0; i < total; i++ ) {     fvault_get_keyname(vaultname, i, key, sizeof(key) - 1);     fvault_get_data(vaultname, key, data, sizeof(data) - 1);         server_print("Key: %s | Data: %s", key, data); }
  • Code:
    // More efficient method to find all keys within a vault: new const vaultname[] = "myvault"; new Array:keys = ArrayCreate(64); new Array:datas = ArrayCreate(512); new total = fvault_load(vaultname, keys, datas); new key[64], data[512]; for( new i = 0; i < total; i++ ) {     ArrayGetString(keys, i, key, 31);     ArrayGetString(datas, i, data, 511);         server_print("Key: %s | Data: %s", key, data); }
  • Code:
    // Pruning player agree/decline after 15 days of not being updated // 15 days * 24 hours * 60 minutes * 60 seconds = 15 days in seconds new end_prune_time = get_systime() - (15 * 24 * 60 * 60); fvault_prune("player_agree", _, end_prune_time);
  • Code:
    // A simple exp mod #include <amxmodx> #include <fvault> new const g_vault_name[] = "EXP_MOD"; new g_exp[33]; public client_authorized(plr) {     if( !is_user_hltv(plr) && !is_user_bot(plr) )     {         LoadExp(plr);     } } public client_disconnect(plr) {     if( g_exp[plr] > 0 )     {         SaveExp(plr);                 g_exp[plr] = 0;     } } LoadExp(plr) {     new authid[35];     get_user_authid(plr, authid, sizeof(authid) - 1);         new data[16];     if( fvault_get_data(g_vault_name, authid, data, sizeof(data) - 1) )     {         g_exp[plr] = str_to_num(data);     }     else     {         g_exp[plr] = 0;     } } SaveExp(plr) {     new authid[35];     get_user_authid(plr, authid, sizeof(authid) - 1);         new data[16];     num_to_str(g_exp[plr], data, sizeof(data) - 1);         fvault_set_data(g_vault_name, authid, data); }

If there are any problems, please tell me so that I can fix them.
Attached Files
File Type: inc fvault.inc (14.3 KB, 12285 views)
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 02-06-2011 at 23:21. Reason: Updated.
Exolent[jNr] is offline