• Print

Author Topic: Table of perms  (Read 7839 times)

0 Members and 1 Guest are viewing this topic.

Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Table of perms
« on: May 24, 2016, 07:45:29 pm »
Is there a way to create a table of the permissions of an entire ulx group that will update automatically?


Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Re: Table of perms
« Reply #2 on: May 24, 2016, 08:42:38 pm »
I have a script that changes your user group to user and gives you the permissions you had based on your rank because I made a few tables of all the permissions. Is there any way I can call a table of the  permissions a group has, to assign to an individual player without creating an entirely new which inherits from the group they were in?

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Table of perms
« Reply #3 on: May 25, 2016, 09:32:32 am »
I have a script that changes your user group to user and gives you the permissions you had based on your rank because I made a few tables of all the permissions. Is there any way I can call a table of the  permissions a group has, to assign to an individual player without creating an entirely new which inherits from the group they were in?

The only thing I can ask is why?

You're completely undermining the entire point of the permission system. The whole point of groups is so you don't have to assign permissions to people individually, and can instead assign them to groups.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Re: Table of perms
« Reply #4 on: May 25, 2016, 01:17:34 pm »
I made an undercover addon and I want it to be able to give permissions to players when they use it. I know the perms are saved in data/ulib/groups.txt, but I was wondering if I could somehow give that table of permissions to a player. How I have it now is I have a table of perms for a specific server, but this won't be helpful on any other server.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Table of perms
« Reply #5 on: May 25, 2016, 03:30:29 pm »
As stated in previously linked post, all live information is stored in ULib.ucl, including players with special access, groups, the commands those players and groups has, and tons of other stuff. Groups.txt and users.txt are actually files from that table.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Re: Table of perms
« Reply #6 on: May 26, 2016, 03:47:44 am »
So would there be a way to either include the file or read it? Does file.read work similarly to include so I could use the information from that file?

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Table of perms
« Reply #7 on: May 26, 2016, 05:06:22 am »
So would there be a way to either include the file or read it? Does file.read work similarly to include so I could use the information from that file?

Are you reading JamminR's posts?

From the topic he linked:

All information about groups is stored in ULib.ucl.groups.

Code: Lua
  1. print(ULib.ucl.groups["admin"].inherit_from)

ULib.ucl.groups is exactly what you want, it is a table of all the groups' permissions.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Re: Table of perms
« Reply #8 on: May 26, 2016, 09:34:46 am »
-snip-

How would I allow permissions from all the groups below them? So far I have

Code: Lua
  1. ULib.ucl.userAllow(id, ULib.ucl.groups[rank].allow)
  2. ULib.ucl.userAllow(id, ULib.ucl.groups[ULib.ucl.groups[rank].inherit_from].allow)
  3.  

but that only gives permissions from the same rank and the rank below it.
« Last Edit: May 26, 2016, 12:43:47 pm by dankpepe »

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Table of perms
« Reply #9 on: May 27, 2016, 04:52:19 am »
How would I allow permissions from all the groups below them? So far I have

Code: Lua
  1. ULib.ucl.userAllow(id, ULib.ucl.groups[rank].allow)
  2. ULib.ucl.userAllow(id, ULib.ucl.groups[ULib.ucl.groups[rank].inherit_from].allow)
  3.  

but that only gives permissions from the same rank and the rank below it.

You'll want to use a loop, storing the previous rank's group table in a variable outside the loop. Just keep retrieving the group that it inherits from and setting your variable to said parent group each time. Stop when you reach a rank that doesn't have a parent (inherit_from is nil or a blank string)
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Re: Table of perms
« Reply #10 on: May 27, 2016, 12:51:03 pm »
Okay, what I did is I used this code:

Code: Lua
  1.  repeat
  2.         ULib.ucl.userAllow(id, ULib.ucl.groups[rank].allow,false)
  3.         rank = ULib.ucl.groups[rank].inherit_from
  4. until rank == "user"
  5.  

I want all the permissions granted to the player to be revoked from special access afterwards. For that, I have:

Code: Lua
  1. repeat
  2.         ULib.ucl.userAllow(id, ULib.ucl.groups[revoke_rank].allow,true)
  3.         revoke_rank = ULib.ucl.groups[revoke_rank].inherit_from
  4. until rank == "user"
  5.  

where both rank and revoke_rank are the rank of the user before they get set to user. However, the second part doesn't actually revoke the perms. Do you know how I could do this?

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Table of perms
« Reply #11 on: May 27, 2016, 08:18:35 pm »
-code-

Can you show us the entire file? Right now it isn't clear what happens to the rank and revoke_rank variables before and after your code snippets.

My guess is that you're trying to set revoke_rank in the first function and use it in the second function, and that's messing up somehow. I'll be able to better diagnose the issue once you post the full code.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline dankpepe

  • Jr. Member
  • **
  • Posts: 51
  • Karma: 1
Re: Table of perms
« Reply #12 on: May 27, 2016, 08:41:45 pm »
-snip-
« Last Edit: May 28, 2016, 10:06:05 pm by dankpepe »

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Table of perms
« Reply #13 on: May 28, 2016, 05:12:59 am »
Okay, so here you're having a problem with scope. In your code you have a variable set, revoke_rank. This variable is only set if the command is not revoking, so attempting to access it in the 'else' part of the loop is not going to work. If you were hoping that the variable would persist after the function has been called, that is not the case. You are going to need to find some other way than variables to store the users starting rank.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

  • Print