Author Topic: Custom ULX AddTrustie code  (Read 5160 times)

0 Members and 1 Guest are viewing this topic.

Offline cold12141

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Custom ULX AddTrustie code
« on: May 10, 2007, 02:36:46 PM »
The console error that was being received was something about the table.

Also, what is wrong with this code:
Code: [Select]
function ulx.cc_addtrustie( ply, command, argv, args )
if #argv < 1 then
if #argv ~= 0 then
ULib.tsay( ply, ulx.LOW_ARGS )
else
ULib.console( ply, "ulx addtrustie <user>" )
end
return
end

local target, err = ULib.getUser( argv[ 1 ], _, ply )
if not target then
ULib.tsay( ply, err )
return
end

if target:IsUserGroup( ULib.ACCESS_SUPERADMIN ) and ply:IsValid() and not ply:IsListenServerHost() then
ULib.tsay( ply, "Sorry, for security reasons, you can't change the access of a superadmin!" )
return
end

local info = ULib.ucl.authed[ target ]
if not info then
ULib.ucl.addUser( target:Nick(), "steamid", target:SteamID(), "trusted", {allow={}, deny={}} , _, _, true )
else
ULib.ucl.addUser( info.account, info.type, info.id, "trusted", {allow={}, deny={}} , _, _, true )
end
end
ulx.concommand( "addtrustie", ulx.cc_addtrustie, "<user>", ULib.ACCESS_MEMBER, _, _, ulx.ID_PLAYER_HELP )
« Last Edit: May 10, 2007, 02:40:40 PM by cold12141 »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8027
  • Karma: 381
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Custom ULX AddTrustie code
« Reply #1 on: May 10, 2007, 03:52:30 PM »
Cold, hope you don't mind, moved your post to Developers corner and started a new topic with it.
Some day I intend to make a sticky somewhere and point to various bits of code people here have done, and separating this from the 'preventing users from building by group' post seems logical.

Also, if you haven't already, may I suggest making this a custom file in your gmod/addons/ulib/lua/ULib/modules
That way when ULX/Ulib is updated, your code won't get overwritten.

I'm looking over the code now, will edit my post if I see any mistakes.
In the meantime, what error are you getting, if any?
« Last Edit: May 10, 2007, 03:57:44 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8027
  • Karma: 381
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Custom ULX AddTrustie code
« Reply #2 on: May 10, 2007, 04:15:31 PM »
Ok, Think I found a major problem to your code.
The ULib.ucl.addUser requires you to add people to a 'group' as a table.
You're passing it a string "trusted"

1) I strongly recommend keeping our immunity code in there. It will allow you to make a trusted user immune later if you wish.
2) Don't forget to re-add the logging code. Any access level changes should be logged, custom or not. Just good security of any access in life. :)

This should fix your problem (I left out the immunity for now, but still, I recommend it)
Code: [Select]
local groups = { "trusted" }

local info = ULib.ucl.authed[ target ]
if not info then
ULib.ucl.addUser( target:Nick(), "steamid", target:SteamID(), groups, {allow={}, deny={}} , _, _, true )
else
ULib.ucl.addUser( info.account, info.type, info.id, groups, {allow={}, deny={}} , _, _, true )
end

Hope that fixes it for you. If not, let us know.
« Last Edit: May 10, 2007, 04:17:13 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline cold12141

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Re: Custom ULX AddTrustie code
« Reply #3 on: May 10, 2007, 04:24:42 PM »
That did not fix it.

This is the error I receive when trying to add a user.
Code: [Select]
[LS ULIB ERROR] Bad user passed to addUser! User account name was nil
« Last Edit: May 10, 2007, 04:29:40 PM by cold12141 »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8027
  • Karma: 381
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Custom ULX AddTrustie code
« Reply #4 on: May 10, 2007, 06:19:26 PM »
That did not fix it.

This is the error I receive when trying to add a user.
Code: [Select]
[LS ULIB ERROR] Bad user passed to addUser! User account name was nil

What are you passing after ulx addtrustie? Player name? SteamID? Is the player connected?
Sounds like this line
Code: [Select]
local target, err = ULib.getUser( argv[ 1 ], _, ply ) is running, but, doesn't contain the information info variable expects.


"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline cold12141

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Re: Custom ULX AddTrustie code
« Reply #5 on: May 10, 2007, 07:03:25 PM »
I'm passing a player name.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8027
  • Karma: 381
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Custom ULX AddTrustie code
« Reply #6 on: May 10, 2007, 07:21:29 PM »
I'm passing a player name.
Yes, but is the player connected?

If so, only thing I know to suggest from here is add in some debug code that text outputs target name and the info table.
Tried that?
* JamminR keeps hoping one of the more advanced coding team members will step in here. He did good to find the fact 'groups' requires a table. :P
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline cold12141

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Re: Custom ULX AddTrustie code
« Reply #7 on: May 10, 2007, 07:23:53 PM »
Yup, tried it on myself  and a friend

Offline spbogie

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 456
  • Karma: 41
Re: Custom ULX AddTrustie code
« Reply #8 on: May 11, 2007, 11:12:51 AM »
Can you give the output of "lua_run PrintTable(ULib.ucl.authed)" on the server console please.
I have not failed. I've just found 10,000 ways that won't work. - Thomas A. Edison
I reject your reality and substitute my own. - Adam Savage

Offline cold12141

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Re: Custom ULX AddTrustie code
« Reply #9 on: May 11, 2007, 02:45:19 PM »
Code: [Select]

> PrintTable(ULib.ucl.authed)...
Player [1][[CB] cold]:
type = listen host
groups:
1 = superadmin
id =
acl:
allow:
deny:
uniqueid = 525689253

Offline spbogie

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 456
  • Karma: 41
Re: Custom ULX AddTrustie code
« Reply #10 on: May 11, 2007, 04:39:54 PM »
Ok, a little more debugging. Add a PrintTable(info) in the else before you call ULib.addUser, then try your command on you and someone else.
I have not failed. I've just found 10,000 ways that won't work. - Thomas A. Edison
I reject your reality and substitute my own. - Adam Savage

Offline cold12141

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Re: Custom ULX AddTrustie code
« Reply #11 on: May 11, 2007, 06:20:03 PM »
Strange, it worked fine when I tried it on a friend this time.

Thanks.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8027
  • Karma: 381
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Custom ULX AddTrustie code
« Reply #12 on: May 11, 2007, 06:39:33 PM »
Glad we could help. Let us know if you see more odd issues.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming