-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDefaultPermissionComponent.cs
41 lines (35 loc) · 1.25 KB
/
DefaultPermissionComponent.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Collections.Generic;
using Sandbox;
using Sandmod.Permission.Target;
namespace Sandmod.Permission;
/// <summary>
/// Default implementation of the <see cref="IPermissionComponent" />.<br />
/// See <see cref="IPermissionComponent" /> for more information:
/// <br /><br />
/// <inheritdoc cref="IPermissionComponent" />
/// </summary>
internal sealed partial class DefaultPermissionComponent : EntityComponent, IPermissionComponent
{
public DefaultPermissionComponent()
{
}
public DefaultPermissionComponent(IReadOnlyCollection<string> permissions)
{
Permissions = new List<string>(permissions);
}
/// <summary>
/// Default property for <see cref="IClient" />'s permissions.<br />
/// It's networked to allow for replication on the client for e.g. UI checks.
/// </summary>
[Net]
[Local]
private List<string> Permissions { get; set; } = new();
public Permission.Result CheckPermission(string permission)
{
return Permission.Grants(Permissions.AsReadOnly(), permission).ToResult();
}
public Permission.Result CheckPermission(string permission, IPermissionTarget target)
{
return CheckPermission(permission + Permission.Separator + target.PermissionString);
}
}