2014-08-04 16:12:15 +04:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
|
|
|
|
|
|
|
//
|
|
|
|
// NVault Functions
|
|
|
|
//
|
2005-08-02 00:22:01 +04:00
|
|
|
|
|
|
|
#if defined _nvault_included
|
2015-02-25 01:56:17 +03:00
|
|
|
#endinput
|
2005-08-02 00:22:01 +04:00
|
|
|
#endif
|
|
|
|
#define _nvault_included
|
|
|
|
|
2015-02-25 01:56:17 +03:00
|
|
|
#pragma reqlib nvault
|
|
|
|
#if !defined AMXMODX_NOAUTOLOAD
|
|
|
|
#pragma loadlib nvault
|
2006-05-10 14:42:49 +04:00
|
|
|
#endif
|
2005-08-02 15:12:42 +04:00
|
|
|
|
2017-12-09 02:22:43 +03:00
|
|
|
/**
|
|
|
|
* @global All timestamps are in UNIX epoch form.
|
|
|
|
*/
|
2006-08-21 01:23:38 +04:00
|
|
|
|
2017-12-09 02:22:43 +03:00
|
|
|
/**
|
|
|
|
* Opens a vault by name. Creates a vault if it doesn't exist yet.
|
|
|
|
*
|
|
|
|
* @param name Name of the vault. The vault will be created in
|
|
|
|
* ${amxx_datadir}/vault directory.
|
|
|
|
*
|
|
|
|
* @return The vault handle to be used in other natives.
|
|
|
|
* INVALID_HANDLE (-1) if not successfully opened.
|
2006-08-21 01:23:38 +04:00
|
|
|
*/
|
2005-08-02 00:22:01 +04:00
|
|
|
native nvault_open(const name[]);
|
|
|
|
|
2017-12-09 02:22:43 +03:00
|
|
|
/**
|
2018-07-24 16:36:31 +03:00
|
|
|
* Retrieves a value from the given key.
|
2017-12-09 02:22:43 +03:00
|
|
|
*
|
|
|
|
* @note An example of retrieving a string:
|
|
|
|
* nvault_get(vaultHandle, "myKey", myString, charsmax(myString));
|
|
|
|
*
|
|
|
|
* @param vault A vault handle returned from nvault_open()
|
|
|
|
* @param key A key to get the value from
|
|
|
|
* @param ... If three argument are given, gets a float value and
|
|
|
|
* puts it in the third argument by reference.
|
|
|
|
* If four arguments are given, gets a string from the
|
|
|
|
* vault and copies it to the third argument, up to
|
|
|
|
* 4th argument characters.
|
|
|
|
*
|
2018-07-24 16:36:31 +03:00
|
|
|
* @return Result as integer if only the first two arguments
|
|
|
|
* of the function are used.
|
|
|
|
* 1 if only the first three arguments are used.
|
|
|
|
* String length if all four parameters are used.
|
2017-12-09 02:22:43 +03:00
|
|
|
* @error On invalid vault handle.
|
2006-08-21 01:23:38 +04:00
|
|
|
*/
|
2015-03-11 16:19:27 +03:00
|
|
|
native nvault_get(vault, const key[], any:...);
|
2005-08-02 00:22:01 +04:00
|
|
|
|
2017-12-09 02:22:43 +03:00
|
|
|
/**
|
2018-07-24 16:36:31 +03:00
|
|
|
* Retrieves full information about a vault entry.
|
2017-12-09 02:22:43 +03:00
|
|
|
*
|
|
|
|
* @param vault A vault handle returned from nvault_open()
|
|
|
|
* @param key A key to get information from
|
|
|
|
* @param value A string where the value should be stored
|
|
|
|
* @param maxlen Maximum length of the @value string
|
|
|
|
* @param timestamp The timestamp of the entry
|
|
|
|
*
|
|
|
|
* @return 1 if an entry was found, 0 otherwise.
|
|
|
|
* @error On invalid vault handle.
|
2006-08-21 01:23:38 +04:00
|
|
|
*/
|
2007-03-05 22:30:40 +03:00
|
|
|
native nvault_lookup(vault, const key[], value[], maxlen, ×tamp);
|
2005-08-02 00:22:01 +04:00
|
|
|
|
2017-12-09 02:22:43 +03:00
|
|
|
/**
|
|
|
|
* Sets value of a vault entry and updates the timestamp.
|
|
|
|
*
|
|
|
|
* @note A new entry is created if one with the given key doesn't exist.
|
|
|
|
*
|
|
|
|
* @param vault A vault handle returned from nvault_open()
|
|
|
|
* @param key A key to set the value for
|
|
|
|
* @param value A value to set
|
|
|
|
*
|
|
|
|
* @noreturn
|
|
|
|
* @error On invalid vault handle.
|
|
|
|
*/
|
2005-08-02 00:22:01 +04:00
|
|
|
native nvault_set(vault, const key[], const value[]);
|
|
|
|
|
2017-12-09 02:22:43 +03:00
|
|
|
/**
|
|
|
|
* Sets value of a vault entry and makes it permanent (non-erasable with nvault_prune()).
|
|
|
|
*
|
|
|
|
* @note A new entry is created if one with the given key doesn't exist.
|
|
|
|
* @note Permanent entries have no timestamp.
|
|
|
|
*
|
|
|
|
* @param vault A vault handle returned from nvault_open()
|
|
|
|
* @param key A key to set the permanent value for
|
|
|
|
* @param value A permanent value to set
|
|
|
|
*
|
|
|
|
* @noreturn
|
|
|
|
* @error On invalid vault handle.
|
|
|
|
*/
|
2005-08-02 00:22:01 +04:00
|
|
|
native nvault_pset(vault, const key[], const value[]);
|
|
|
|
|
2017-12-09 02:22:43 +03:00
|
|
|
/**
|
|
|
|
* Prunes the vault for entries that are within the given timestamps.
|
|
|
|
*
|
|
|
|
* @note This will not erase values set with nvault_pset().
|
|
|
|
* @note An example of pruning all entries that are older than 24 hours:
|
|
|
|
* nvault_prune(vaultHandle, 0, get_systime() - (60 * 60 * 24));
|
|
|
|
*
|
|
|
|
* @param vault A vault handle returned from nvault_open()
|
|
|
|
* @param start The timestamp to start erasing from
|
|
|
|
* @param end The timestamp to erase to
|
|
|
|
*
|
2018-07-24 16:36:31 +03:00
|
|
|
* @return Number of erased values.
|
2017-12-09 02:22:43 +03:00
|
|
|
* @error On invalid vault handle.
|
2006-08-21 01:23:38 +04:00
|
|
|
*/
|
2005-08-02 00:22:01 +04:00
|
|
|
native nvault_prune(vault, start, end);
|
|
|
|
|
2017-12-09 02:22:43 +03:00
|
|
|
/**
|
|
|
|
* Closes a vault.
|
|
|
|
*
|
|
|
|
* @param vault A vault handle returned from nvault_open()
|
|
|
|
*
|
|
|
|
* @noreturn
|
|
|
|
* @error On invalid vault handle.
|
|
|
|
*/
|
2005-08-02 00:22:01 +04:00
|
|
|
native nvault_close(vault);
|
2006-04-26 09:21:29 +04:00
|
|
|
|
2017-12-09 02:22:43 +03:00
|
|
|
/**
|
|
|
|
* Removes an entry from the vault by its key.
|
|
|
|
*
|
|
|
|
* @param vault A vault handle returned from nvault_open()
|
|
|
|
* @param key The key to remove from the vault
|
|
|
|
*
|
|
|
|
* @noreturn
|
|
|
|
* @error On invalid vault handle.
|
|
|
|
*/
|
2006-04-26 09:21:29 +04:00
|
|
|
native nvault_remove(vault, const key[]);
|
|
|
|
|
2017-12-09 02:22:43 +03:00
|
|
|
/**
|
|
|
|
* "Touches" an entry in the vault, updating its timestamp.
|
|
|
|
*
|
|
|
|
* @note If timestamp is equal to -1, it will use the current time.
|
|
|
|
* @note An empty entry is created if one with the given key doesn't exist.
|
|
|
|
*
|
|
|
|
* @param vault A vault handle returned from nvault_open()
|
|
|
|
* @param key The key to search for
|
|
|
|
* @param timestamp Update an entry's timestamp to this one. Default is -1.
|
|
|
|
*
|
|
|
|
* @noreturn
|
|
|
|
* @error On invalid vault handle.
|
2006-08-21 01:23:38 +04:00
|
|
|
*/
|
|
|
|
native nvault_touch(vault, const key[], timestamp=-1);
|