The Vault

How does SourceMod’s Vault work?

A Vault was an Admin-Mod concept that let you store key/value pairs in a text file. In SourceMod, we’ve taken this a step up. The vault is implemented as four data structures: The Manager, Vault Masters, a Vault itself, and a Vault Entry.

The Vault Manager lets you move between different storage mechanisms. The planned implementations are Text (standard text files, for old-timers), Binary (efficient storage that can’t be edited by hand), and SQL (for integration with the web interface).

An IVaultMaster is an implementation of a vault access structure – these will let you open a vault from the Text/Binary/SQL interfaces. In AMX Mod and Admin-Mod, the Vault was a global storage facility. In SourceMod, you can have individual vaults, for example:

var vault = Vault("my_vault");
var str = vault.GetKey("STEAM_0:%s", id);

This will greatly enhance a plugin’s ability to manage its own persistent data.

An IVault is a single structure with access to a chunk of data sets, called IVaultEntrys. When you open an IVault with a IVaultMaster, you get an IVault back. When you get a key from an IVault, you get an IVaultEntry. The entry has three parameters:
The Key (i.e., the variable)
The Value (the variable’s contents)
The Timestamp (the last edit of the variable. 0 for persistent).

The timestamp addition was suggested by Geesu for a new cool feature of the Vault API – pruning! Now you can prune and clear individual vaults based on their date, and even set dates to be persistent, or invulnerable to pruning.

Vaults are far more powerful in SourceMod, as they can be used for temporary tables, persistent configuration data, and abstract storage; and since you can choose more efficient storage mechanisms, I imagine they will become much more used as time goes on.

2 Responses to “The Vault”

  1. sYs73m says:

    Good job on confusing the piss out of me.

    A+

  2. Geesu says:

    Timestamps RULE!!!!!!!!

Leave a Reply

You must be logged in to post a comment.