This commit is contained in:
GetParanoid 2025-03-19 09:39:02 -05:00
parent 1d03bf3cd3
commit 7e81d1f0ea
7 changed files with 49 additions and 36 deletions

View File

@ -1,6 +1,6 @@
local ClientConfig = require "config.client"
local _trace = Citizen.Trace local _trace = Citizen.Trace
local errorWords = {"failure", "error", "not", "failed", "not safe", "invalid", "cannot", ".lua", "server", "client", "attempt", "traceback", "stack", "function"}
function error(...) function error(...)
local resource = GetCurrentResourceName() local resource = GetCurrentResourceName()
@ -15,7 +15,7 @@ end
function Citizen.Trace(...) function Citizen.Trace(...)
if type(...) == "string" then if type(...) == "string" then
local args = string.lower(...) local args = string.lower(...)
for _, word in ipairs(errorWords) do for _, word in ipairs(ClientConfig.errorWords) do
if string.find(args, word) then if string.find(args, word) then
error(...) error(...)
return return
@ -23,10 +23,4 @@ function Citizen.Trace(...)
end end
end end
_trace(...) _trace(...)
end end
RegisterCommand('error:trigger', function()
local math = 1 + nil
print(math)
end)

View File

@ -0,0 +1,18 @@
return {
errorWords = {
"failure",
"error",
"not",
"failed",
"not safe",
"invalid",
"cannot",
".lua",
"server",
"client",
"attempt",
"traceback",
"stack",
"function"
}
}

View File

@ -0,0 +1,3 @@
return {
Webhook = 'https://discord.com/api/'
}

View File

View File

@ -1,6 +1,8 @@
---@diagnostic disable: param-type-mismatch ---@diagnostic disable: param-type-mismatch
while not CONFIG_INIT do Wait(100) end print('hof-error/sv/errorLog/CONFIG_INIT') local ServerConfig = require "config.server"
local ServerFunctions = require "server.sv_functions"
local QBX = exports.qbx_core
local LOGGER = require '@qbx_core.modules.logger'
RegisterServerEvent("Error:Server:Report", function(resource, ...) RegisterServerEvent("Error:Server:Report", function(resource, ...)
local src = source local src = source
@ -8,28 +10,30 @@ RegisterServerEvent("Error:Server:Report", function(resource, ...)
errorMessage = errorMessage:gsub("%^%d+", "") errorMessage = errorMessage:gsub("%^%d+", "")
local userName = GetPlayerName(src) local userName = GetPlayerName(src)
local steamID = GetPlayerIdentifierByType(source, 'steam'):gsub('steam:',"") or 'ERROR: STEAM-NOT-FOUND' local steamIdent = GetPlayerIdentifierByType(src, 'steam')
local discordID = GetPlayerIdentifierByType(source, 'discord'):gsub('discord:',"") or 'ERROR: DISCORD-NOT-FOUND' local steamID = (steamIdent and steamIdent:gsub('steam:',"")) or 'ERROR: STEAM-NOT-FOUND'
local discordIdent = GetPlayerIdentifierByType(src, 'discord')
local discordID = (discordIdent and discordIdent:gsub('discord:',"")) or 'ERROR: DISCORD-NOT-FOUND'
local citizenid = QBX:GetPlayer(src).PlayerData.citizenid local citizenid = QBX:GetPlayer(src).PlayerData.citizenid
local ped = GetPlayerPed(src) local ped = GetPlayerPed(src)
local x, y, z = table.unpack(GetEntityCoords(ped)) local x, y, z = table.unpack(GetEntityCoords(ped))
local heading = GetEntityHeading(ped) local heading = GetEntityHeading(ped)
LOGGER.log({ LOGGER.log({
source = citizenid, source = citizenid,
webhook = 'https://discord.com/api/webhooks/', webhook = ServerConfig.Webhook,
event = 'Error:Server:Report', event = 'Error:Server:Report',
color = 'red', color = 'red',
message = string.format("**__Script Error In %s__**", resource) ..'\n'.. message = string.format("**__Script Error In %s__**", resource) ..'\n'..
'---------------------------------------\n'.. '---------------------------------------\n'..
'**__Triggered By:__** \n'.. '**__Triggered By:__** \n'..
'**Username:** '.. userName ..'\n'.. '**Username:** '.. userName ..'\n'..
'**Steam Account:** '.. 'https://steamcommunity.com/profiles/'..steamID(source) ..'\n'.. '**Steam Account:** '.. 'https://steamcommunity.com/profiles/'.. tonumber(steamID, 16) ..'\n'..
'**Discord:** <@'.. discordID ..'> \n'.. '**Discord:** <@'.. discordID ..'> \n'..
'**Source(ID):** '.. src ..'\n'.. '**Source(ID):** '.. src ..'\n'..
'**CitizenID:** '.. citizenid ..'\n'.. '**CitizenID:** '.. citizenid ..'\n'..
'**Coords:** '.. FormatCoords(x,y,z,heading) ..'\n'.. '**Coords:** '.. ServerFunctions.FormatCoords(x,y,z,heading) ..'\n'..
'**Status:** '.. DeadOrLastStand(source) ..'\n'.. '**Status:** '.. ServerFunctions.DeadOrLastStand(src) ..'\n'..
'**Identifiers:** '.. FetchIdentifiers(source)'\n'.. '**Identifiers:** '.. ServerFunctions.FetchIdentifiers(src) .. '\n'..
'---------------------------------------\n'.. '---------------------------------------\n'..
errorMessage.. errorMessage..
'---------------------------------------\n' '---------------------------------------\n'

View File

@ -1,4 +1,6 @@
FormatCoords = function(x,y,z,heading) local QBX = exports.qbx_core
local function FormatCoords(x,y,z,heading)
local formattedX = math.floor(x * 100) / 100 local formattedX = math.floor(x * 100) / 100
local formattedY = math.floor(y * 100) / 100 local formattedY = math.floor(y * 100) / 100
local formattedZ = math.floor(z * 100) / 100 local formattedZ = math.floor(z * 100) / 100
@ -7,7 +9,7 @@ FormatCoords = function(x,y,z,heading)
return formattedString return formattedString
end end
FetchIdentifiers = function (source) local function FetchIdentifiers (source)
local identifiersString = '' local identifiersString = ''
for _, identifier in ipairs(GetPlayerIdentifiers(source)) do for _, identifier in ipairs(GetPlayerIdentifiers(source)) do
@ -18,7 +20,7 @@ FetchIdentifiers = function (source)
return identifiersString return identifiersString
end end
DeadOrLastStand = function (source) local function DeadOrLastStand (source)
local _source = source local _source = source
local Player = QBX:GetPlayer(_source) local Player = QBX:GetPlayer(_source)
local dead = Player.PlayerData.metadata.isDead local dead = Player.PlayerData.metadata.isDead
@ -26,4 +28,10 @@ DeadOrLastStand = function (source)
if dead then return "Player Dead" end if dead then return "Player Dead" end
if laststand then return "Player in Laststand" end if laststand then return "Player in Laststand" end
return "Player Alive" return "Player Alive"
end end
return {
FormatCoords = FormatCoords,
FetchIdentifiers = FetchIdentifiers,
DeadOrLastStand = DeadOrLastStand
}

View File

@ -1,14 +0,0 @@
-- 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