-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinit-server.lua
More file actions
91 lines (72 loc) · 2.82 KB
/
init-server.lua
File metadata and controls
91 lines (72 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
-- Store the original functions
local originalAddEventHandler = AddEventHandler
local originalExports = exports
-- Not needed since RegisterNetEvent proxies to AddEventHandler
-- local originalRegisterNetEvent = RegisterNetEvent
-- Create a function to handle the monkey patching
local function monkeyPatchEventHandler(originalFunc, event, callback)
-- Create a wrapper function that calls the original callback and triggers an event
local wrappedCallback = function(...)
local source = source
-- Call the original callback
local success, error = pcall(callback, ...)
-- Do not log exports
if string.find(event, "^__cfx_export_") then return end
local data = {
event = event,
source = source,
invoking_resource = GetInvokingResource(),
error = error
}
if source ~= "" and GetResourceState('qbx_core') == 'started' then
local citizenId = nil
if Player(source) and Player(source).state and Player(source).state.isLoggedIn then
local player = exports['qbx_core']:GetPlayer(source)
citizenId = player and player.PlayerData and player.PlayerData.citizenid or nil
if citizenId then
data.citizen_id = citizenId
end
end
end
TriggerEvent('kifflom_log:server:event:trigger', data, ...)
end
-- Register with the wrapped callback
return originalFunc(event, wrappedCallback)
end
AddEventHandler = function(name, callback)
return monkeyPatchEventHandler(originalAddEventHandler, name, callback)
end
-- Create a function to handle the monkey patching for creating exports
-- Exports are created as such:
-- exports('name', function() end)
-- Exports are called as such:
-- exports['resourceName']:functionName()
-- exports.resourceName.functionName()
-- This functionality should be preserved
local resourceName = GetCurrentResourceName()
-- Create a proxy for export creation
exports = setmetatable({}, {
__call = function(_, functionName, exportFunction)
-- Create a wrapped function that logs calls to this export
local wrappedFunction = function(...)
local invokingResource = GetInvokingResource() or 'unknown'
local data = {
resource = resourceName,
function_name = functionName,
invoking_resource = invokingResource
}
pcall(function(...)
TriggerEvent('kifflom_log:server:export:call', data, ...)
end, ...)
-- Call the original export function and return its results
return exportFunction(...)
end
-- Register the wrapped function with the original exports system
return originalExports(functionName, wrappedFunction)
end,
-- Handle accessing exports from other resources (exports['resourceName'] or exports.resourceName)
__index = function(_, key)
return originalExports[key]
end
})
local originalTriggerClientEvent = TriggerClientEvent