• Print

Author Topic: Default access of opposite command  (Read 4898 times)

0 Members and 1 Guest are viewing this topic.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Default access of opposite command
« on: April 29, 2017, 12:01:40 pm »
I was wondering if there was a way to set the default access of an opposite command. For example, I have this function:
(All other calls in here are defined, just wondering about access)


Code: Lua
  1.  
  2. function scc.joinChannel( calling_ply, target_ply, channel, is_force )
  3.    if not target_ply then target_ply = calling_ply end
  4.    local old = target_ply:GetChannel()
  5.    local players = SCC.PlayersInChannel( target_ply:GetChannel() )
  6.    local newPlayers = SCC.PlayersInChannel( channel )
  7.    local can, err = SCC.CanPlayerJoin( target_ply, channel )
  8.    
  9.    if not can then
  10.       ULib.tsayError( calling_ply, "[SCC Error] You cannot perform this action: " .. err, true )
  11.    end
  12.  
  13.  
  14.    if not is_force then
  15.       calling_ply:JoinChannel( channel, false )  
  16.       ulx.fancyLogAdmin( calling_ply, { calling_ply }, SCC.JoinMessage, channel )
  17.       ulx.fancyLogAdmin( calling_ply, { players }, SCC.LeaveMessage )
  18.       ulx.fancyLogAdmin( calling_ply, { newPlayers }, SCC.JoinedMessage )
  19.    else
  20.       calling_ply:JoinChannel( channel, true )
  21.       ulx.fancyLogAdmin( calling_ply, { calling_ply }, SCC.ForceMessage, target_ply, channel )
  22.       ulx.fancyLogAdmin( calling_ply, { players }, SCC.LeaveMessage )
  23.       ulx.fancyLogAdmin( calling_ply, { target_ply }, SCC.ForcedMessage, channel )
  24.    end
  25. end
  26. local sjoin = ulx.command( "SVC Utility", "svc joinchannel", scc.joinChannel, "!joinchannel" )
  27. sjoin:addParam{ type = ULib.cmds.PlayerArg, ULib.cmds.optional, default = "^" }
  28. sjoin:addParam{ type = ULib.cmds.StringArg, completes = scc.channels, ULib.cmds.restrictToCompletes, error = "Invalid channel \"%s\" specified." }
  29. sjoin:addParam{ type = ULib.cmds.BoolArg, invisible = true }
  30. sjoin:setOpposite( "svc force", { _, _, _, true }, "!forcejoin" )
  31. sjoin:help( "Joins a specified channel." )
  32. sjoin:defaultAccess( "user" )
  33.  


And I'm trying to figure out if there is a way to set the opposite to have the access of "operator" while the default is "user". One solution I could think of is just making another function call this but with is_force as true. I decided to just do that but I was wondering if there was a way to do that.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Default access of opposite command
« Reply #1 on: April 29, 2017, 01:31:46 pm »
There is no default way in ULib's command setup to do what you ask.
It's usually presumed that if you have access to do a command, you also have access to undo a command.

Two likely option, other than your 'make a different function that references this one with is_force' would be to, within the 'else' statement, check for which groups (operator) you only want to be allowed to do it, or, and I'm really not sure on this one so you'd have to test, deny access to "svc force" for the user group.
I'd really question my latter deny suggestion would work though - I don't think ULib registers the opposite as a command that can be denied like it does the ulx.command line code.

Force and joinchannel are, imo, two totally different commands. You just happen to be combining them.
joining a channel and forcing someone to join a channel are not opposites, imo.
« Last Edit: April 29, 2017, 01:34:02 pm by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Default access of opposite command
« Reply #2 on: April 29, 2017, 02:46:56 pm »
Right I don't think they're opposites but I wanted them to do the same function. I'll most likely just make another command.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Default access of opposite command
« Reply #3 on: April 29, 2017, 05:40:32 pm »
It wouldn't hurt to save code though.

Keep your join channel code of course.
Then just set a command that calls the function for users, then one that calls the same function with is_force like you wanted.

example logic

function my_channeljoin (calling, target, forced)
    if forced
        blah
    else
        blah
    end
end

local joinchannel = ulx command (blah, "svc joinchannel", my_channeljoin)
joinchannel params = forced/false
blah group users

local forcejoin = ulx command (blah, "svc forcechannel", my_channeljoin)
joinchannel params = forced/true
blah group operators

Your join code couldn't be called directly by players, but the commands for it could depending on group.
« Last Edit: April 29, 2017, 05:51:14 pm by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Default access of opposite command
« Reply #4 on: April 29, 2017, 05:46:31 pm »
Huh... that actually makes a lot of sense. I never would've thought of that.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

  • Print