Struct PermissionBranch
- Namespace
- Uncreated.Warfare.Players.Permissions
- Assembly
- Uncreated.Warfare.dll
Represents a relative permission with wildcards and additive/subtractive metadata.
[JsonConverter(typeof(PermissionBranchJsonConverter))]
public readonly struct PermissionBranch : IEquatable<PermissionBranch>, IEquatable<PermissionLeaf>, ITranslationArgument
- Implements
- Inherited Members
- Extension Methods
Remarks
Stolen from DevkitServer.
Constructors
PermissionBranch(string)
Parse a permission branch with a prefix.
public PermissionBranch(string path)
Parameters
pathstring
Exceptions
- FormatException
Parse failure.
Fields
Superuser
Additive superuser branch. Unlocks all permissions.
public static readonly PermissionBranch Superuser
Field Value
SuperuserSubtractive
Removes a superuser permission branch which would've unlocked all permissions. Doesn't necessarily remove all permissions.
public static readonly PermissionBranch SuperuserSubtractive
Field Value
Properties
IsAbsolute
If this branch doesn't contain a wildcard.
public bool IsAbsolute { get; }
Property Value
IsSuperuser
Is this the superuser permission (unlocks all permissions).
public bool IsSuperuser { get; }
Property Value
Mode
How this branch affects existing permissions. Additive gives the permission, subtractive removes it.
public PermissionMode Mode { get; }
Property Value
Path
The path relative to the branch's domain. The domain is the permission prefix of the permission owner.
public string Path { get; }
Property Value
Remarks
Example: request.*.
Unturned
Is this permission relating to the base game?
public bool Unturned { get; }
Property Value
Valid
Is this permission valid (has a path and a source definition)?
public bool Valid { get; }
Property Value
Warfare
Is this permission relating to Uncreated Warfare?
public bool Warfare { get; }
Property Value
WildcardLevel
Permission depth level (number of periods plus one) where the wildcard is at, or zero for absolute permissions.
public int WildcardLevel { get; }
Property Value
Remarks
Example: warfare::request.* would be 2.
Methods
Contains(PermissionBranch)
If branch (and any leaves it contains) would be included in this branch.
public bool Contains(PermissionBranch branch)
Parameters
branchPermissionBranch
Returns
Remarks
Does not check Mode.
Contains(PermissionLeaf)
If leaf would be included in this branch.
public bool Contains(PermissionLeaf leaf)
Parameters
leafPermissionLeaf
Returns
Remarks
Does not check Mode.
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
Equals(PermissionBranch)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(PermissionBranch branch)
Parameters
branchPermissionBranch
Returns
Equals(PermissionLeaf)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(PermissionLeaf leaf)
Parameters
leafPermissionLeaf
Returns
EqualsWithoutMode(PermissionBranch)
public bool EqualsWithoutMode(PermissionBranch branch)
Parameters
branchPermissionBranch
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
GetPrefix()
Get the permission prefix.
public string GetPrefix()
Returns
Remarks
Looks like this when placed in a full permission branch: warfare::request.*.
GetWildcardLevel(string)
Get the wildcard level in a path. Example: warfare::request.* would return 2. If there's no wildcard zero is returned.
public static int GetWildcardLevel(string path)
Parameters
pathstring
Returns
Remarks
Can optionally have a prefix.
Parse(string)
Parse a permission branch with a prefix.
public static PermissionBranch Parse(string path)
Parameters
pathstring
Returns
Exceptions
- FormatException
Parse failure.
Read(ByteReader)
public static PermissionBranch Read(ByteReader reader)
Parameters
readerByteReader
Returns
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
Translate(ITranslationValueFormatter, in ValueFormatParameters)
Allows objects to define how they're translated in their own definition instead of creating a value converter.
public string Translate(ITranslationValueFormatter formatter, in ValueFormatParameters parameters)
Parameters
formatterITranslationValueFormatterparametersValueFormatParameters
Returns
TryParse(string, out PermissionBranch)
Parse a permission branch with a prefix.
public static bool TryParse(string path, out PermissionBranch permissionBranch)
Parameters
pathstringpermissionBranchPermissionBranch
Returns
Write(ByteWriter, PermissionBranch)
public static void Write(ByteWriter writer, PermissionBranch branch)
Parameters
writerByteWriterbranchPermissionBranch
Operators
operator ==(PermissionBranch, PermissionBranch)
public static bool operator ==(PermissionBranch left, PermissionBranch right)
Parameters
leftPermissionBranchrightPermissionBranch
Returns
explicit operator PermissionLeaf(PermissionBranch)
public static explicit operator PermissionLeaf(PermissionBranch branch)
Parameters
branchPermissionBranch
Returns
operator !=(PermissionBranch, PermissionBranch)
public static bool operator !=(PermissionBranch left, PermissionBranch right)
Parameters
leftPermissionBranchrightPermissionBranch