From 7e81d1f0ea192658790acd730e12c9b707349760 Mon Sep 17 00:00:00 2001 From: GetParanoid Date: Wed, 19 Mar 2025 09:39:02 -0500 Subject: [PATCH] refactor --- client/cl_main.lua | 12 +++--------- config/client.lua | 18 ++++++++++++++++++ config/server.lua | 3 +++ config/shared.lua | 0 server/sv_errorLog.lua | 22 +++++++++++++--------- server/sv_functions.lua | 16 ++++++++++++---- server/sv_main.lua | 14 -------------- 7 files changed, 49 insertions(+), 36 deletions(-) delete mode 100644 config/shared.lua delete mode 100644 server/sv_main.lua diff --git a/client/cl_main.lua b/client/cl_main.lua index 27406b2..6951faa 100644 --- a/client/cl_main.lua +++ b/client/cl_main.lua @@ -1,6 +1,6 @@ +local ClientConfig = require "config.client" 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() @@ -15,7 +15,7 @@ end function Citizen.Trace(...) if type(...) == "string" then local args = string.lower(...) - for _, word in ipairs(errorWords) do + for _, word in ipairs(ClientConfig.errorWords) do if string.find(args, word) then error(...) return @@ -23,10 +23,4 @@ function Citizen.Trace(...) end end _trace(...) -end - - -RegisterCommand('error:trigger', function() - local math = 1 + nil - print(math) -end) \ No newline at end of file +end \ No newline at end of file diff --git a/config/client.lua b/config/client.lua index e69de29..c3d2f51 100644 --- a/config/client.lua +++ b/config/client.lua @@ -0,0 +1,18 @@ +return { + errorWords = { + "failure", + "error", + "not", + "failed", + "not safe", + "invalid", + "cannot", + ".lua", + "server", + "client", + "attempt", + "traceback", + "stack", + "function" + } +} \ No newline at end of file diff --git a/config/server.lua b/config/server.lua index e69de29..86a6e10 100644 --- a/config/server.lua +++ b/config/server.lua @@ -0,0 +1,3 @@ +return { + Webhook = 'https://discord.com/api/' +} \ No newline at end of file diff --git a/config/shared.lua b/config/shared.lua deleted file mode 100644 index e69de29..0000000 diff --git a/server/sv_errorLog.lua b/server/sv_errorLog.lua index 5a41cda..c7bb877 100644 --- a/server/sv_errorLog.lua +++ b/server/sv_errorLog.lua @@ -1,6 +1,8 @@ ---@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, ...) local src = source @@ -8,28 +10,30 @@ RegisterServerEvent("Error:Server:Report", function(resource, ...) 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 steamIdent = GetPlayerIdentifierByType(src, 'steam') + 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 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/', + webhook = ServerConfig.Webhook, 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'.. + '**Steam Account:** '.. 'https://steamcommunity.com/profiles/'.. tonumber(steamID, 16) ..'\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'.. + '**Coords:** '.. ServerFunctions.FormatCoords(x,y,z,heading) ..'\n'.. + '**Status:** '.. ServerFunctions.DeadOrLastStand(src) ..'\n'.. + '**Identifiers:** '.. ServerFunctions.FetchIdentifiers(src) .. '\n'.. '---------------------------------------\n'.. errorMessage.. '---------------------------------------\n' diff --git a/server/sv_functions.lua b/server/sv_functions.lua index e28610a..d0a7175 100644 --- a/server/sv_functions.lua +++ b/server/sv_functions.lua @@ -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 formattedY = math.floor(y * 100) / 100 local formattedZ = math.floor(z * 100) / 100 @@ -7,7 +9,7 @@ FormatCoords = function(x,y,z,heading) return formattedString end -FetchIdentifiers = function (source) +local function FetchIdentifiers (source) local identifiersString = '' for _, identifier in ipairs(GetPlayerIdentifiers(source)) do @@ -18,7 +20,7 @@ FetchIdentifiers = function (source) return identifiersString end -DeadOrLastStand = function (source) +local function DeadOrLastStand (source) local _source = source local Player = QBX:GetPlayer(_source) local dead = Player.PlayerData.metadata.isDead @@ -26,4 +28,10 @@ DeadOrLastStand = function (source) 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 +end + +return { + FormatCoords = FormatCoords, + FetchIdentifiers = FetchIdentifiers, + DeadOrLastStand = DeadOrLastStand +} \ No newline at end of file diff --git a/server/sv_main.lua b/server/sv_main.lua deleted file mode 100644 index 2b5ee96..0000000 --- a/server/sv_main.lua +++ /dev/null @@ -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 \ No newline at end of file