Ulysses

General => Developers Corner => Topic started by: gorgorp on August 08, 2009, 03:55:20 AM

Title: ulx rank reading
Post by: gorgorp on August 08, 2009, 03:55:20 AM
how do i with lua read what rank a user has like

if ply:HasPriv("superadmin")
or what ever you can
Title: Re: ulx rank reading
Post by: gorgorp on August 08, 2009, 08:20:16 AM
could someone please help me
Title: Re: ulx rank reading
Post by: gorgorp on August 08, 2009, 08:28:41 AM
nvm i figured out
Title: Re: ulx rank reading
Post by: Megiddo on August 08, 2009, 10:43:59 AM
In ULib, is player:GetGroups(). I'm not aware of any default gmod implementation to do the same thing.
Title: Re: ulx rank reading
Post by: JamminR on August 08, 2009, 08:38:04 PM
Megiddo, though ULib has enhanced functionality, I'm pretty sure he probably found IsAdmin, IsSuperadmin, and IsUserGroup from the standard Gmod lua.
Title: Re: ulx rank reading
Post by: jay209015 on August 09, 2009, 12:24:19 PM
I use this to get a players group:
Code: [Select]
function URestrict.GetUserGroup( ply )
for k, v in pairs( ULib.ucl.authed[ ply ].groups ) do
if v ~= ULib.ACCESS_ALL then
return v
else
return "user"
end
end
end
Title: Re: ulx rank reading
Post by: JamminR on August 09, 2009, 12:37:57 PM
Jay, I've often wondered, and Megiddo may have more insight, would that return the 'highest' level of access that the person has? If they were a custom group such as Elite, that inherited Respected, which inheritied Member below it - would doing it that way always return 'Elite?

Which leads to another question regarding optimization;
Rather than going through a for loop of the .groups - would it be possible to just return ULib.ucl.authed[ ply ].groups[ <1?> ] ??
Would 1 always be the "highest" rank, and if so, wouldn't a table lookup like that be quicker than the for loop?
Title: Re: ulx rank reading
Post by: Megiddo on August 09, 2009, 01:03:33 PM
Looks like he's just returning the first value he comes across. You wouldn't want to return the group at index 1 because I think depending on how the file is setup, it may or may not be the number 1 and may instead be the string "1". I think that was fixed when we made our own file parser instead of using garry's, but I'm not sure.
Title: Re: ulx rank reading
Post by: JamminR on August 09, 2009, 05:59:03 PM
So in essence, Jay's way of grabbing the 'highest' rank isn't guaranteed?

Though I know Player:query could be used to test for a specific command access, if I wanted to write a script (or in my case, already have an unfinished one not worked on in year(s)) that returned the highest group at the top of the inheritance chain as listed in example above.... is there a ULib command to do it?
If not directly, how would you check?

This was a challenge I was having with UMotd returning the 'high' group of any non-standard groups.
Elite/Respected/Member/Minge etc.
Title: Re: ulx rank reading
Post by: Megiddo on August 09, 2009, 06:08:05 PM
There is no easy way, you'd have to traverse the ULib.ucl table to figure it out. Sorry. :P

I'm thinking of recoding UCL though (as I've had it on my todo list since nearly the beginning of time), so this would definitely be something I'd improve.
Title: Re: ulx rank reading
Post by: jay209015 on August 09, 2009, 08:16:25 PM
Wouldn't the easiest way of determing a users actual highest rank be the rank that has the highest amount of allows, including inheritance?
Title: Re: ulx rank reading
Post by: JamminR on August 09, 2009, 08:36:32 PM
Many cases, yes, but not always.
Theoretically, as soon as we tried to depend on that method, some ULX user would have his so tweaked, he'd be granting "Elite" (using my previous examples) access to 'Respected', then denying them something because they were considered a different team or something.
Though a reasonable suggestion, it's just not foolproof that I can think of.
Title: Re: ulx rank reading
Post by: gorgorp on August 10, 2009, 01:52:56 AM
well as i said before i figured it out

function GetGroupUser( ply )
   for k, v in pairs( ULib.ucl.authed[ ply ].groups ) do
      if v ~= ULib.ACCESS_ALL then
         return v
      else
         return "user"
      end   
   end
end
Title: Re: ulx rank reading
Post by: JamminR on August 10, 2009, 02:54:52 PM
gorgorp, problem is, that I've been asking about;
That method isn't 100% guaranteed to return the 'highest' rank of a ULib group chain.
Might most of the time, but no guarantees.