Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions [core]/es_extended/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ shared_scripts {
server_scripts {
'@oxmysql/lib/MySQL.lua',
'shared/config/logs.lua',
'server/config/commandperms.lua',

'server/common.lua',
'server/modules/callback.lua',
Expand Down
43 changes: 43 additions & 0 deletions [core]/es_extended/server/config/commandperms.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Config.CommandPermissions = {
["setcoords"] = { "admin" },
["tp"] = { "admin" },
["setjob"] = { "admin" },
["car"] = { "admin" },
["cardel"] = { "admin" },
["dv"] = { "admin" },
["fix"] = { "admin" },
["repair"] = { "admin" },
["setaccountmoney"] = { "admin" },
["giveaccountmoney"] = { "admin" },
["removeaccountmoney"] = { "admin" },
["giveitem"] = { "admin" },
["giveweapon"] = { "admin" },
["giveammo"] = { "admin" },
["giveweaponcomponent"] = { "admin" },
["clearall"] = { "admin" },
["clsall"] = { "admin" },
["refreshjobs"] = { "admin" },
["refreshitems"] = { "admin" },
["clearinventory"] = { "admin" },
["clearloadout"] = { "admin" },
["setgroup"] = { "admin" },
["save"] = { "admin" },
["saveall"] = { "admin" },
["group"] = { "user" },
["job"] = { "user" },
["info"] = { "user" },
["playtime"] = { "user" },
["coords"] = { "admin" },
["tpm"] = { "admin" },
["goto"] = { "admin" },
["bring"] = { "admin" },
["kill"] = { "admin" },
["freeze"] = { "admin" },
["unfreeze"] = { "admin" },
["noclip"] = { "admin" },
["players"] = { "admin" },
["setdim"] = { "admin" },
["setbucket"] = { "admin" },
["clear"] = { "user" },
["cls"] = { "user" },
}
36 changes: 27 additions & 9 deletions [core]/es_extended/server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ function ESX.TriggerClientEvent(eventName, playerIds, ...)
end
end

---@param name string | table
---@param group string | table
---@param cb fun(xPlayer : xPlayer|false, args : table, showError :function )
---Supports multiple overloads:
---1. ESX.RegisterCommand(name, group, cb, allowConsole?, suggestion?)
---2. ESX.RegisterCommand(name, false, cb, allowConsole?, suggestion?) -- Looks up group in Config.CommandPermissions
---@param name string | string[]
---@param group false | string | string[] -- Use false to lookup in Config.CommandPermissions
---@param cb fun(xPlayer: xPlayer|false, args: table, showError: function)
---@param allowConsole? boolean
---@param suggestion? {help:string, validate:boolean, arguments:{name:string, validate:boolean, help:string, type:'number'|'string'|'player'|'coordinate'|'playerId'|'item'|'weapon'|'any'|'merge'}[]}
---@param suggestion? {help?: string, validate?: boolean, arguments?: {name: string, validate?: boolean, help?: string, type: 'number'|'string'|'player'|'coordinate'|'playerId'|'item'|'weapon'|'any'|'merge'}[]}
function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
if type(name) == "table" then
for _, v in ipairs(name) do
Expand All @@ -37,6 +40,21 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
return
end

local commandGroup = group

if group == false then
local permGroups = Config.CommandPermissions[name]

if permGroups and type(permGroups) == "table" then
commandGroup = #permGroups == 1 and permGroups[1] or permGroups
else
commandGroup = "user"
end
elseif type(group) ~= "string" and type(group) ~= "table" then
error(("Invalid group provided to ESX.RegisterCommand for command '%s'"):format(name))
return
end

if Core.RegisteredCommands[name] then
print(('[^3WARNING^7] Command ^5"%s" ^7already registered, overriding command'):format(name))

Expand All @@ -56,7 +74,7 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
TriggerClientEvent("chat:addSuggestion", -1, ("/%s"):format(name), suggestion.help, suggestion.arguments)
end

Core.RegisteredCommands[name] = { group = group, cb = cb, allowConsole = allowConsole, suggestion = suggestion }
Core.RegisteredCommands[name] = { group = commandGroup, cb = cb, allowConsole = allowConsole, suggestion = suggestion }

RegisterCommand(name, function(playerId, args)
local command = Core.RegisteredCommands[name]
Expand Down Expand Up @@ -146,7 +164,7 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
end
end
end

if ESX.IsFunctionReference(v.Validator?.validate) and not err then
local candidate = newArgs[v.name]
local ok, res = pcall(v.Validator.validate, candidate)
Expand Down Expand Up @@ -187,12 +205,12 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
end
end, true)

if type(group) == "table" then
for _, v in ipairs(group) do
if type(commandGroup) == "table" then
for _, v in ipairs(commandGroup) do
ExecuteCommand(("add_ace group.%s command.%s allow"):format(v, name))
end
else
ExecuteCommand(("add_ace group.%s command.%s allow"):format(group, name))
ExecuteCommand(("add_ace group.%s command.%s allow"):format(commandGroup, name))
end
end

Expand Down
Loading