An abstract and shared permission framework
Sandmod provides all kinds of frameworks for developers.
This way we can all have a shared experience where addon incompatibility is no issue anymore.
Sandmod Permission is an abstract permission framework based on providers and components.
You have the freedom to choose how you want to provide and check the permission.
Here are some possible and funky examples how you could provide permissions:
- Retrieved from a database
- Based on ranks / groups / roles
- Based on inventory items
- Based on play time
- Based on suicide count
- Probably anything...
The library is split into 2 parts.
- Providing permissions and permission check logic
- Checking permissions
The permission checking part is probably the most used one as this is the main point of the library.
If you are not sure how permissions are defined or you want get everything out of your permissions, check out the Permission definition section.
If you want to check if a client is allowed to do something, you just want to know if they do or not (a simple true / false).
You probably don't care about how it's defined that the client is allowed to, because others should take care of it.
For this case, all you need to do is use the bool IClient.HasPermission(string permission)
or bool IClient.HasPermission(string permission, IPermissionTarget target)
method.
This is the more technical and complex part of the library, but you only need it if you actually want to provide permissions yourself.
The main component are the IPermissionProvider and the IPermissionComponent.
The IPermissionProvider is used to provided the IPermissionComponents to the client.
Check out the DefaultPermissionProvider for an basic example.
The IPermissionComponent represents partial permissions of a client.
It's partial because a client can have multiple components on them and they are all taken into account when checking if the client has a specific permission.
The IPermissionComponent is easily implementable and allows you to create your own logic for providing and checking your own permissions.
The permissions inside the IPermissionComponent should be replicated to allow permission checks on the client side.
Check out the DefaultPermissionComponent for an basic example.
Permissions are mostly defined as lowercase string in a .
notation.
This allows for grouping of the permission sections.
Example permission | Included permissions |
---|---|
example |
example |
example.permission |
example example.permission |
example.permission.other |
example example.permission example.permission.other |
In general it's recommended to start permissions with a unique name, to prevent permission conflicts with other addons (e.g. addon.example.permission
).
By grouping permissions it's important to group them properly else unwanted behaviour might happen with wildcards.
Here is a bad example:
Permissions of the client | Checked permissions | Allowed permissions |
---|---|---|
kick.* |
kick.client1 kick.client2 kick.bot1 |
kick.client1 kick.client2 kick.bot1 |
The above example doesn't allow you to have separate wildcards for the permissions for the clients and bots.
If you wanted to do this properly, you can do it like this:
Permissions of the client | Checked permissions | Allowed permissions |
---|---|---|
kick.client.* |
kick.client.client1 kick.client.client2 kick.bot.bot1 |
kick.client.client1 kick.client.client2 |
kick.bot.* |
kick.client.client1 kick.client.client2 kick.bot.bot1 |
kick.bot.bot1 |
kick.* |
kick.client.client1 kick.client.client2 kick.bot.bot1 |
kick.client.client1 kick.client.client2 kick.bot.bot1 |
To add this library to your s&box editor, simply clone the Sandmod Permission project from asset.party.
Check out the DefaultPermissionProvider for an basic example.
Check out the DefaultPermissionComponent for an basic example.
Maybe a permission template registry will be added to allow permission configuration tools to list used permissions with their parameters.
If you think something is missing or can be optimized feel free to create an issue or pull request.