diff --git a/config.json b/config.json index dff7961..9fbef97 100644 --- a/config.json +++ b/config.json @@ -27,6 +27,10 @@ "oxInventoryEvents": { "enabled": true, "dataset": "default" + }, + "esxCoreEvents": { + "enabled": false, + "dataset": "default" } } } \ No newline at end of file diff --git a/config.schema.json b/config.schema.json index 654eedb..578039c 100644 --- a/config.schema.json +++ b/config.schema.json @@ -132,6 +132,23 @@ } }, "default": { "enabled": false, "dataset": "default" } + }, + "esxCoreEvents": { + "description": "ESX core (es_extended) events configuration.", + "type": "object", + "properties": { + "enabled": { + "description": "Enable ESX core events to be logged.", + "type": "boolean", + "default": false + }, + "dataset": { + "description": "Dataset to use for ESX core events.", + "type": "string", + "default": "default" + } + }, + "default": { "enabled": false, "dataset": "default" } } }, "required": [ @@ -144,7 +161,8 @@ "playerEvents", "chatEvents", "txAdminEvents", - "oxInventoryEvents" + "oxInventoryEvents", + "esxCoreEvents" ] } }, diff --git a/features/logs/server/logger.ts b/features/logs/server/logger.ts index e8fa588..163cc3a 100644 --- a/features/logs/server/logger.ts +++ b/features/logs/server/logger.ts @@ -20,6 +20,7 @@ import './chat'; import './txadmin' import './baseevents' import './third-party/ox-inventory' +import './third-party/esx-core' const levels = config.logs.levels.reduce>( (acc, curr, idx) => { diff --git a/features/logs/server/third-party/esx-core.ts b/features/logs/server/third-party/esx-core.ts new file mode 100644 index 0000000..43a28f2 --- /dev/null +++ b/features/logs/server/third-party/esx-core.ts @@ -0,0 +1,182 @@ +import { config } from "~/utils/common/config"; +import { ingest } from "../logger"; + +if (config.logs.esxCoreEvents?.enabled) { + const dataset = config.logs.esxCoreEvents.dataset; + + // Player lifecycle + + onNet( + "esx:playerLoaded", + ( + playerId: number, + xPlayer: { job?: unknown; accounts?: unknown; identifier?: string }, + ) => { + const playerName = GetPlayerName(playerId.toString()); + ingest( + dataset, + "info", + `player ${playerName} loaded`, + { + playerSource: playerId, + playerName, + job: xPlayer?.job, + identifier: xPlayer?.identifier, + }, + { _internal_RESOURCE: "es_extended" }, + ); + }, + ); + + onNet("esx:playerSpawned", (playerId: number) => { + const playerName = GetPlayerName(playerId.toString()); + ingest( + dataset, + "info", + `player ${playerName} spawned`, + { + playerSource: playerId, + playerName, + }, + { _internal_RESOURCE: "es_extended" }, + ); + }); + + // Job changes + + onNet( + "esx:setJob", + ( + playerId: number, + job: { name: string; label: string; grade: number; grade_label: string }, + lastJob: { name: string; label: string; grade: number }, + ) => { + const playerName = GetPlayerName(playerId.toString()); + ingest( + dataset, + "info", + `player ${playerName} job changed to ${job.name}`, + { + playerSource: playerId, + playerName, + job: { + name: job.name, + label: job.label, + grade: job.grade, + gradeLabel: job.grade_label, + }, + previousJob: { + name: lastJob.name, + label: lastJob.label, + grade: lastJob.grade, + }, + }, + { _internal_RESOURCE: "es_extended" }, + ); + }, + ); + + // Inventory changes (built-in esx_inventory, NOT ox_inventory) + + onNet( + "esx:addInventoryItem", + (playerId: number, itemName: string, itemCount: number) => { + const playerName = GetPlayerName(playerId.toString()); + ingest( + dataset, + "info", + `player ${playerName} received item ${itemName} x${itemCount}`, + { + playerSource: playerId, + playerName, + itemName, + itemCount, + action: "add", + }, + { _internal_RESOURCE: "es_extended" }, + ); + }, + ); + + onNet( + "esx:removeInventoryItem", + (playerId: number, itemName: string, itemCount: number) => { + const playerName = GetPlayerName(playerId.toString()); + ingest( + dataset, + "info", + `player ${playerName} lost item ${itemName} x${itemCount}`, + { + playerSource: playerId, + playerName, + itemName, + itemCount, + action: "remove", + }, + { _internal_RESOURCE: "es_extended" }, + ); + }, + ); + + // Account money changes + + onNet( + "esx:addAccountMoney", + (playerId: number, accountName: string, money: number) => { + const playerName = GetPlayerName(playerId.toString()); + ingest( + dataset, + "info", + `player ${playerName} received $${money} in account ${accountName}`, + { + playerSource: playerId, + playerName, + accountName, + amount: money, + action: "add", + }, + { _internal_RESOURCE: "es_extended" }, + ); + }, + ); + + onNet( + "esx:removeAccountMoney", + (playerId: number, accountName: string, money: number) => { + const playerName = GetPlayerName(playerId.toString()); + ingest( + dataset, + "info", + `player ${playerName} lost $${money} from account ${accountName}`, + { + playerSource: playerId, + playerName, + accountName, + amount: money, + action: "remove", + }, + { _internal_RESOURCE: "es_extended" }, + ); + }, + ); + + onNet( + "esx:setAccountMoney", + (playerId: number, accountName: string, money: number) => { + const playerName = GetPlayerName(playerId.toString()); + ingest( + dataset, + "info", + `player ${playerName} account ${accountName} set to $${money}`, + { + playerSource: playerId, + playerName, + accountName, + amount: money, + action: "set", + }, + { _internal_RESOURCE: "es_extended" }, + ); + }, + ); +} diff --git a/features/utils/common/config.ts b/features/utils/common/config.ts index 2f2ceaf..becc778 100644 --- a/features/utils/common/config.ts +++ b/features/utils/common/config.ts @@ -29,6 +29,7 @@ const ConfigSchema = object({ chatEvents: EventConfigSchema, txAdminEvents: EventConfigSchema, oxInventoryEvents: EventConfigSchema, + esxCoreEvents: EventConfigSchema, }), });