Skip to content

Commit cd9154a

Browse files
author
Dutchman101
committed
freeroam: Additional (sanity) checks, fixes for common debug warnings and popular methods to get an unfair advantage in combat
1 parent f194983 commit cd9154a

File tree

2 files changed

+158
-29
lines changed

2 files changed

+158
-29
lines changed

[gameplay]/freeroam/fr_client.lua

Lines changed: 141 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -196,35 +196,63 @@ wndSkin = {
196196
}
197197

198198
function setSkinCommand(cmd, skin)
199+
200+
if isPlayerMoving(localPlayer) then
201+
errMsg("You can't use /ss while running! Stop moving first!")
202+
return
203+
end
204+
199205
skin = skin and tonumber(skin)
200206
if skin then
201207
server.setMySkin(skin)
202208
fadeCamera(true)
203209
closeWindow(wndSpawnMap)
204210
closeWindow(wndSetPos)
211+
else
212+
errMsg("Invalid skin ID! Usage: /ss [id]")
205213
end
206214
end
207215
addCommandHandler('setskin', setSkinCommand)
208216
addCommandHandler('ss', setSkinCommand)
209217

218+
function isPlayerMoving(p)
219+
if isElement(p) and getElementType(p) == "player" then
220+
return Vector3(getElementVelocity(p)).length ~= 0
221+
end
222+
return false
223+
end
224+
210225
---------------------------
211226
--- Set animation window
212227
---------------------------
213228

214229
function applyAnimation(leaf)
215-
if type(leaf) ~= 'table' then
216-
leaf = getSelectedGridListLeaf(wndAnim, 'animlist')
217-
if not leaf then
230+
if isPlayerAiming(localPlayer) then
231+
errMsg("You cannot perform animations while actively aiming a weapon!")
232+
return
233+
end
234+
235+
if isPedReloadingWeapon(localPlayer) then
236+
errMsg("You cannot perform animations while reloading a weapon!")
237+
return
238+
end
239+
240+
if type(leaf) ~= "table" then
241+
leaf = getSelectedGridListLeaf(wndAnim, "animlist")
242+
if not leaf or not leaf.parent.name or not leaf.name or string.len(leaf.name) > 25 or string.len(leaf.parent.name) > 25
243+
then errMsg("Invalid animation request")
218244
return
219245
end
220246
end
221247
server.setPedAnimation(localPlayer, leaf.parent.name, leaf.name, true, true)
222248
end
223249

224250
function stopAnimation()
225-
server.setPedAnimation(localPlayer, false)
251+
if getPedAnimation(localPlayer) then
252+
server.setPedAnimation(localPlayer, false)
253+
end
226254
end
227-
addCommandHandler("stopanim", stopAnimation)
255+
addCommandHandler('stopanim', stopAnimation)
228256
bindKey("lshift", "down", stopAnimation)
229257

230258
wndAnim = {
@@ -255,6 +283,22 @@ wndAnim = {
255283

256284
addCommandHandler('anim',
257285
function(command, lib, name)
286+
287+
if not lib or not name then
288+
return errMsg("Invalid animation! Rule of thumb: Provide both library and anim name!")
289+
end
290+
291+
if not tostring(lib) or not tostring(name) then
292+
return errMsg("Invalid animation!")
293+
end
294+
295+
if string.len(lib) > 40 or string.len(name) > 40 then
296+
return errMsg("Invalid animation!")
297+
end
298+
299+
if isPlayerAiming(localPlayer) then errMsg ("You cannot perform animations while actively aiming a weapon!") return end
300+
if isPedReloadingWeapon(localPlayer) then errMsg ("You cannot perform animations while reloading a weapon!") return end
301+
258302
if lib and name and (
259303
(lib:lower() == "finale" and name:lower() == "fin_jump_on") or
260304
(lib:lower() == "finale2" and name:lower() == "fin_cop1_climbout")
@@ -278,20 +322,24 @@ function addWeapon(leaf, amount)
278322
return
279323
end
280324
end
281-
if amount < 1 then
282-
errMsg("Invalid amount")
325+
if amount < 1 or amount > 999999999 or string.len(amount) > 10 then
326+
errMsg("Invalid amount!")
283327
return
284328
end
285329
if isPedReloadingWeapon(localPlayer) then
286330
errMsg ("You can't get weapons while reloading a weapon!")
287-
return
331+
return
332+
end
333+
if isPlayerAiming(localPlayer) then
334+
errMsg ("You can't get weapons while aiming a weapon!")
335+
return
288336
end
289337
server.giveMeWeapon(leaf.id, amount)
290338
end
291339

292340
function isPlayerAiming(p)
293341
if isElement(p) then
294-
if getPedTask(p, "secondary", 0) == "TASK_SIMPLE_USE_GUN" then
342+
if getPedTask(p, "secondary", 0) == "TASK_SIMPLE_USE_GUN" or isPedDoingGangDriveby(p) then
295343
return true
296344
end
297345
end
@@ -323,12 +371,19 @@ wndWeapon = {
323371
}
324372

325373
function giveWeaponCommand(cmd, weapon, amount)
374+
375+
if weapon and string.len(weapon) > 25 then errMsg("Invalid weapon name/ID!") return end
376+
if amount and string.len(amount) > 9 then errMsg("Invalid amount!") return end
377+
326378
weapon = tonumber(weapon) and math.floor(tonumber(weapon)) or weapon and getWeaponIDFromName(weapon) or 0
327-
amount = amount and math.floor(tonumber(amount)) or 1500
328-
if amount < 1 or weapon < 1 or weapon > 46 then return end
379+
amount = tonumber(amount) and math.floor(tonumber(amount)) or 2500
380+
381+
if not weapon then errMsg("Invalid weapon! Syntax: /wp [weapon id/name]") return end
382+
if not amount or amount < 1 or amount > 999999999 or weapon < 1 or weapon > 46 then return end
329383
if internallyBannedWeapons[weapon] then return end
330-
if isPlayerAiming(localPlayer) then errMsg ("You can't use this command while aiming a weapon!") return end
384+
if isPlayerAiming(localPlayer) then errMsg ("You can't get weapons while aiming a weapon or driveby'ing!") return end
331385
if isPedReloadingWeapon(localPlayer) then errMsg ("You can't use this command while reloading a weapon!") return end
386+
if weapon == 39 or weapon == 40 then errMsg ("You can't get Satchels with /wp command! Use F1 > weapons instead!") return end
332387
server.giveMeWeapon(weapon, amount)
333388
end
334389
addCommandHandler('give', giveWeaponCommand)
@@ -340,7 +395,16 @@ addCommandHandler('wp', giveWeaponCommand)
340395

341396
addCommandHandler('setstyle',
342397
function(cmd, style)
343-
style = style and tonumber(style) or 7
398+
style = style and tonumber(style) or 6
399+
400+
if not style then return end
401+
402+
if string.len(style) > 2 or style < 0 or style > 16 then
403+
return errMsg("Invalid style ID!")
404+
end
405+
406+
if getPedFightingStyle(localPlayer) == style then return end
407+
344408
if allowedStyles[style] then
345409
server.setPedFightingStyle(localPlayer, style)
346410
end
@@ -440,6 +504,12 @@ wndClothes = {
440504

441505
function addClothesCommand(cmd, type, model, texture)
442506
type = type and tonumber(type)
507+
508+
if string.len(type) > 30 or string.len(model) > 30 or string.len(texture) > 30 then
509+
errMsg("Invalid clothes input!")
510+
return
511+
end
512+
443513
if type and model and texture then
444514
server.addPedClothes(localPlayer, texture, model, type)
445515
end
@@ -449,7 +519,7 @@ addCommandHandler('ac', addClothesCommand)
449519

450520
function removeClothesCommand(cmd, type)
451521
type = type and tonumber(type)
452-
if type then
522+
if type and string.len(type) < 30 then
453523
server.removePedClothes(localPlayer, type)
454524
end
455525
end
@@ -1102,6 +1172,9 @@ addCommandHandler('getpos', getPosCommand)
11021172
addCommandHandler('gp', getPosCommand)
11031173

11041174
function setPosCommand(cmd, x, y, z, r)
1175+
if isPlayerAiming(localPlayer) then return errMsg ("You can't use /sp while aiming a weapon!") end
1176+
if isPedReloadingWeapon(localPlayer) then return errMsg ("You can't use /sp while reloading a weapon!") end
1177+
11051178
local vehicle = getPedOccupiedVehicle(localPlayer)
11061179
if vehicle then
11071180
local vehModel = getElementModel(vehicle)
@@ -1278,12 +1351,27 @@ wndCreateVehicle = {
12781351
}
12791352

12801353
function createVehicleCommand(cmd, ...)
1354+
12811355
local args = {...}
1282-
vehID = getVehicleModelFromName(table.concat(args," ")) or tonumber(args[1]) and math.floor(tonumber(args[1])) or false
1356+
1357+
if not ... then
1358+
return errMsg("Enter vehicle model please! Syntax: /cv [vehicle ID/name]")
1359+
end
1360+
1361+
vehID = getVehicleModelFromName(table.concat(args, " ")) or tonumber(args[1]) and math.floor(tonumber(args[1])) or false
1362+
1363+
if not vehID or not tostring(vehID) or not tonumber(vehID) then
1364+
return errMsg("Invalid vehicle model!")
1365+
end
1366+
1367+
if string.len(table.concat(args, " ")) > 25 or tonumber(vehID) and string.len(vehID) > 3 then
1368+
return errMsg("Invalid vehicle model!")
1369+
end
1370+
12831371
if vehID and vehID >= 400 and vehID <= 611 then
12841372
server.giveMeVehicles(vehID)
12851373
else
1286-
errMsg("Invalid vehicle model")
1374+
errMsg("Invalid vehicle model!")
12871375
end
12881376
end
12891377
addCommandHandler('createvehicle', createVehicleCommand)
@@ -1462,9 +1550,19 @@ function setColorCommand(cmd, ...)
14621550
if not vehicle then
14631551
return
14641552
end
1465-
local colors = { getVehicleColor(vehicle) }
1466-
local args = { ... }
1467-
for i=1,12 do
1553+
local colors = {getVehicleColor(vehicle)}
1554+
local args = {...}
1555+
1556+
if string.len(...) > 5 or not tonumber(...) then
1557+
return
1558+
end
1559+
1560+
if not ... then
1561+
errMsg("Enter colors please!")
1562+
return
1563+
end
1564+
1565+
for i = 1, 12 do
14681566
colors[i] = args[i] and tonumber(args[i]) or colors[i]
14691567
end
14701568
server.setVehicleColor(vehicle, unpack(colors))
@@ -1498,6 +1596,7 @@ function openColorPicker()
14981596
end
14991597

15001598
function closedColorPicker()
1599+
if not editingVehicle then return end
15011600
local r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4 = getVehicleColor(editingVehicle, true)
15021601
server.setVehicleColor(editingVehicle, r1, g1, b1, r2, g2, b2, r3, g3, b3, r4, g4, b4)
15031602
local r, g, b = getVehicleHeadLightColor(editingVehicle)
@@ -1548,7 +1647,10 @@ function paintjobInit()
15481647
end
15491648

15501649
function applyPaintjob(paint)
1551-
server.setVehiclePaintjob(getPedOccupiedVehicle(localPlayer), paint.id)
1650+
local vehicle = getPedOccupiedVehicle(localPlayer)
1651+
if vehicle and tonumber(paint.id) and string.len(paint.id) == 1 then
1652+
server.setVehiclePaintjob(vehicle, paint.id)
1653+
end
15521654
end
15531655

15541656
wndPaintjob = {
@@ -1582,11 +1684,17 @@ wndPaintjob = {
15821684
}
15831685

15841686
function setPaintjobCommand(cmd, paint)
1687+
15851688
local vehicle = getPedOccupiedVehicle(localPlayer)
1689+
if not vehicle then return end
1690+
15861691
paint = paint and tonumber(paint)
1587-
if not paint or not vehicle then
1588-
return
1692+
1693+
if not paint then return end
1694+
if string.len(paint) > 5 then errMsg("Invalid paintjob ID!")
1695+
return
15891696
end
1697+
15901698
server.setVehiclePaintjob(vehicle, paint)
15911699
end
15921700
addCommandHandler('paintjob', setPaintjobCommand)
@@ -1715,6 +1823,10 @@ wndWeather = {
17151823

17161824
function setWeatherCommand(cmd, weather)
17171825
weather = weather and tonumber(weather)
1826+
if weather and string.len(weather) > 266 then
1827+
errMsg("Invalid weather ID!")
1828+
return
1829+
end
17181830
if weather then
17191831
setWeather(weather)
17201832
end
@@ -1754,7 +1866,7 @@ end
17541866

17551867
function applyGameSpeed()
17561868
speed = getControlNumber(wndGameSpeed, 'speed')
1757-
if speed then
1869+
if speed and tonumber(speed) then
17581870
setMyGameSpeed(speed)
17591871
end
17601872
closeWindow(wndGameSpeed)
@@ -1906,6 +2018,10 @@ end
19062018

19072019
function alphaCommand(command, alpha)
19082020
alpha = alpha and tonumber(alpha) or 255
2021+
if alpha and string.len(alpha) > 3 then
2022+
errMsg("Invalid input!")
2023+
return
2024+
end
19092025
if alpha >= 0 and alpha <= 255 then
19102026
server.setElementAlpha(localPlayer, alpha)
19112027
end
@@ -1996,7 +2112,8 @@ addEventHandler('onClientResourceStart', resourceRoot,
19962112
function()
19972113
fadeCamera(true)
19982114
getPlayers()
1999-
setJetpackMaxHeight ( 9001 )
2115+
setJetpackMaxHeight(9001)
2116+
setAircraftMaxHeight(1600)
20002117
triggerServerEvent('onLoadedAtClient', resourceRoot)
20012118
createWindow(wndMain)
20022119
hideAllWindows()

[gameplay]/freeroam/fr_server.lua

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ end
170170

171171
local function sendSettings(player,settingPlayer,settings)
172172

173+
if not player and isElement(player) then
174+
return
175+
end
176+
173177
for setting,value in pairs(settings) do
174178
triggerClientEvent(player,"onClientFreeroamLocalSettingChange",settingPlayer,setting,value)
175179
end
@@ -252,19 +256,24 @@ addEventHandler('onClothesInit', resourceRoot,
252256
result.playerClothes[type] = {texture = texture, model = model}
253257
end
254258
end
255-
triggerClientEvent(client, 'onClientClothesInit', resourceRoot, result)
259+
if client and isElement(client) then
260+
triggerClientEvent(client, "onClientClothesInit", resourceRoot, result)
261+
end
256262
end
257263
)
258264

259265
addEvent('onPlayerGravInit', true)
260266
addEventHandler('onPlayerGravInit', root,
261267
function()
262268
if client ~= source then return end
263-
triggerClientEvent(client, 'onClientPlayerGravInit', client, getPedGravity(client))
269+
if client and isElement(client) then
270+
triggerClientEvent(client, "onClientPlayerGravInit", client, getPedGravity(client))
271+
end
264272
end
265273
)
266274

267275
function setMySkin(skinid)
276+
if not isElement(source) then return end
268277
if getElementModel(source) == skinid then return end
269278
if isPedDead(source) then
270279
local x, y, z = getElementPosition(source)
@@ -355,6 +364,7 @@ function giveMeWeapon(weapon, amount)
355364
end
356365

357366
function giveMeVehicles(vehID)
367+
if not isElement(source) then return end
358368
local px, py, pz, prot
359369
local element = getPedOccupiedVehicle(source) or source
360370
local px,py,pz = getElementPosition(element)
@@ -431,9 +441,11 @@ addEventHandler('onPlayerChat', root,
431441
lastChatMessage[source] = msg
432442
end
433443
end
434-
local r, g, b = getPlayerNametagColor(source)
435-
outputChatBox(getPlayerName(source) .. ': #FFFFFF' .. msg:gsub('#%x%x%x%x%x%x', ''), root, r, g, b, true)
436-
outputServerLog( "CHAT: " .. getPlayerName(source) .. ": " .. msg )
444+
if isElement(source) then
445+
local r, g, b = getPlayerNametagColor(source)
446+
outputChatBox(getPlayerName(source) .. ': #FFFFFF' .. msg:gsub('#%x%x%x%x%x%x', ''), root, r, g, b, true)
447+
outputServerLog( "CHAT: " .. getPlayerName(source) .. ": " .. msg )
448+
end
437449
end
438450
end
439451
)

0 commit comments

Comments
 (0)