0 Members and 1 Guest are viewing this topic.
local f = "ULib/restricted_concommands.txt"local data = file.Read( f, "DATA" ) or {}--------------- Helpers -----------------local function saveFile() file.Write( f, util.TableToKeyValues( data ) )endlocal function loadFile() data = file.Read( f, "DATA" ) or {}end -- Important that you don't call this after making-- changes to permissions without saving your changes.local function loadFuncs() local old_comms = concommand.GetTable() loadFile() for k,v in pairs( old_comms ) do concommand.Remove( k ) -- Remove it first -- Create a new function that calls the hook first local new = function( ply, cmd, args, str ) local allow = hook.Call( "ConCommandRan", GAMEMODE, ply, cmd, args, str ) if not allow then return end v( ply, cmd, args, str ) end -- Use that function as the new console command. concommand.Add( k, new ) endend-- Can the player use the command?local function allowed( cmd, ply ) local group = ply:GetUserGroup() local groupInfo = data[group] return groupInfo.allow[cmd] ~= false end---------------------------------------------------- ulx -- function ulx.groupallowcmd( caller, group, cmd ) local groupInfo = data[group] if not groupInfo.allow[cmd] then ULib.tsayError( caller, "Group \'#s\' does not have access to #s", group, cmd ) return false end groupInfo.allow[cmd] = true saveFile() ulx.fancyLogAdmin( caller, false, "#A restricted command #s from group #s.", cmd, group )endlocal allow = ulx.command( "User Management", ulx.groupallowcmd, "ulx groupallowcmd" )allow:addParam{ type=ULib.cmds.StringArg, completes=ulx.group_names, hint="group", error="invalid group \"%s\" specified", ULib.cmds.restrictToCompletes }allow:addParam{ type=ULib.cmds.StringArg, hint="command" }allow:defaultAccess( ULib.ACCESS_SUPERADMIN )allow:help( "Allows a group's access to a command." )function ulx.groupdenycmd( caller, group, cmd ) local groupInfo = data[group] if not groupInfo.allow[cmd] then ULib.tsayError( caller, "Group \'#s\' does not have access to #s", group, cmd ) return false end groupInfo.allow[cmd] = false saveFile() ulx.fancyLogAdmin( caller, false, "#A restricted command #s from group #s.", cmd, group )endlocal deny = ulx.command( "User Management", ulx.groupdenycmd, "ulx groupdenycmd" )deny:addParam{ type=ULib.cmds.StringArg, completes=ulx.group_names, hint="group", error="invalid group \"%s\" specified", ULib.cmds.restrictToCompletes }deny:addParam{ type=ULib.cmds.StringArg, hint="command" }deny:defaultAccess( ULib.ACCESS_SUPERADMIN )deny:help( "Denies a group's access to a command." )-- hooks -- local function concommandRan( ply, cmd, args, str ) if not allowed( cmd, ply ) then ULib.tsayError( ply, "You don't have access to this command, " .. ply:Name() ) return false end return true endhook.Add( "ConCommandRan", "ULX_RestrictConcommands", concommandRan )local function init() -- New hook, leave it blank for now. We'll right the ulx hook later. -- return true to allow it to run, return false to deny. function GAMEMODE:ConCommandRan( ply, cmd, args, str ) return true end loadFuncs()endhook.Add( "Initialize", "ULX_LoadConcommands", init )
function ulx.groupallowcmd( caller, group, cmd ) local groupInfo = data[group] if not groupInfo.allow[cmd] then ULib.tsayError( caller, "Group \'#s\' does not have access to #s", group, cmd ) return false end groupInfo.allow[cmd] = true saveFile() ulx.fancyLogAdmin( caller, false, "#A restricted command #s from group #s.", cmd, group )end-- THIS LINE SPECIFICALLY. ->>> local allow = ulx.command( "User Management", ulx.groupallowcmd, "ulx groupallowcmd" )allow:addParam{ type=ULib.cmds.StringArg, completes=ulx.group_names, hint="group", error="invalid group \"%s\" specified", ULib.cmds.restrictToCompletes }allow:addParam{ type=ULib.cmds.StringArg, hint="command" }allow:defaultAccess( ULib.ACCESS_SUPERADMIN )allow:help( "Allows a group's access to a command." )
ulx.command( (string) category, (string) consoleCommand, (function) callback, (string) chatCommand )