mirror of
https://github.com/Jetsparrow/jetherald.git
synced 2026-01-20 23:56:08 +03:00
29 lines
939 B
C#
29 lines
939 B
C#
namespace JetHerald.Authorization;
|
|
public static class PermissionParser
|
|
{
|
|
public static bool ProvePermission(string permissions, string required)
|
|
=> permissions.Split(";").Any(p => MatchPermission(p, required));
|
|
|
|
// TODO check, test and redo
|
|
static bool MatchPermission(string match, string required)
|
|
{
|
|
string[] matchwords = match.Split('.');
|
|
string[] reqwords = required.Split('.');
|
|
|
|
if (reqwords.Length < matchwords.Length)
|
|
return false;
|
|
|
|
int matchindex = 0, reqindex = 0;
|
|
|
|
while (matchindex < matchwords.Length)
|
|
{
|
|
if (matchwords[matchindex] == "**") reqindex = reqwords.Length - (matchwords.Length - matchindex);
|
|
else if (matchwords[matchindex] != reqwords[reqindex] && matchwords[matchindex] != "*") return false;
|
|
matchindex++;
|
|
reqindex++;
|
|
}
|
|
|
|
return reqindex == reqwords.Length;
|
|
}
|
|
}
|