mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-19 16:06:02 +01:00
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:
@@ -31,14 +31,14 @@ local parse = {
|
|||||||
poly = function(data)
|
poly = function(data)
|
||||||
local points = {}
|
local points = {}
|
||||||
for i = 1, #data.points do
|
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
|
end
|
||||||
|
|
||||||
local pattern
|
local pattern
|
||||||
if printFunction then
|
if printFunction then
|
||||||
pattern = {
|
pattern = {
|
||||||
'local poly = lib.zones.poly({\n',
|
'local poly = lib.zones.poly({\n',
|
||||||
('\tname = %s,\n'):format(data.name or 'none'),
|
('\tname = "%s",\n'):format(data.name or 'none'),
|
||||||
'\tpoints = {\n',
|
'\tpoints = {\n',
|
||||||
('%s\t},\n'):format(table.concat(points)),
|
('%s\t},\n'):format(table.concat(points)),
|
||||||
('\tthickness = %s,\n'):format(data.height),
|
('\tthickness = %s,\n'):format(data.height),
|
||||||
@@ -47,7 +47,7 @@ local parse = {
|
|||||||
else
|
else
|
||||||
pattern = {
|
pattern = {
|
||||||
'{\n',
|
'{\n',
|
||||||
('\tname = %s,\n'):format(data.name or 'none'),
|
('\tname = "%s",\n'):format(data.name or 'none'),
|
||||||
'\tpoints = {\n',
|
'\tpoints = {\n',
|
||||||
('%s\t},\n'):format(table.concat(points)),
|
('%s\t},\n'):format(table.concat(points)),
|
||||||
('\tthickness = %s,\n'):format(data.height),
|
('\tthickness = %s,\n'):format(data.height),
|
||||||
@@ -62,20 +62,20 @@ local parse = {
|
|||||||
if printFunction then
|
if printFunction then
|
||||||
pattern = {
|
pattern = {
|
||||||
'local box = lib.zones.box({\n',
|
'local box = lib.zones.box({\n',
|
||||||
('\tname = %s,\n'):format(data.name or 'none'),
|
('\tname = "%s",\n'):format(data.name or 'none'),
|
||||||
('\tcoords = vec(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
|
('\tcoords = vec3(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
|
||||||
('\tsize = vec(%s, %s, %s),\n'):format(data.width, data.length, data.height),
|
('\tsize = vec3(%s, %s, %s),\n'):format(data.width, data.length, data.height),
|
||||||
('\trotation = %s,\n'):format(data.heading),
|
('\trotation = %s,\n'):format(data.heading),
|
||||||
'})\n',
|
'})\n',
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pattern = {
|
pattern = {
|
||||||
'{\n',
|
'{\n',
|
||||||
('\tname = %s,\n'):format(data.name or 'none'),
|
('\tname = "%s",\n'):format(data.name or 'none'),
|
||||||
('\tcoords = vec(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
|
('\tcoords = vec3(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
|
||||||
('\tsize = vec(%s, %s, %s),\n'):format(data.width, data.length, data.height),
|
('\tsize = vec3(%s, %s, %s),\n'):format(data.width, data.length, data.height),
|
||||||
('\trotation = %s,\n'):format(data.heading),
|
('\trotation = %s,\n'):format(data.heading),
|
||||||
'}\n',
|
'},\n',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -86,18 +86,18 @@ local parse = {
|
|||||||
if printFunction then
|
if printFunction then
|
||||||
pattern = {
|
pattern = {
|
||||||
'local sphere = lib.zones.sphere({\n',
|
'local sphere = lib.zones.sphere({\n',
|
||||||
('\tname = %s,\n'):format(data.name or 'none'),
|
('\tname = "%s",\n'):format(data.name or 'none'),
|
||||||
('\tcoords = vec(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
|
('\tcoords = vec3(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
|
||||||
('\tradius = %s,\n'):format(data.heading),
|
('\tradius = %s,\n'):format(data.heading),
|
||||||
'})\n',
|
'})\n',
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pattern = {
|
pattern = {
|
||||||
'{\n',
|
'{\n',
|
||||||
('\tname = %s,\n'):format(data.name or 'none'),
|
('\tname = "%s",\n'):format(data.name or 'none'),
|
||||||
('\tcoords = vec(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
|
('\tcoords = vec3(%s, %s, %s),\n'):format(data.xCoord, data.yCoord, data.zCoord),
|
||||||
('\tradius = %s,\n'):format(data.heading),
|
('\tradius = %s,\n'):format(data.heading),
|
||||||
'}\n',
|
'},\n',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -105,12 +105,8 @@ local parse = {
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
local path = GetResourcePath(GetCurrentResourceName()) .. '/resource/zone creator/created_zones.lua'
|
RegisterNetEvent('ox_lib:saveZone', function(data)
|
||||||
path = path:gsub('//', '/')
|
if not source or not IsPlayerAceAllowed(source, 'command') then return end
|
||||||
RegisterServerEvent('ox_lib:saveZone', function(data)
|
local output = (LoadResourceFile(cache.resource, 'created_zones.lua') or '') .. parse[data.zoneType](data)
|
||||||
local file = io.open(path, 'a')
|
SaveResourceFile(cache.resource, 'created_zones.lua', output, -1)
|
||||||
io.output(file)
|
|
||||||
local output = parse[data.zoneType](data)
|
|
||||||
io.write(output)
|
|
||||||
io.close(file)
|
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user