refactor(server/zoneCreator): output format and path, security fix

Don't allow players to trigger ox_lib:saveZone without ace permissions.
Write created_zones to root.
Use explicit vectors and set name as a string.
This commit is contained in:
Linden
2022-09-14 15:19:01 +10:00
parent c95fd8ecf4
commit 3084265bbb

View File

@@ -31,14 +31,14 @@ local parse = {
poly = function(data)
local points = {}
for i = 1, #data.points do
points[#points + 1] = ('\t\tvec(%s, %s, %s),\n'):format((data.points[i].x), (data.points[i].y), data.zCoord)
points[#points + 1] = ('\t\tvec3(%s, %s, %s),\n'):format((data.points[i].x), (data.points[i].y), data.zCoord)
end
local pattern
if printFunction then
pattern = {
'local poly = lib.zones.poly({\n',
('\tname = %s,\n'):format(data.name or 'none'),
('\tname = "%s",\n'):format(data.name or 'none'),
'\tpoints = {\n',
('%s\t},\n'):format(table.concat(points)),
('\tthickness = %s,\n'):format(data.height),
@@ -47,7 +47,7 @@ local parse = {
else
pattern = {
'{\n',
('\tname = %s,\n'):format(data.name or 'none'),
('\tname = "%s",\n'):format(data.name or 'none'),
'\tpoints = {\n',
('%s\t},\n'):format(table.concat(points)),
('\tthickness = %s,\n'):format(data.height),
@@ -62,20 +62,20 @@ local parse = {
if printFunction then
pattern = {
'local box = lib.zones.box({\n',
('\tname = %s,\n'):format(data.name or 'none'),
('\tcoords = vec(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
('\tsize = vec(%s, %s, %s),\n'):format(data.width, data.length, data.height),
('\tname = "%s",\n'):format(data.name or 'none'),
('\tcoords = vec3(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
('\tsize = vec3(%s, %s, %s),\n'):format(data.width, data.length, data.height),
('\trotation = %s,\n'):format(data.heading),
'})\n',
}
else
pattern = {
'{\n',
('\tname = %s,\n'):format(data.name or 'none'),
('\tcoords = vec(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
('\tsize = vec(%s, %s, %s),\n'):format(data.width, data.length, data.height),
('\tname = "%s",\n'):format(data.name or 'none'),
('\tcoords = vec3(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
('\tsize = vec3(%s, %s, %s),\n'):format(data.width, data.length, data.height),
('\trotation = %s,\n'):format(data.heading),
'}\n',
'},\n',
}
end
@@ -86,18 +86,18 @@ local parse = {
if printFunction then
pattern = {
'local sphere = lib.zones.sphere({\n',
('\tname = %s,\n'):format(data.name or 'none'),
('\tcoords = vec(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
('\tname = "%s",\n'):format(data.name or 'none'),
('\tcoords = vec3(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
('\tradius = %s,\n'):format(data.heading),
'})\n',
}
else
pattern = {
'{\n',
('\tname = %s,\n'):format(data.name or 'none'),
('\tcoords = vec(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
('\tname = "%s",\n'):format(data.name or 'none'),
('\tcoords = vec3(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
('\tradius = %s,\n'):format(data.heading),
'}\n',
'},\n',
}
end
@@ -105,12 +105,8 @@ local parse = {
end,
}
local path = GetResourcePath(GetCurrentResourceName()) .. '/resource/zone creator/created_zones.lua'
path = path:gsub('//', '/')
RegisterServerEvent('ox_lib:saveZone', function(data)
local file = io.open(path, 'a')
io.output(file)
local output = parse[data.zoneType](data)
io.write(output)
io.close(file)
RegisterNetEvent('ox_lib:saveZone', function(data)
if not source or not IsPlayerAceAllowed(source, 'command') then return end
local output = (LoadResourceFile(cache.resource, 'created_zones.lua') or '') .. parse[data.zoneType](data)
SaveResourceFile(cache.resource, 'created_zones.lua', output, -1)
end)