Skip to content

feat: add opt-in checks #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
"blips_deactivated": "Blips deactivated",
"names_deactivated": "Names deactivated",
"no_report_reply": "Reply failed to send due to no message",
"no_reports": "no pending reports to load"
"no_reports": "no pending reports to load",
"not_optin": "You are not opted in."
}
}
10 changes: 10 additions & 0 deletions server/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,39 @@ lib.addCommand('admin', {
help = 'Opens Admin Menu',
restricted = config.useMenu,
}, function(source)
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end
TriggerClientEvent('qbx_admin:client:openMenu', source)
end)

lib.addCommand('noclip', {
help = 'Toggle NoClip',
restricted = config.noclip,
}, function(source)
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end
TriggerClientEvent('qbx_admin:client:ToggleNoClip', source)
end)

lib.addCommand('names', {
help = 'Toggle Player Names',
restricted = config.names,
}, function(source)
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end
TriggerClientEvent('qbx_admin:client:names', source)
end)

lib.addCommand('blips', {
help = 'Toggle Player Blips',
restricted = config.blips,
}, function(source)
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end
TriggerClientEvent('qbx_admin:client:blips', source)
end)

lib.addCommand('admincar', {
help = 'Buy Vehicle',
restricted = config.saveVehicle,
}, function(source)
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end
local vehicle = GetVehiclePedIsIn(GetPlayerPed(source), false)
if vehicle == 0 then
return exports.qbx_core:Notify(source, 'You have to be in a vehicle, to use this', 'error')
Expand Down Expand Up @@ -83,6 +88,7 @@ lib.addCommand('setmodel', {
{name = 'id', help = 'Player ID', type = 'number', optional = true},
}
}, function(source, args)
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end
local Target = args.id or source

if not exports.qbx_core:GetPlayer(Target) then return end
Expand All @@ -94,26 +100,30 @@ lib.addCommand('vec2', {
help = 'Copy vector2 to clipboard (Admin only)',
restricted = config.dev,
}, function(source)
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end
TriggerClientEvent('qbx_admin:client:copyToClipboard', source, 'coords2')
end)

lib.addCommand('vec3', {
help = 'Copy vector3 to clipboard (Admin only)',
restricted = config.dev,
}, function(source)
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end
TriggerClientEvent('qbx_admin:client:copyToClipboard', source, 'coords3')
end)

lib.addCommand('vec4', {
help = 'Copy vector4 to clipboard (Admin only)',
restricted = config.dev,
}, function(source)
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end
TriggerClientEvent('qbx_admin:client:copyToClipboard', source, 'coords4')
end)

lib.addCommand('heading', {
help = 'Copy heading to clipboard (Admin only)',
restricted = config.dev,
}, function(source)
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end
TriggerClientEvent('qbx_admin:client:copyToClipboard', source, 'heading')
end)
31 changes: 21 additions & 10 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ REPORTS = {}
function OnAdmin(permission, cb)
for k, v in pairs(exports.qbx_core:GetQBPlayers()) do
if IsPlayerAceAllowed(k, permission) then
cb(v)
if exports.qbx_core:IsOptin(k) then
cb(v)
end
end
end
end
Expand Down Expand Up @@ -53,6 +55,7 @@ end

RegisterNetEvent('qbx_admin:server:sendReply', function(report, message)
if not IsPlayerAceAllowed(source, config.commandPerms.reportReply) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end

for k, v in pairs(REPORTS) do
if v.id == report.id then
Expand All @@ -74,6 +77,7 @@ end)

RegisterNetEvent('qbx_admin:server:deleteReport', function(report)
if not IsPlayerAceAllowed(source, config.commandPerms.reportReply) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end

for k, v in pairs(REPORTS) do
if v.id == report.id then
Expand Down Expand Up @@ -118,6 +122,7 @@ local generalOptions = {
}
RegisterNetEvent('qbx_admin:server:playerOptionsGeneral', function(selected, selectedPlayer, input)
if not IsPlayerAceAllowed(source, config.eventPerms.playerOptionsGeneral) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end

---@diagnostic disable-next-line: redundant-parameter
generalOptions[selected](selectedPlayer, source, input)
Expand All @@ -126,10 +131,13 @@ end)
local administrationOptions = {
function(source, selectedPlayer, input)
if not IsPlayerAceAllowed(source, config.eventPerms.kick) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end

DropPlayer(selectedPlayer.id, input)
end,
function(source, selectedPlayer, input)
if not IsPlayerAceAllowed(source, config.eventPerms.ban) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end
local banDuration = (input[2] or 0) * 3600 + (input[3] or 0) * 86400 + (input[4] or 0) * 2629743
DropPlayer(selectedPlayer.id, locale('player_options.administration.banreason', input[1], os.date('%c', os.time() + banDuration)))
MySQL.Async.insert('INSERT INTO bans (name, license, discord, ip, reason, expire, bannedby) VALUES (?, ?, ?, ?, ?, ?, ?)', {
Expand All @@ -139,6 +147,7 @@ local administrationOptions = {
end,
function(source, selectedPlayer, input)
if not IsPlayerAceAllowed(source, config.eventPerms.changePerms) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end
if input == 'remove' then exports.qbx_core:RemovePermission(selectedPlayer.id) else exports.qbx_core:AddPermission(selectedPlayer.id, input) end
end,
}
Expand Down Expand Up @@ -182,6 +191,8 @@ RegisterNetEvent('qbx_admin:server:changePlayerData', function(selected, selecte
local target = exports.qbx_core:GetPlayer(selectedPlayer.id)

if not IsPlayerAceAllowed(source, config.eventPerms.changePlayerData) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end

if not target then return end

playerDataOptions[selected](target, input)
Expand All @@ -192,6 +203,7 @@ RegisterNetEvent('qbx_admin:server:giveAllWeapons', function(weaponType, playerI
local target = exports.qbx_core:GetPlayer(src)

if not IsPlayerAceAllowed(source, config.eventPerms.giveAllWeapons) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end

for i = 1, #config.weaponList[weaponType], 1 do
target.Functions.AddItem(config.weaponList[weaponType][i], 1)
Expand All @@ -203,6 +215,7 @@ lib.callback.register('qbx_admin:callback:getradiolist', function(source, freque
local players = {}

if not IsPlayerAceAllowed(source, config.eventPerms.getRadioList) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end

for targetSource, _ in pairs(list) do -- cheers Knight who shall not be named
local player = exports.qbx_core:GetPlayer(targetSource)
Expand All @@ -216,6 +229,7 @@ end)

lib.callback.register('qbx_admin:server:getPlayers', function(source)
if not IsPlayerAceAllowed(source, config.eventPerms.useMenu) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end

local players = {}
for k, v in pairs(exports.qbx_core:GetQBPlayers()) do
Expand Down Expand Up @@ -245,6 +259,7 @@ end)

lib.callback.register('qbx_admin:server:getPlayer', function(source, playerToGet)
if not IsPlayerAceAllowed(source, config.eventPerms.useMenu) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end

local playerData = exports.qbx_core:GetPlayer(playerToGet).PlayerData
local player = {
Expand All @@ -270,21 +285,17 @@ lib.callback.register('qbx_admin:server:getPlayer', function(source, playerToGet
end)

lib.callback.register('qbx_admin:server:clothingMenu', function(source, target)
if not IsPlayerAceAllowed(source, config.eventPerms.clothingMenu) then
exports.qbx_core:Notify(source, locale('error.no_perms'), 'error')
return false
end
if not IsPlayerAceAllowed(source, config.eventPerms.clothingMenu) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return false end
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return false end

TriggerClientEvent('qb-clothing:client:openMenu', target)

return true
end)

lib.callback.register('qbx_admin:server:canUseMenu', function(source)
if not IsPlayerAceAllowed(source, config.eventPerms.useMenu) then
exports.qbx_core:Notify(source, locale('error.no_perms'), 'error')
return false
end
if not IsPlayerAceAllowed(source, config.eventPerms.useMenu) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return false end
if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return false end

return true
end)
Expand All @@ -303,6 +314,6 @@ end)

lib.callback.register('qbx_admin:server:getReports', function(source)
if not IsPlayerAceAllowed(source, config.commandPerms.reportReply) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end

if not exports.qbx_core:IsOptin(source) then exports.qbx_core:Notify(source, locale('error.not_optin'), 'error') return end
return REPORTS
end)