Skip to content

FilePermissionProvider

Namespace Mc.Scripting.Permissions · Kind class (sealed)

public sealed class FilePermissionProvider : IPermissionProvider

The built-in backend: groups (weighted, inheriting, with prefix and suffix) and per-player overrides, stored in permissions.json. Resolution order: the player’s own entries, then his groups by weight (highest first, parents after their child), then the implicit “default” group everybody belongs to. Within one layer the most specific node wins: an exact entry beats a.b.*, a longer wildcard beats a shorter one, * comes last; a false value is a denial. A key written as "-node" in the file means the same as "node": false.

Member Description
FilePermissionProvider(string path) Opens (and creates, when missing) the permission file.
public FilePermissionProvider(string path)

Opens (and creates, when missing) the permission file. A file that cannot be read (malformed JSON) does not stop the server: the provider starts empty (the registered defaults apply), logs the problem once and leaves the file alone so that it can be fixed and reloaded with FilePermissionProvider.Reload.

Parameters

Name Type Description
path string The file path.
Member Description
IReadOnlyList<string> GroupNames { get; } The group names.
string? LoadError { get; } Why the file could not be read (null when it was, or since it was fixed and reloaded).
string Name { get; }
public IReadOnlyList<string> GroupNames { get; }

The group names.

public string? LoadError { get; }

Why the file could not be read (null when it was, or since it was fixed and reloaded).

public string Name { get; }
Member Description
void AddToGroup(Uuid player, string group, string? name = null) Adds the player to a group.
void CreateGroup(string name, int weight = 0) Creates a group (no-op when it exists).
bool DeleteGroup(string name) Deletes a group and removes it from every player and parent list.
PermissionValue Get(Uuid player, string node)
string GetPrefix(Uuid player) The prefix of the player’s highest-weight group that has one (empty if none).
string GetSuffix(Uuid player) The suffix of the player’s highest-weight group that has one (empty if none).
IReadOnlyDictionary<string, bool> GroupEntries(string group) The explicit entries of a group, for admin tools.
IReadOnlyCollection<string> Groups(Uuid player)
IReadOnlyDictionary<string, bool> PlayerEntries(Uuid player) The explicit entries of a player (without groups), for admin tools.
void Reload() Re-reads the file (a missing file is created with a “default” and an “admin” group).
bool RemoveFromGroup(Uuid player, string group) Removes the player from a group.
void Save() Writes the file if something changed.
void SetGroupMeta(string group, string prefix, string suffix) Sets prefix and suffix text of a group (metadata for chat plugins).
void SetGroupParents(string group, IEnumerable<string> parents) Sets the groups a group inherits from.
void SetGroupPermission(string group, string node, bool? value) Sets (true/false) or removes (null) a permission entry of a group.
void SetPlayerPermission(Uuid player, string node, bool? value, string? name = null) Sets (true/false) or removes (null) a permission entry of a player.
public void AddToGroup(Uuid player, string group, string? name = null)

Adds the player to a group.

Parameters

Name Type Description
player Uuid The player’s profile id.
group string The group (must exist).
name string? = null The player’s name, stored for readability of the file.
public void CreateGroup(string name, int weight = 0)

Creates a group (no-op when it exists).

Parameters

Name Type Description
name string The group name.
weight int = 0 Higher weights win over lower ones when groups disagree.
public bool DeleteGroup(string name)

Deletes a group and removes it from every player and parent list.

Parameters

Name Type Description
name string The group name (“default” cannot be deleted).

Returns bool: Whether the group existed.

public PermissionValue Get(Uuid player, string node)

Parameters

Name Type Description
player Uuid
node string

Returns PermissionValue

public string GetPrefix(Uuid player)

The prefix of the player’s highest-weight group that has one (empty if none).

Parameters

Name Type Description
player Uuid The player.

Returns string: The prefix text.

public string GetSuffix(Uuid player)

The suffix of the player’s highest-weight group that has one (empty if none).

Parameters

Name Type Description
player Uuid The player.

Returns string: The suffix text.

public IReadOnlyDictionary<string, bool> GroupEntries(string group)

The explicit entries of a group, for admin tools.

Parameters

Name Type Description
group string The group.

Returns IReadOnlyDictionary<string, bool>: A snapshot of node -> value (empty for an unknown group).

public IReadOnlyCollection<string> Groups(Uuid player)

Parameters

Name Type Description
player Uuid

Returns IReadOnlyCollection<string>

public IReadOnlyDictionary<string, bool> PlayerEntries(Uuid player)

The explicit entries of a player (without groups), for admin tools.

Parameters

Name Type Description
player Uuid The player.

Returns IReadOnlyDictionary<string, bool>: A snapshot of node -> value.

public void Reload()

Re-reads the file (a missing file is created with a “default” and an “admin” group).

Throws

  • System.IO.InvalidDataException: The file is not valid JSON; the permissions in memory stay as they were.
public bool RemoveFromGroup(Uuid player, string group)

Removes the player from a group.

Parameters

Name Type Description
player Uuid The player’s profile id.
group string The group.

Returns bool: Whether he was a member.

public void Save()

Writes the file if something changed. The engine writes it (a host call: the worker’s sandbox refuses writes to the server folder), atomically (temp file, flushed, then renamed over the old one). The engine refuses a write that comes too soon after the last one (its rate limit): then the changes stay pending and the next call (the runtime’s flush, a second later) tries again. Never throws; a refusal is logged once per streak.

public void SetGroupMeta(string group, string prefix, string suffix)

Sets prefix and suffix text of a group (metadata for chat plugins).

Parameters

Name Type Description
group string The group.
prefix string The prefix.
suffix string The suffix.
public void SetGroupParents(string group, IEnumerable<string> parents)

Sets the groups a group inherits from.

Parameters

Name Type Description
group string The group.
parents IEnumerable<string> The parent groups (cycles are ignored when evaluating).
public void SetGroupPermission(string group, string node, bool? value)

Sets (true/false) or removes (null) a permission entry of a group.

Parameters

Name Type Description
group string The group.
node string The node (wildcards allowed).
value bool? The value, or null to remove the entry.
public void SetPlayerPermission(Uuid player, string node, bool? value, string? name = null)

Sets (true/false) or removes (null) a permission entry of a player.

Parameters

Name Type Description
player Uuid The player’s profile id.
node string The node (wildcards allowed).
value bool? The value, or null to remove the entry.
name string? = null The player’s name, stored for readability of the file.
Member Description
event Action<Uuid?>? Changed
public event Action<Uuid?>? Changed;

Returns Action<Uuid?>?

IPermissionProvider · PermissionValue · Uuid