Skip to content

Commit e8b60e3

Browse files
Brito1227MonkeyWhisper
authored andcommitted
Move permission checks to server for admin actions
1 parent 3f0b480 commit e8b60e3

11 files changed

Lines changed: 34 additions & 85 deletions

File tree

client/inventory.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
-- Open Inventory
22
RegisterNetEvent('ps-adminmenu:client:openInventory', function(data, selectedData)
3-
local data = CheckDataFromKey(data)
4-
if not data or not CheckPerms(data.perms) then return end
53
local player = selectedData["Player"].value
64

75
if Config.Inventory == 'ox_inventory' then
@@ -13,8 +11,6 @@ end)
1311

1412
-- Open Stash
1513
RegisterNetEvent('ps-adminmenu:client:openStash', function(data, selectedData)
16-
local data = CheckDataFromKey(data)
17-
if not data or not CheckPerms(data.perms) then return end
1814
local stash = selectedData["Stash"].value
1915

2016
if Config.Inventory == 'ox_inventory' then
@@ -27,8 +23,6 @@ end)
2723

2824
-- Open Trunk
2925
RegisterNetEvent('ps-adminmenu:client:openTrunk', function(data, selectedData)
30-
local data = CheckDataFromKey(data)
31-
if not data or not CheckPerms(data.perms) then return end
3226
local vehiclePlate = selectedData["Plate"].value
3327

3428
if Config.Inventory == 'ox_inventory' then

client/main.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ RegisterNUICallback("clickButton", function(data)
3939
local selectedData = data.selectedData
4040
local key = data.data
4141
local data = CheckDataFromKey(key)
42-
if not data or not CheckPerms(data.perms) then return end
42+
if not data then return end
4343

4444
if data.type == "client" then
45-
TriggerEvent(data.event, key, selectedData)
45+
TriggerServerEvent('ps-adminmenu:server:ValidateClientAction', key, selectedData, data.event, data.perms)
4646
elseif data.type == "server" then
4747
TriggerServerEvent(data.event, key, selectedData)
4848
elseif data.type == "command" then

client/misc.lua

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
-- Toggles Invincibility
22
local visible = true
33
RegisterNetEvent('ps-adminmenu:client:ToggleInvisible', function(data)
4-
local data = CheckDataFromKey(data)
5-
if not data or not CheckPerms(data.perms) then return end
64
visible = not visible
7-
85
SetEntityVisible(cache.ped, visible, 0)
96
end)
107

118
-- God Mode
129
local godmode = false
1310
RegisterNetEvent('ps-adminmenu:client:ToggleGodmode', function(data)
14-
local data = CheckDataFromKey(data)
15-
if not data or not CheckPerms(data.perms) then return end
1611
godmode = not godmode
1712

1813
if godmode then
@@ -55,30 +50,28 @@ local function CopyCoords(data)
5550
end
5651

5752
RegisterCommand("vector2", function()
58-
if not CheckPerms('mod') then return end
59-
CopyCoords("vector2")
53+
TriggerServerEvent('ps-adminmenu:server:ValidateCommand', 'vector2', 'mod')
6054
end, false)
6155

6256
RegisterCommand("vector3", function()
63-
if not CheckPerms('mod') then return end
64-
CopyCoords("vector3")
57+
TriggerServerEvent('ps-adminmenu:server:ValidateCommand', 'vector3', 'mod')
6558
end, false)
6659

6760
RegisterCommand("vector4", function()
68-
if not CheckPerms('mod') then return end
69-
CopyCoords("vector4")
61+
TriggerServerEvent('ps-adminmenu:server:ValidateCommand', 'vector4', 'mod')
7062
end, false)
7163

7264
RegisterCommand("heading", function()
73-
if not CheckPerms('mod') then return end
74-
CopyCoords("heading")
65+
TriggerServerEvent('ps-adminmenu:server:ValidateCommand', 'heading', 'mod')
7566
end, false)
7667

68+
RegisterNetEvent('ps-adminmenu:client:CopyCoords', function(type)
69+
CopyCoords(type)
70+
end)
71+
7772
-- Infinite Ammo
7873
local InfiniteAmmo = false
7974
RegisterNetEvent('ps-adminmenu:client:setInfiniteAmmo', function(data)
80-
local data = CheckDataFromKey(data)
81-
if not data or not CheckPerms(data.perms) then return end
8275
InfiniteAmmo = not InfiniteAmmo
8376

8477
if GetAmmoInPedWeapon(cache.ped, cache.weapon) < 6 then
@@ -116,9 +109,6 @@ local function showCoordsMenu()
116109
end
117110

118111
RegisterNetEvent('ps-adminmenu:client:ToggleCoords', function(data)
119-
local data = CheckDataFromKey(data)
120-
if not data or not CheckPerms(data.perms) then return end
121-
122112
showCoords = not showCoords
123113

124114
if showCoords then
@@ -128,9 +118,6 @@ end)
128118

129119
-- Set Ammo
130120
RegisterNetEvent('ps-adminmenu:client:SetAmmo', function(data, selectedData)
131-
local data = CheckDataFromKey(data)
132-
if not data or not CheckPerms(data.perms) then return end
133-
134121
local ammo = selectedData["Ammo Amount"].value
135122
local weapon = GetSelectedPedWeapon(cache.ped)
136123

@@ -142,8 +129,11 @@ RegisterNetEvent('ps-adminmenu:client:SetAmmo', function(data, selectedData)
142129
end
143130
end)
144131

145-
RegisterCommand("setammo", function(source)
146-
if not CheckPerms('mod') then return end
132+
RegisterCommand("setammo", function()
133+
TriggerServerEvent('ps-adminmenu:server:ValidateCommand', 'setammo', 'mod')
134+
end, false)
135+
136+
RegisterNetEvent('ps-adminmenu:client:SetAmmoCommand', function()
147137
local weapon = GetSelectedPedWeapon(cache.ped)
148138
local ammo = 999
149139
if weapon ~= nil then
@@ -152,15 +142,12 @@ RegisterCommand("setammo", function(source)
152142
else
153143
QBCore.Functions.Notify(locale("no_weapon"), 'error')
154144
end
155-
end, false)
145+
end)
156146

157147
--Toggle Dev
158148
local ToggleDev = false
159149

160150
RegisterNetEvent('ps-adminmenu:client:ToggleDev', function(dataKey)
161-
local data = CheckDataFromKey(dataKey)
162-
if not data or not CheckPerms(data.perms) then return end
163-
164151
ToggleDev = not ToggleDev
165152

166153
TriggerEvent("qb-admin:client:ToggleDevmode") -- toggle dev mode (ps-hud/qb-hud)
@@ -182,7 +169,7 @@ local toogleAdmin = lib.addKeybind({
182169

183170
--noclip
184171
RegisterCommand('nc', function()
185-
TriggerEvent(Config.Actions["noclip"].event)
172+
TriggerServerEvent('ps-adminmenu:server:ValidateClientAction', 'noclip', nil, Config.Actions["noclip"].event, Config.Actions["noclip"].perms)
186173
end, false)
187174

188175
local toogleNoclip = lib.addKeybind({

client/noclip.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ local function ToggleNoclip()
200200
end
201201

202202
RegisterNetEvent('ps-adminmenu:client:ToggleNoClip', function()
203-
if not CheckPerms(Config.Actions["noclip"].perms) then return end
204203
ToggleNoclip()
205204
end)
206205

client/players.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,17 @@ end
144144

145145
-- Toggle Blips and Names events
146146
RegisterNetEvent('ps-adminmenu:client:toggleBlips', function(data)
147-
local data = CheckDataFromKey(data)
148-
if not data or not CheckPerms(data.perms) then return end
149147
if not ShowBlips then preparePlayers() end
150148
ToggleBlipsAndNames(true)
151149
end)
152150

153151
RegisterNetEvent('ps-adminmenu:client:toggleNames', function(data)
154-
local data = CheckDataFromKey(data)
155-
if not data or not CheckPerms(data.perms) then return end
156152
if not ShowNames then preparePlayers() end
157153
ToggleBlipsAndNames(false)
158154
end)
159155

160156
-- Mute Player
161157
RegisterNetEvent("ps-adminmenu:client:MutePlayer", function(data, selectedData)
162-
local data = CheckDataFromKey(data)
163-
if not data or not CheckPerms(data.perms) then return end
164158
local playerId = selectedData["Player"].value
165159
if not playerId then return end
166160
exports["pma-voice"]:toggleMutePlayer(playerId)

client/teleport.lua

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ end)
1616

1717
-- Teleport to coords
1818
RegisterNetEvent('ps-adminmenu:client:TeleportToCoords', function(data, selectedData)
19-
local data = CheckDataFromKey(data)
20-
if not data or not CheckPerms(data.perms) then return end
21-
2219
local coordsStr = selectedData["Coords"].value
2320
local x, y, z, heading
2421

@@ -44,8 +41,6 @@ end)
4441

4542
-- Teleport to Locaton
4643
RegisterNetEvent('ps-adminmenu:client:TeleportToLocation', function(data, selectedData)
47-
local data = CheckDataFromKey(data)
48-
if not data or not CheckPerms(data.perms) then return end
4944
local coords = selectedData["Location"].value
5045

5146
lastCoords = GetEntityCoords(cache.ped)
@@ -54,9 +49,6 @@ end)
5449

5550
-- Teleport back
5651
RegisterNetEvent('ps-adminmenu:client:TeleportBack', function(data)
57-
local data = CheckDataFromKey(data)
58-
if not data or not CheckPerms(data.perms) then return end
59-
6052
if lastCoords then
6153
local coords = GetEntityCoords(cache.ped)
6254
teleport(lastCoords.x, lastCoords.y, lastCoords.z)

client/troll.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ end)
2020

2121
-- Play Sound
2222
RegisterNetEvent('ps-adminmenu:client:PlaySound', function(data, selectedData)
23-
local data = CheckDataFromKey(data)
24-
if not data or not CheckPerms(data.perms) then return end
2523
local player = selectedData["Player"].value
2624
local sound = selectedData["Sound"].value
2725

client/utils.lua

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ function ToggleUI(bool)
77
})
88
end
99

10-
--- @param perms table
11-
function CheckPerms(perms)
12-
return lib.callback.await('ps-adminmenu:callback:CheckPerms', false, perms)
13-
end
14-
1510
function CheckDataFromKey(key)
1611
local actions = Config.Actions[key]
1712
if actions then

client/vehicles.lua

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ end
88

99
-- Own Vehicle
1010
RegisterNetEvent('ps-adminmenu:client:Admincar', function(data)
11-
local data = CheckDataFromKey(data)
12-
if not data or not CheckPerms(data.perms) then return end
13-
1411
if not cache.vehicle then return end
1512

1613
local props = lib.getVehicleProperties(cache.vehicle)
@@ -27,9 +24,6 @@ end)
2724

2825
-- Spawn Vehicle
2926
RegisterNetEvent('ps-adminmenu:client:SpawnVehicle', function(data, selectedData)
30-
local data = CheckDataFromKey(data)
31-
if not data or not CheckPerms(data.perms) then return end
32-
3327
local selectedVehicle = selectedData["Vehicle"].value
3428
local hash = GetHashKey(selectedVehicle)
3529

@@ -57,9 +51,6 @@ end)
5751

5852
-- Refuel Vehicle
5953
RegisterNetEvent('ps-adminmenu:client:RefuelVehicle', function(data)
60-
local data = CheckDataFromKey(data)
61-
if not data or not CheckPerms(data.perms) then return end
62-
6354
if cache.vehicle then
6455
if Config.Fuel == "ox_fuel" then
6556
Entity(cache.vehicle).state.fuel = 100.0
@@ -74,8 +65,6 @@ end)
7465

7566
-- Change plate
7667
RegisterNetEvent('ps-adminmenu:client:ChangePlate', function(data, selectedData)
77-
local data = CheckDataFromKey(data)
78-
if not data or not CheckPerms(data.perms) then return end
7968
local plate = selectedData["Plate"].value
8069

8170
if string.len(plate) > 8 then
@@ -129,8 +118,6 @@ local function UpdateVehicleMenu()
129118
end
130119

131120
RegisterNetEvent('ps-adminmenu:client:ToggleVehDevMenu', function(data)
132-
local data = CheckDataFromKey(data)
133-
if not data or not CheckPerms(data.perms) then return end
134121
if not cache.vehicle then return end
135122

136123
VEHICLE_DEV_MODE = not VEHICLE_DEV_MODE
@@ -157,9 +144,6 @@ end
157144

158145

159146
RegisterNetEvent('ps-adminmenu:client:maxmodVehicle', function(data)
160-
local data = CheckDataFromKey(data)
161-
if not data or not CheckPerms(data.perms) then return end
162-
163147
if cache.vehicle then
164148
UpgradePerformance(cache.vehicle)
165149
else
@@ -170,9 +154,6 @@ end)
170154
-- Spawn Personal vehicles
171155

172156
RegisterNetEvent("ps-adminmenu:client:SpawnPersonalVehicle", function(data, selectedData)
173-
local data = CheckDataFromKey(data)
174-
if not data or not CheckPerms(data.perms) then return end
175-
176157
local plate = selectedData['VehiclePlate'].value
177158
local ped = PlayerPedId()
178159
local coords = QBCore.Functions.GetCoords(ped)

client/world.lua

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
-- Changes the time
22
RegisterNetEvent('ps-adminmenu:client:ChangeTime', function(data, selectedData)
3-
local data = CheckDataFromKey(data)
4-
if not data or not CheckPerms(data.perms) then return end
53
local time = selectedData["Time Events"].value
64

75
if not time then return end
@@ -11,17 +9,12 @@ end)
119

1210
-- Changes the weather
1311
RegisterNetEvent('ps-adminmenu:client:ChangeWeather', function(data, selectedData)
14-
local data = CheckDataFromKey(data)
15-
if not data or not CheckPerms(data.perms) then return end
1612
local weather = selectedData["Weather"].value
1713

1814
TriggerServerEvent('qb-weathersync:server:setWeather', weather)
1915
end)
2016

2117
RegisterNetEvent('ps-adminmenu:client:copyToClipboard', function(data, selectedData)
22-
local data = CheckDataFromKey(data)
23-
if not data or not CheckPerms(data.perms) then return end
24-
2518
local dropdown = selectedData["Copy Coords"].value
2619
local ped = PlayerPedId()
2720
local string = nil

0 commit comments

Comments
 (0)