100 lines
2.3 KiB
Lua
100 lines
2.3 KiB
Lua
local type = type
|
|
|
|
local table_pack = table.pack
|
|
local table_unpack = table.unpack
|
|
|
|
local coroutine_running = coroutine.running
|
|
|
|
--[[ Custom extensions --]]
|
|
local msgpack = msgpack
|
|
local msgpack_pack = msgpack.pack
|
|
local msgpack_unpack = msgpack.unpack
|
|
|
|
local Citizen = Citizen
|
|
local Citizen_InvokeFunctionReference = Citizen.InvokeFunctionReference
|
|
|
|
local isDuplicityVersion = IsDuplicityVersion()
|
|
|
|
local boundaryIdx = 1
|
|
|
|
local function dummyUseBoundary(idx)
|
|
return nil
|
|
end
|
|
|
|
local function getBoundaryFunc(bfn, bid)
|
|
return function(fn, ...)
|
|
local boundary = bid
|
|
if not boundary then
|
|
boundary = boundaryIdx + 1
|
|
boundaryIdx = boundary
|
|
end
|
|
|
|
bfn(boundary, coroutine_running())
|
|
|
|
local wrap = function(...)
|
|
dummyUseBoundary(boundary)
|
|
|
|
local v = table_pack(fn(...))
|
|
return table_unpack(v)
|
|
end
|
|
|
|
local v = table_pack(wrap(...))
|
|
|
|
bfn(boundary, nil)
|
|
|
|
return table_unpack(v)
|
|
end
|
|
end
|
|
|
|
local runWithBoundaryEnd = getBoundaryFunc(Citizen.SubmitBoundaryEnd)
|
|
|
|
local rpcEvName = ('__cfx_rpcReq')
|
|
|
|
local prefix = 'fivepd:'
|
|
|
|
RegisterNetEvent(rpcEvName)
|
|
|
|
AddEventHandler(rpcEvName, function(retEvent, retId, refId, args)
|
|
if string.sub(refId, 1, #prefix) ~= prefix then
|
|
print(('^1RPC request from %s: invalid reference ID: %s^0'):format(source, refId))
|
|
return
|
|
end
|
|
|
|
local source = source
|
|
|
|
local eventTriggerFn = TriggerServerEvent
|
|
|
|
if isDuplicityVersion then
|
|
eventTriggerFn = function(name, ...)
|
|
TriggerClientEvent(name, source, ...)
|
|
end
|
|
end
|
|
|
|
local returnEvent = function(args, err)
|
|
eventTriggerFn(retEvent, retId, args, err)
|
|
end
|
|
|
|
runWithBoundaryEnd(function()
|
|
local payload = Citizen_InvokeFunctionReference(refId, msgpack_pack(args))
|
|
|
|
if #payload == 0 then
|
|
returnEvent(false, 'err')
|
|
return
|
|
end
|
|
|
|
local rvs = msgpack_unpack(payload)
|
|
|
|
if type(rvs[1]) == 'table' and rvs[1].__cfx_async_retval then
|
|
rvs[1].__cfx_async_retval(returnEvent)
|
|
else
|
|
returnEvent(rvs)
|
|
end
|
|
end)
|
|
end)
|
|
|
|
if isDuplicityVersion then
|
|
for _ = 1, 5 do
|
|
print('^1By using this resource you acknowledge that this server will be vulnerable to RCE attacks.^0')
|
|
end
|
|
end
|