commit 1d03bf3cd39b9040c64cee0d8a79ac5a3a237138 Author: GetParanoid Date: Mon Feb 24 17:04:19 2025 -0600 Move to public repo diff --git a/client/cl_main.lua b/client/cl_main.lua new file mode 100644 index 0000000..27406b2 --- /dev/null +++ b/client/cl_main.lua @@ -0,0 +1,32 @@ +local _trace = Citizen.Trace + +local errorWords = {"failure", "error", "not", "failed", "not safe", "invalid", "cannot", ".lua", "server", "client", "attempt", "traceback", "stack", "function"} + +function error(...) + local resource = GetCurrentResourceName() + print(string.format("----- RESOURCE ERROR -----")) + print(...) + print(string.format("------ PLEASE REPORT THIS TO STAFF ------")) + print(string.format("------ IDEALLY WITH CLIPS & SCREENSHOTS OF WHAT YOU'RE DOING ------")) + TriggerServerEvent("Error:Server:Report", resource, ...) +end + +---@diagnostic disable-next-line: duplicate-set-field +function Citizen.Trace(...) + if type(...) == "string" then + local args = string.lower(...) + for _, word in ipairs(errorWords) do + if string.find(args, word) then + error(...) + return + end + end + end + _trace(...) +end + + +RegisterCommand('error:trigger', function() + local math = 1 + nil + print(math) +end) \ No newline at end of file diff --git a/config/client.lua b/config/client.lua new file mode 100644 index 0000000..e69de29 diff --git a/config/server.lua b/config/server.lua new file mode 100644 index 0000000..e69de29 diff --git a/config/shared.lua b/config/shared.lua new file mode 100644 index 0000000..e69de29 diff --git a/fxmanifest.lua b/fxmanifest.lua new file mode 100644 index 0000000..8cc0499 --- /dev/null +++ b/fxmanifest.lua @@ -0,0 +1,30 @@ +---@diagnostic disable: undefined-global +fx_version 'cerulean' +games {'gta5'} +lua54 'yes' +author 'GetParanoid' +description '' +version '1.0.0' + + +shared_scripts { + '@ox_lib/init.lua', + '@qbx_core/modules/lib.lua', +} + +client_script { + '@qbx_core/modules/playerdata.lua', + "client/*.lua", +} +server_script { + "@oxmysql/lib/MySQL.lua", + "server/*.lua", +} + +files { + 'config/client.lua', + 'config/shared.lua', +} + +lua54 'yes' +use_experimental_fxv2_oal 'yes' \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..5d27201 --- /dev/null +++ b/readme.md @@ -0,0 +1,8 @@ +# Error Logging + +Automatic client side error logs for QBX + +Just add `client_script "@hof-errors/client/cl_main.lua"` to any script's fxmanifest you want to integrate with + + +Add webhook to server/sv_errorLog.lua \ No newline at end of file diff --git a/server/sv_errorLog.lua b/server/sv_errorLog.lua new file mode 100644 index 0000000..5a41cda --- /dev/null +++ b/server/sv_errorLog.lua @@ -0,0 +1,37 @@ +---@diagnostic disable: param-type-mismatch +while not CONFIG_INIT do Wait(100) end print('hof-error/sv/errorLog/CONFIG_INIT') + + +RegisterServerEvent("Error:Server:Report", function(resource, ...) + local src = source + local errorMessage = ... + errorMessage = errorMessage:gsub("%^%d+", "") + + local userName = GetPlayerName(src) + local steamID = GetPlayerIdentifierByType(source, 'steam'):gsub('steam:',"") or 'ERROR: STEAM-NOT-FOUND' + local discordID = GetPlayerIdentifierByType(source, 'discord'):gsub('discord:',"") or 'ERROR: DISCORD-NOT-FOUND' + local citizenid = QBX:GetPlayer(src).PlayerData.citizenid + local ped = GetPlayerPed(src) + local x, y, z = table.unpack(GetEntityCoords(ped)) + local heading = GetEntityHeading(ped) + LOGGER.log({ + source = citizenid, + webhook = 'https://discord.com/api/webhooks/', + event = 'Error:Server:Report', + color = 'red', + message = string.format("**__Script Error In %s__**", resource) ..'\n'.. + '---------------------------------------\n'.. + '**__Triggered By:__** \n'.. + '**Username:** '.. userName ..'\n'.. + '**Steam Account:** '.. 'https://steamcommunity.com/profiles/'..steamID(source) ..'\n'.. + '**Discord:** <@'.. discordID ..'> \n'.. + '**Source(ID):** '.. src ..'\n'.. + '**CitizenID:** '.. citizenid ..'\n'.. + '**Coords:** '.. FormatCoords(x,y,z,heading) ..'\n'.. + '**Status:** '.. DeadOrLastStand(source) ..'\n'.. + '**Identifiers:** '.. FetchIdentifiers(source)'\n'.. + '---------------------------------------\n'.. + errorMessage.. + '---------------------------------------\n' + }) +end) \ No newline at end of file diff --git a/server/sv_functions.lua b/server/sv_functions.lua new file mode 100644 index 0000000..e28610a --- /dev/null +++ b/server/sv_functions.lua @@ -0,0 +1,29 @@ +FormatCoords = function(x,y,z,heading) + local formattedX = math.floor(x * 100) / 100 + local formattedY = math.floor(y * 100) / 100 + local formattedZ = math.floor(z * 100) / 100 + local formattedHeading = math.floor(heading * 100) / 100 + local formattedString = formattedX .. ', '.. formattedY .. ', '.. formattedZ .. ', H: '..formattedHeading + return formattedString +end + +FetchIdentifiers = function (source) + + local identifiersString = '' + for _, identifier in ipairs(GetPlayerIdentifiers(source)) do + identifiersString = identifiersString .. '\n'..identifier + end + identifiersString = identifiersString .. '\n' + + return identifiersString +end + +DeadOrLastStand = function (source) + local _source = source + local Player = QBX:GetPlayer(_source) + local dead = Player.PlayerData.metadata.isDead + local laststand = Player.PlayerData.metadata.inLaststand + if dead then return "Player Dead" end + if laststand then return "Player in Laststand" end + return "Player Alive" +end \ No newline at end of file diff --git a/server/sv_main.lua b/server/sv_main.lua new file mode 100644 index 0000000..2b5ee96 --- /dev/null +++ b/server/sv_main.lua @@ -0,0 +1,14 @@ +-- Initialize configuration status +_G.CONFIG_INIT = false + +local server_config = require 'config.server' +local shared_config = require 'config.shared' +_G.LOGGER = require '@qbx_core.modules.logger' + +_G.SERVER_CONFIG = server_config +_G.SHARED_CONFIG = shared_config + +_G.QBX = exports.qbx_core + +-- Mark configuration as initialized +_G.CONFIG_INIT = true \ No newline at end of file