refactor
This commit is contained in:
parent
1d03bf3cd3
commit
7e81d1f0ea
@ -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
|
||||
@ -24,9 +24,3 @@ function Citizen.Trace(...)
|
||||
end
|
||||
_trace(...)
|
||||
end
|
||||
|
||||
|
||||
RegisterCommand('error:trigger', function()
|
||||
local math = 1 + nil
|
||||
print(math)
|
||||
end)
|
||||
@ -0,0 +1,18 @@
|
||||
return {
|
||||
errorWords = {
|
||||
"failure",
|
||||
"error",
|
||||
"not",
|
||||
"failed",
|
||||
"not safe",
|
||||
"invalid",
|
||||
"cannot",
|
||||
".lua",
|
||||
"server",
|
||||
"client",
|
||||
"attempt",
|
||||
"traceback",
|
||||
"stack",
|
||||
"function"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
return {
|
||||
Webhook = 'https://discord.com/api/'
|
||||
}
|
||||
@ -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'
|
||||
|
||||
@ -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
|
||||
@ -27,3 +29,9 @@ DeadOrLastStand = function (source)
|
||||
if laststand then return "Player in Laststand" end
|
||||
return "Player Alive"
|
||||
end
|
||||
|
||||
return {
|
||||
FormatCoords = FormatCoords,
|
||||
FetchIdentifiers = FetchIdentifiers,
|
||||
DeadOrLastStand = DeadOrLastStand
|
||||
}
|
||||
@ -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
|
||||
Loading…
Reference in New Issue
Block a user