Ulysses

General => Developers Corner => Topic started by: cold12141 on May 10, 2007, 02:36:46 PM

Title: Custom ULX AddTrustie code
Post by: cold12141 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 )
Title: Re: Custom ULX AddTrustie code
Post by: JamminR 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?
Title: Re: Custom ULX AddTrustie code
Post by: JamminR 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.
Title: Re: Custom ULX AddTrustie code
Post by: cold12141 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
Title: Re: Custom ULX AddTrustie code
Post by: JamminR 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.


Title: Re: Custom ULX AddTrustie code
Post by: cold12141 on May 10, 2007, 07:03:25 PM
I'm passing a player name.
Title: Re: Custom ULX AddTrustie code
Post by: JamminR 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?
/me 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
Title: Re: Custom ULX AddTrustie code
Post by: cold12141 on May 10, 2007, 07:23:53 PM
Yup, tried it on myself  and a friend
Title: Re: Custom ULX AddTrustie code
Post by: spbogie 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.
Title: Re: Custom ULX AddTrustie code
Post by: cold12141 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
Title: Re: Custom ULX AddTrustie code
Post by: spbogie 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.
Title: Re: Custom ULX AddTrustie code
Post by: cold12141 on May 11, 2007, 06:20:03 PM
Strange, it worked fine when I tried it on a friend this time.

Thanks.
Title: Re: Custom ULX AddTrustie code
Post by: JamminR on May 11, 2007, 06:39:33 PM
Glad we could help. Let us know if you see more odd issues.