NockyCZ / CS2-Discord-Utilities

Plugin for communication between your CS2 server and your Discord server
https://buymeacoffee.com/sourcefactory
43 stars 20 forks source link

Should ManageRolesAndPermissions be responsible for "remove permissions on role loss"? #42

Open NotJustin opened 1 week ago

NotJustin commented 1 week ago

This module grants discord users roles based on their in game permissions. This module also does the reverse, it grants a player in game permissions based on their discord roles.

The config has an option for "Remove role on permission loss". Should there be something for "Remove permission on role loss"?

CounterStrikeSharp's AdminManager.AddPlayerPermissions allows you to temporarily grant a user permissions. I believe the user keeps those permissions until the server restarts, or the command css_reloadadmins is used. That means the following can happen:

  1. A user uses the link command.
  2. The plugin grants the user permissions based on their discord roles.
  3. The discord role is removed, or the user uses the unlink command.
  4. The user has permissions that they should not have anymore.

Do you think this is a problem worth addressing?

One idea on how to go about it: If a user is linked, the bot can directly listen for when a role is added/removed from the user, and use the AdminManager.AddPlayerPermissions / AdminManager.RemovePlayerPermissions with the linked SteamID (I believe these commands should work even if the user is not online on the server). Also, if the user unlinks, or the linked role is removed from them on discord, the bot should do the same thing based on SteamID.

The only thing I'm uncertain about is, let's say a user has an admin role on discord, but also already has ban/unban permissions due to some other plugin, or simply existing in admins.json. If the user then loses the role on discord or unlinks, they should still technically keep those permissions, because those permissions were not originally granted by this module. How would this module know not to remove those permissions? Maybe at this point, it's the problem of the server operator to figure out, because they have two different systems granting conflicting permissions.

NockyCZ commented 6 days ago

Yea, its possible, i will try to figure it out for the next update