-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayerRolesFromGranularPermissions.cs
49 lines (42 loc) · 1.26 KB
/
PlayerRolesFromGranularPermissions.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
42
43
44
45
46
47
48
49
using BattleBitAPI.Common;
using BBRAPIModules;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Permissions;
[RequireModule(typeof(GranularPermissions))]
[Module("Provides player roles based on granular permissions", "1.0.0")]
public class PlayerRolesFromGranularPermissions : BattleBitModule
{
[ModuleReference]
public GranularPermissions GranularPermissions { get; set; } = null!;
public PlayerRolesConfiguration Configuration { get; set; } = null!;
public override Task OnPlayerJoiningToServer(ulong steamID, PlayerJoiningArguments args)
{
foreach (string permission in Configuration.PermissionRoles.Keys)
{
if (!this.GranularPermissions.HasPermission(steamID, permission))
{
continue;
}
if (Configuration.AppendRoles)
{
args.Stats.Roles |= Configuration.PermissionRoles[permission];
}
else
{
args.Stats.Roles = Configuration.PermissionRoles[permission];
}
}
return Task.CompletedTask;
}
}
public class PlayerRolesConfiguration : ModuleConfiguration
{
public Dictionary<string, Roles> PermissionRoles { get; set; } = new()
{
{ "Role.Admin", Roles.Admin },
{ "Role.Moderator", Roles.Moderator },
{ "Role.Modmin", Roles.Admin | Roles.Moderator }
};
public bool AppendRoles { get; set; } = false;
}