I'm writing a plugin for a member here and it involves granting/revoking permissions from players. It's my first time working with permissions and it looked pretty simple but I have an issue I can't quite grasp.
This piece of code is the issue:
The issue I have is that when I run the code and the permission does not exist, it will register it properly. Further executions will not trigger the creation again since the permission is now found. That said, each time I restart the server, it seems the permission is unregistered (it does remain in the user profile though). Looking at the config files, I can't find a place where permissions are saved other than in the user data.Code:var exists = permission.PermissionExists(perm.Key); if (!exists) { Puts($"Created permission [{perm.Key}]."); permission.RegisterPermission(perm.Key, this); } var has = permission.UserHasPermission(player.userID.ToString(), perm.Key);
So my question is... Do I even need to register the permission or can I just randomly grant an non-existing permission and it will work? And if so.. what is the point of RegisterPermission? Is there like a save to save registered permissions?
I'm confused... Can I just ignore registration?
Permissions question
Discussion in 'Rust Development' started by Deicide666ra, Sep 10, 2015.
-
Your plugin must always registers the permissions it uses. The reason being is for when you grant user permission it knows if they exist.
-
Ummkay... but I still don't get it. Are these saved somewhere? or are you saying each time a plugin starts it needs to register all permissions it's going to use and these are volatile and only valid during it's execution span?
So basically on init I register all permissions I plan to use.. and then I can grand/revoke them... plugin unloads, the permissions are still attached to players but the registration does not exist anymore? Am I getting this right? -
Wulf Community Admin
Permissions for each plugin only exist while that plugin is loaded and has them registered. -
I see. But these permissions when granted to players do persist through executions right? If I setup the kit plugin to use permission "kitperm" and then have my other plugin register and then grant/revoke permission "kitperm" and unload the plugin.. Users that have been granted the permission will be able to use the kit, right?
Just making sure I understand the whole thing... Why is there even registration though? Why not just have grand/revoke? Not sure I see the point of registering permissions. -
Wulf Community Admin
The permissions will be in the config files, but they won't do anything without the permission being registered.
Registering a permission ties it to that plugin. If another plugin also registers it, it prints a warning. -
OK so in the scenario I explained earlier, a plugin that controls who can or cannot use this or that kit.... I should register all permissions I plan to grant/revoke from players within my plugin on start and then grant/revoke as needed (in this case I'm pulling the permission associations from a web site)... The user permissions will save/load, but the actual permissions do not... and for the /kit command to work with this or that permission, my plugin will need to be loaded, right? If my plugin is not loaded, then the permission does not exist for the kit plugin?
[DOUBLEPOST=1441915928,1441904737][/DOUBLEPOST]Bump, can I get a confirmation on my last reply? I want to finish this plugin
-
Wulf Community Admin
The plugin has to be loaded for the permission to work as far as I know. -
Confirmed I just tested it... Thanks Wulf.
I'm still curious as to why you guys even have registration though. Is it just to pop that warning if two plugins try to use two permissions with the same name? IMHO grand/revoke/check would be enough
-
Wulf Community Admin
Without a permission being registered, there's nothing to stop users from using wrong, typoed, or otherwise non-existant permissions. I'm sure there are other reasons though, but that one alone is a good reason for me.
