Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(server/player): improve money logging #483

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ local function logPayload(payload)
local tags
local username = 'QBX Logs'
local avatarUrl = 'https://qbox-project.github.io/qbox-duck.png'

if payload.tags then
for i = 1, #payload.tags do
if not tags then tags = '' end
Expand Down Expand Up @@ -138,7 +138,7 @@ end
---@field webhook? string Discord logs only. url of the webhook this log should send to
---@field color? string Discord logs only. what color the message should be
---@field tags? string[] Discord logs only. tags in discord. Example: {'<@%roleid>', '@everyone'}
---@field oxLibTags? string[] -- Tags for ox_lib logger
---@field oxLibTags? string -- Tags for ox_lib logger
solareon marked this conversation as resolved.
Show resolved Hide resolved

---Logs using ox_lib if ox_lib logging is configured. Additionally logs to discord if a web hook is passed.
---@param log Log
Expand Down
22 changes: 16 additions & 6 deletions server/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -718,13 +718,15 @@ function CreatePlayer(playerData, Offline)
if not self.Offline then
self.Functions.UpdatePlayerData()
local tags = amount > 100000 and config.logging.role or nil
local resource = GetInvokingResource() or cache.resource
logger.log({
source = 'qbx_core',
source = resource,
solareon marked this conversation as resolved.
Show resolved Hide resolved
webhook = config.logging.webhook['playermoney'],
event = 'AddMoney',
color = 'lightgreen',
tags = tags,
message = ('**%s (citizenid: %s | id: %s)** $%s (%s) added, new %s balance: $%s reason: %s'):format(GetPlayerName(self.PlayerData.source), self.PlayerData.citizenid, self.PlayerData.source, amount, moneytype, moneytype, self.PlayerData.money[moneytype], reason),
--oxLibTags = ('script:%s,playerName:%s,citizenId:%s,playerSource:%s,amount:%s,moneyType:%s,newBalance:%s,reason:%s'):format(resource, GetPlayerName(self.PlayerData.source), self.PlayerData.citizenid, self.PlayerData.source, amount, moneytype, self.PlayerData.money[moneytype], reason)
})
TriggerClientEvent('hud:client:OnMoneyChange', self.PlayerData.source, moneytype, amount, false)
TriggerClientEvent('QBCore:Client:OnMoneyChange', self.PlayerData.source, moneytype, amount, 'add', reason)
Expand Down Expand Up @@ -755,13 +757,15 @@ function CreatePlayer(playerData, Offline)
if not self.Offline then
self.Functions.UpdatePlayerData()
local tags = amount > 100000 and config.logging.role or nil
local resource = GetInvokingResource() or cache.resource
logger.log({
source = 'qbx_core',
source = resource,
webhook = config.logging.webhook['playermoney'],
event = 'RemoveMoney',
color = 'red',
tags = tags,
message = ('** %s (citizenid: %s | id: %s)** $%s (%s) removed, new %s balance: $%s reason: %s'):format(GetPlayerName(self.PlayerData.source), self.PlayerData.citizenid, self.PlayerData.source, amount, moneytype, moneytype, self.PlayerData.money[moneytype], reason),
--oxLibTags = ('script:%s,playerName:%s,citizenId:%s,playerSource:%s,amount:%s,moneyType:%s,newBalance:%s,reason:%s'):format(resource, GetPlayerName(self.PlayerData.source), self.PlayerData.citizenid, self.PlayerData.source, amount, moneytype, self.PlayerData.money[moneytype], reason)
})
TriggerClientEvent('hud:client:OnMoneyChange', self.PlayerData.source, moneytype, amount, true)
if moneytype == 'bank' then
Expand All @@ -788,14 +792,20 @@ function CreatePlayer(playerData, Offline)

if not self.Offline then
self.Functions.UpdatePlayerData()
local dirChange = difference < 0 and 'added' or 'removed'
local absDifference = math.abs(difference)
local tags = absDifference > 50000 and config.logging.role or {}
local resource = GetInvokingResource() or cache.resource
logger.log({
source = 'qbx_core',
source = resource,
webhook = config.logging.webhook['playermoney'],
event = 'SetMoney',
color = 'green',
message = ('**%s (citizenid: %s | id: %s)** $%s (%s) set, new %s balance: $%s reason: %s'):format(GetPlayerName(self.PlayerData.source), self.PlayerData.citizenid, self.PlayerData.source, amount, moneytype, moneytype, self.PlayerData.money[moneytype], reason),
color = difference < 0 and 'green' or 'red',
tags = tags,
message = ('**%s (citizenid: %s | id: %s)** $%s (%s) %s, new %s balance: $%s reason: %s'):format(GetPlayerName(self.PlayerData.source), self.PlayerData.citizenid, self.PlayerData.source, absDifference, moneytype, dirChange, moneytype, self.PlayerData.money[moneytype], reason),
--oxLibTags = ('script:%s,playerName:%s,citizenId:%s,playerSource:%s,amount:%s,moneyType:%s,newBalance:%s,reason:%s,direction:%s'):format(resource, GetPlayerName(self.PlayerData.source), self.PlayerData.citizenid, self.PlayerData.source, absDifference, moneytype, self.PlayerData.money[moneytype], reason, dirChange)
})
TriggerClientEvent('hud:client:OnMoneyChange', self.PlayerData.source, moneytype, math.abs(difference), difference < 0)
TriggerClientEvent('hud:client:OnMoneyChange', self.PlayerData.source, moneytype, absDifference, difference < 0)
TriggerClientEvent('QBCore:Client:OnMoneyChange', self.PlayerData.source, moneytype, amount, 'set', reason)
TriggerEvent('QBCore:Server:OnMoneyChange', self.PlayerData.source, moneytype, amount, 'set', reason)
end
Expand Down