-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayerPermissions.cs
92 lines (78 loc) · 2.37 KB
/
PlayerPermissions.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using BattleBitAPI.Common;
using BBRAPIModules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Permissions;
[Module("Library for persistent server roles for players", "1.0.0")]
public class PlayerPermissions : BattleBitModule
{
public static PlayerPermissionsConfiguration Configuration { get; set; }
public override Task OnPlayerJoiningToServer(ulong steamID, PlayerJoiningArguments args)
{
if (Configuration.OverrideRoles)
{
args.Stats.Roles = this.GetPlayerRoles(steamID);
}
else
{
args.Stats.Roles |= this.GetPlayerRoles(steamID);
}
return Task.CompletedTask;
}
public override Task OnPlayerConnected(RunnerPlayer player)
{
lock (Configuration.PlayerRoles)
{
if (!Configuration.PlayerRoles.ContainsKey(player.SteamID))
{
Configuration.PlayerRoles.Add(player.SteamID, Roles.None);
}
}
return Task.CompletedTask;
}
public bool HasPlayerRole(ulong steamID, Roles role)
{
return (this.GetPlayerRoles(steamID) & role) == role;
}
public Roles GetPlayerRoles(ulong steamID)
{
lock (Configuration.PlayerRoles)
{
if (Configuration.PlayerRoles.ContainsKey(steamID))
{
return Configuration.PlayerRoles[steamID];
}
}
return Roles.None;
}
public void SetPlayerRoles(ulong steamID, Roles roles)
{
lock (Configuration.PlayerRoles)
{
if (Configuration.PlayerRoles.ContainsKey(steamID))
{
Configuration.PlayerRoles[steamID] = roles;
}
else
{
Configuration.PlayerRoles.Add(steamID, roles);
}
}
Configuration.Save();
}
public void AddPlayerRoles(ulong steamID, Roles role)
{
this.SetPlayerRoles(steamID, this.GetPlayerRoles(steamID) | role);
}
public void RemovePlayerRoles(ulong steamID, Roles role)
{
this.SetPlayerRoles(steamID, this.GetPlayerRoles(steamID) & ~role);
}
}
public class PlayerPermissionsConfiguration : ModuleConfiguration
{
public bool OverrideRoles { get; set; } = true;
public Dictionary<ulong, Roles> PlayerRoles { get; set; } = new();
}