Skip to content

NativePermissionTable

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

public static class NativePermissionTable

Feeds the engine’s permission table (docs/agents/permissions.md): declares node defaults, sets and changes the rules of a player, claims the table, and reads its statistics. The engine validates every message as a whole; a refused message changes nothing (the status is the host call’s: 0 applied, -1 malformed, -2 oversize, -3 refused, -4 version gap, -5 unknown kind). While a claim is held the engine answers the permission requirements of commands from the table; the rules describe a player’s permissions, and a player whose rules were never sent gets the defaults.

Member Description
const byte Any = 255 The wildcard of a context position.
const int MaxMessageBytes = 262144 The largest message the engine accepts.
const int MaxRulesPerMessage = 512 Rules in one message (a larger subject is sent with delta messages).
public const byte Any = 255;

The wildcard of a context position.

public const int MaxMessageBytes = 262144;

The largest message the engine accepts.

public const int MaxRulesPerMessage = 512;

Rules in one message (a larger subject is sent with delta messages).

Member Description
static int Apply(byte[] message) Applies a message built by one of the functions below.
static byte[] BeginSnapshot() Starts a full resynchronisation (after a worker start): every subject sent before NativePermissionTable.EndSnapshot is kept, the others are dropped at the end.
static bool Claim(bool on) Claims (true) or releases (false) the table.
static bool Declare(Permission permission) Declares a node’s defaults for its five operator levels (what the node answers for a subject without a rule).
DeltaSubject Upserts or removes rules of a subject whose version is baseVersion; the engine refuses a delta on any other version (-4) and then the subject needs {{cref:M:Mc.Scripting.Permissions.NativePermissionTable.SetSubject(Mc.Scripting.Uuid,System.UInt32,System.Byte,System.Byte,System.Collections.Generic.IReadOnlyList{Mc.Scripting.Permissions.NativeRule})}}.
static byte[] DropSubject(Uuid subject) Drops a subject’s state (a player who left; the engine frees it).
static byte[] EndSnapshot() Ends a full resynchronisation (see NativePermissionTable.BeginSnapshot).
static byte[] SetSlots(Uuid subject, byte slot0, byte slot1) Sets a subject’s plugin context slot values without touching its rules.
SetSubject Replaces every rule of a subject (at most NativePermissionTable.MaxRulesPerMessage of them).
static NativeTableStats? Stats() The table’s counters (the engine’s perm_stats).
static bool WriteBuiltin(string json) Writes the built-in backend’s file (permissions.json) through the engine: the worker’s own sandbox refuses the write.
public static int Apply(byte[] message)

Applies a message built by one of the functions below.

Parameters

Name Type Description
message byte[] The message.

Returns int: 0 when applied, else a negative status (see the type’s remarks).

public static byte[] BeginSnapshot()

Starts a full resynchronisation (after a worker start): every subject sent before NativePermissionTable.EndSnapshot is kept, the others are dropped at the end. Until then the last state keeps answering.

Returns byte[]: The message.

public static bool Claim(bool on)

Claims (true) or releases (false) the table. Releasing returns command requirements to the built-in backend.

Parameters

Name Type Description
on bool

Returns bool: True when the engine accepted the change.

public static bool Declare(Permission permission)

Declares a node’s defaults for its five operator levels (what the node answers for a subject without a rule). Called by the server for every registered permission node; a plugin does not need it for nodes it registers through PermissionManager.Register.

Parameters

Name Type Description
permission Permission The node.

Returns bool: True when the engine has the node.

public static byte[] DeltaSubject(Uuid subject, uint baseVersion, uint version, IReadOnlyList<ValueTuple<bool, NativeRule>> changes)

Upserts or removes rules of a subject whose version is baseVersion; the engine refuses a delta on any other version (-4) and then the subject needs {{cref:M:Mc.Scripting.Permissions.NativePermissionTable.SetSubject(Mc.Scripting.Uuid,System.UInt32,System.Byte,System.Byte,System.Collections.Generic.IReadOnlyList{Mc.Scripting.Permissions.NativeRule})}}.

Parameters

Name Type Description
subject Uuid The player’s profile id.
baseVersion uint The version the subject has now.
version uint The version after this message.
changes IReadOnlyList<ValueTuple<bool, NativeRule>> Upserts (true: replaces the rule with the same node, layer and context, or adds it) and removals (false: the rule with the same node, layer and context is removed).

Returns byte[]: The message.

public static byte[] DropSubject(Uuid subject)

Drops a subject’s state (a player who left; the engine frees it).

Parameters

Name Type Description
subject Uuid The player’s profile id.

Returns byte[]: The message.

public static byte[] EndSnapshot()

Ends a full resynchronisation (see NativePermissionTable.BeginSnapshot).

Returns byte[]: The message.

public static byte[] SetSlots(Uuid subject, byte slot0, byte slot1)

Sets a subject’s plugin context slot values without touching its rules.

Parameters

Name Type Description
subject Uuid The player’s profile id.
slot0 byte The first slot value.
slot1 byte The second slot value.

Returns byte[]: The message.

public static byte[] SetSubject(Uuid subject, uint version, byte slot0, byte slot1, IReadOnlyList<NativeRule> rules)

Replaces every rule of a subject (at most NativePermissionTable.MaxRulesPerMessage of them).

Parameters

Name Type Description
subject Uuid The player’s profile id.
version uint The subject’s version after this message; a delta must name it as its base.
slot0 byte The value of the first plugin context slot of the subject (NativePermissionTable.Any when unknown).
slot1 byte The value of the second plugin context slot.
rules IReadOnlyList<NativeRule> The rules.

Returns byte[]: The message.

public static NativeTableStats? Stats()

The table’s counters (the engine’s perm_stats).

Returns NativeTableStats?: The values, or null when the host does not answer.

public static bool WriteBuiltin(string json)

Writes the built-in backend’s file (permissions.json) through the engine: the worker’s own sandbox refuses the write.

Parameters

Name Type Description
json string One JSON object.

Returns bool: True when the engine wrote it.

NativeRule · NativeTableStats · Permission · Uuid