Amaroq7 / SPMod

SourcePawn Scripting Engine for Half-Life 1 based games
GNU General Public License v3.0
27 stars 12 forks source link

[WIP] Access manager #47

Open Mistrick opened 6 years ago

Mistrick commented 6 years ago

Description

Access manager

TODO:

Motivation and Context

How has this been tested?

#include <spmod>

public PluginInfo pluginInfo =
{
    name = "test",
    version = "0.0.0",
    author = "author",
    url = "https://github.com/Amaroq7/SPMod"
};

Group g;

public void OnPluginInit()
{
    g = Group("test");
    g.AttachPermission("one");
    g.AttachPermission("two");
    g.AttachPermission("three");

    Command("^say /p1$", TestP1);
    Command("^say /p2$", TestP2);
    Command("^say /p3$", TestP3);
    Command("^say /p4$", TestP4);
}

public PluginReturn TestP1(int client, Command cid)
{
    Player p = view_as<Player>(client);
    p.AttachGroup(g);
    p.AttachPermission("four");
}

public PluginReturn TestP2(int client, Command cid)
{
    Player p = view_as<Player>(client);
    PrintToServer("client %d, has one[%d], two[%d], three[%d], four[%d]",
                    client,
                    p.HasAccess("one"),
                    p.HasAccess("two"),
                    p.HasAccess("three"),
                    p.HasAccess("four"))
}
public PluginReturn TestP3(int client, Command cid)
{
    Player p = view_as<Player>(client);
    p.RemovePermission("four");
}
public PluginReturn TestP4(int client, Command cid)
{
    Player p = view_as<Player>(client);
    p.RemoveGroup(g);
}

Screenshots (if appropriate):

image

Types of changes

Checklist:

Amaroq7 commented 4 years ago

I like the concept of groups and single permissions this gives us much more flexibility than flags.

I have a question, is there a possibility to exclude permissions for particular players? Let's say we have 2 players which belong to the same group f.e. admin and we want one of them to have all permissions from the group except f.e. ban.

Mistrick commented 4 years ago

I have a question, is there a possibility to exclude permissions for particular players? Let's say we have 2 players which belong to the same group f.e. admin and we want one of them to have all permissions from the group except f.e. ban.

Yes, I try to do system based on sets. We can add member for exceptions and after union in PlayerRole::hasAccess add complement with exceptions.

sonarcloud[bot] commented 11 months ago

SonarCloud Quality Gate failed.    Quality Gate failed

Bug E 1 Bug
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell C 163 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint