ConsoleTokenStore
A internal static class in TavernLib, TavernLib.Backend.RemoteConsole. Reach it through att-stubs' publicized assemblies or Harmony's AccessTools.
Internal: console_tokens.json with an in-memory copy rebuilt after each write, so the check on every command never reads the disk. Server; only the server writes the file.
- Listed in TavernLib.Backend.RemoteConsole
- Nested types
Entry
Fields
8 private and internal fields
| Member | What it is |
|---|---|
private static Dictionary<string, ConsoleTokenStore.Entry> _byId | In-memory copy of the named tokens by id, rebuilt after every load or write. |
private static DateTime _lastLoad | When the file was last tried, used to space out retries. |
private static bool _loadErrorLogged | Whether the unreadable-file error has been logged, so it is logged once. |
private static int _ownerGeneration | In-memory copy of the owner token's generation from the file. |
private static readonly string FilePath | Path of console_tokens.json in the ModdingTavern folder. |
private static readonly ConditionalWeakTable<CommandPart, string> Paths | Cache of the typed path (for example player progression list) for each command or module. |
private static readonly TimeSpan RetryEvery | How long to wait before trying again to read a token file that failed to load (5 seconds). |
private static readonly ConsoleTokenFile TokenFile | The config file object used to read and write console_tokens.json. |
Properties
| Member | What it is |
|---|---|
static IEnumerable<ConsoleToken> All { get; } | Every named token, oldest first. |
static bool Loaded { get; private set; } | True once the file has been read, or found missing. |
static int OwnerGeneration { get; } | The owner token's generation from the file: 0 until it is first rotated. |
Methods
| Member | What it is |
|---|---|
static bool Allows(string id, CommandPart part) | The gate: may this named token see and run this command or module? A module passes when a granted command is inside it. |
static bool EnsureLoaded() | True once the file has been read. Retries a failed read at most every 5 seconds. |
static ConsoleToken Find(string id) | The named token with this id, or null. |
static void Load() | Reads the file. A missing one means no tokens yet; an unreadable one leaves every console token refused, the owner's too. |
static bool NeverGranted(string path) | True for repeat, token and anything under them, which can't be given to a named token. |
static string NormalizePath(string path) | A path in lower case with single spaces and no outer spaces. |
static string PathOf(CommandPart part) | The typed path of a command or module, such as player progression list, without parameters. |
static void Touch(string id) | Records now as the token's last use. Logs a warning if the file can't be written. |
static void Update(Func<ConsoleTokenList, bool> change) | Reads the file, applies a change and writes it back under its lock. The copy is rebuilt when the change returns true. |
3 private and internal methods
| Member | What it is |
|---|---|
private static IEnumerable<string> Ancestors(string path) (iterator) | Yields each shorter parent path of a command path, longest first. |
private static bool Granted(HashSet<string> granted, string path) | Returns whether a path, or any parent path of it, is in the granted set. |
private static void Rebuild(ConsoleTokenList list) | Replaces the in-memory token copy and owner generation from a token list and marks the store loaded. |