• Print

Author Topic: Restrict xgui ConCommand  (Read 5573 times)

0 Members and 1 Guest are viewing this topic.

Offline Darkblizzard

  • Newbie
  • *
  • Posts: 39
  • Karma: 1
Restrict xgui ConCommand
« on: June 01, 2018, 03:33:12 pm »
Hello,
I'm trying to restrict it so the concommand "xgui" or "ulx menu" doesn't open unless in a certain usergroup. I would use the Garry's Mod functions, but looking through the code each one begins with "xgui.". Is there a specific way to do this without having to damage the code?
Thanks!

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Restrict xgui ConCommand
« Reply #1 on: June 02, 2018, 08:18:56 am »
You should be able to restrict access to the "xgui" command inside of XGUI, just like you do with the other ULX commands.
Experiencing God's grace one day at a time.

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Restrict xgui ConCommand
« Reply #2 on: June 04, 2018, 09:42:46 am »
Actually, the xgui commands are defined on the client:
https://github.com/TeamUlysses/ulx/blob/master/lua/ulx/modules/cl/xgui_client.lua#L562-L568

My reasoning at the time was that even regular users have access to at least one or two ulx commands.

You can probably write some lua code that loads after xgui initializes to override the xgui.show function. Something like this should do (untested code):
Code: Lua
  1. -- After xgui_client.lua has loaded (ulx module)
  2. local oldShow = xgui.show
  3. function xgui.show(tabname)
  4.     if yourCustomCheckToSeeIfTheyCanOpenXgui then
  5.         oldShow(tabname)
  6.     end
  7. end
  8.  
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline Darkblizzard

  • Newbie
  • *
  • Posts: 39
  • Karma: 1
Re: Restrict xgui ConCommand
« Reply #3 on: June 07, 2018, 05:17:04 pm »
Sorry for the late response, but if I wanted to use "ply:IsSuperAdmin()", where does it recognize the "ply"?

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Restrict xgui ConCommand
« Reply #4 on: June 07, 2018, 07:17:41 pm »
That would be the player object as a variable passed into the function you are working within.

So, for example in this code:

Code: [Select]

function TestFunction( ply )
    print ( ply:IsSuperAdmin() )
end


The ply INSIDE the function... the one that is attached to :IsSuperAdmin() is accepted as the arguement passed into the function TestFunction() so outside the function, when you call the function TestFunction() you would need to make sure to pass it a player object.

example:

Code: [Select]

TestFunction( ULib.getUser("darkblizzard") )


Does that make sense?

lua is loosely typed.. meaning that variables don't require being defined with a type.. as long as what you set is the data type that is expected when you try and use it later, it will function.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Restrict xgui ConCommand
« Reply #5 on: June 07, 2018, 07:22:19 pm »
Now... let's say you're working within a ULX command structure.. which you probably are (maybe?)

Take a look at the code for the !slap command

Code: [Select]
------------------------------ Slap ------------------------------
function ulx.slap( calling_ply, target_plys, dmg )
local affected_plys = {}

for i=1, #target_plys do
local v = target_plys[ i ]
if v:IsFrozen() then
ULib.tsayError( calling_ply, v:Nick() .. " is frozen!", true )
else
ULib.slap( v, dmg )
table.insert( affected_plys, v )
end
end

ulx.fancyLogAdmin( calling_ply, "#A slapped #T with #i damage", affected_plys, dmg )
end

local slap = ulx.command( CATEGORY_NAME, "ulx slap", ulx.slap, "!slap" )
slap:addParam{ type=ULib.cmds.PlayersArg }
slap:addParam{ type=ULib.cmds.NumArg, min=0, default=0, hint="damage", ULib.cmds.optional, ULib.cmds.round }
slap:defaultAccess( ULib.ACCESS_ADMIN )
slap:help( "Slaps target(s) with given damage." )

notice how at the top where the function is defined, there are variable names passed into it. calling_ply, target_plys and dmg

In the code calling_ply is the one who RAN the command.. so if you wanted to check if that player was a superadmin.. you would use calling_ply:IsSuperAdmin() not ply:IsSuperAdmin().. that's because the player object passed into the function is calling_ply

the target_plys variable is a table of player objects.. further in the code you'll notice how we're iterating through that table with a for loop. In that case.. the player being checked in the loop is 'v'.



I know this is a bit confusing if you're not used to programming, but I think it is pretty straight forward.

let me know if you have any more questions.

Offline Darkblizzard

  • Newbie
  • *
  • Posts: 39
  • Karma: 1
Re: Restrict xgui ConCommand
« Reply #6 on: June 07, 2018, 08:12:27 pm »
Oh no, I understand how that works, and actually made some code myself using that. What I don't understand is where to get "ply" when working in the xgui client? The xgui.open function does not have "ply", and it appears like all the functions are rather custom which makes me nervous about breaking any of the code within.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Restrict xgui ConCommand
« Reply #7 on: June 08, 2018, 12:16:32 am »
XGUI is clientside.. so ply would just be LocalPlayer()

Offline Darkblizzard

  • Newbie
  • *
  • Posts: 39
  • Karma: 1
Re: Restrict xgui ConCommand
« Reply #8 on: June 08, 2018, 10:28:50 am »
Thanks for the help!

  • Print