Repository navigation
Description
Summary
The playtime-tracker example never records any playtime. startSession passes a Lua callback as the third argument of exports.oxmysql:scalar_async, which is not a callback parameter, so sessions[src] is never set. In standalone mode, sessions are also started from playerSpawned, an event that only fires on the client.
Where
examples/playtime-tracker/server/main.lua:88-98(startSession,scalar_asynccall)examples/playtime-tracker/server/main.lua:110-114(standaloneAddEventHandler('playerSpawned', ...))examples/playtime-tracker/server/main.lua:56-58(savePlaytimereturns early without a session)examples/playtime-tracker/server/main.lua:138-146(/playtime"still loading" branch)
Details
exports.oxmysql:scalar_async(
'SELECT seconds FROM player_playtime WHERE identifier = ?',
{ identifier },
function(existing)
sessions[src] = { ... }
end
)In oxmysql the _async exports have the signature (query, parameters, invokingResource) and return a promise. The Lua function is treated as the invoking resource name and is never called. Because sessions[src] is never assigned, savePlaytime always returns early, the periodic flush iterates an empty table, nothing is ever written to player_playtime, and /playtime always answers "Playtime is still loading".
Separately, the standalone branch registers AddEventHandler('playerSpawned', ...) in a server script. playerSpawned is raised locally on the client by spawnmanager and is never delivered to the server, so in standalone mode no session would start even after the export call is fixed. Under every framework, players already online when the resource (re)starts are also never tracked until they reconnect.
Impact
The example's single feature does nothing under ESX, QBCore or standalone, and users copying the pattern get silent no-ops. The README says standalone mode is supported.
Steps to reproduce
- Start the resource with oxmysql and the SQL from
examples/playtime-tracker/sql/applied. - Join and wait past
Config.SaveIntervalMinutes. - Run
/playtime: it always shows "Playtime is still loading". Theplayer_playtimetable stays empty. - With
Config.Framework = 'standalone', no session is created on join either.
Suggested fix
- Use the callback export,
exports.oxmysql:scalar(query, params, function(existing) ... end), or load@oxmysql/lib/MySQL.luaand uselocal existing = MySQL.scalar.await(query, params). - Guard the async result so a callback that resolves after the player has dropped does not recreate
sessions[src]. - For standalone, start sessions from the server-side
playerJoiningevent instead ofplayerSpawned. - In an
onResourceStarthandler for this resource, loop overGetPlayers()and start sessions for players already online.
Acceptance criteria
- After joining and waiting one save interval,
player_playtimehas a row for the player and/playtimereports a total. - Standalone mode starts a session on join.
- Restarting the resource resumes tracking for players already online.
- A player who drops before the DB read completes does not leave a stale session.
Getting started
- Relevant files:
examples/playtime-tracker/server/main.lua,examples/playtime-tracker/README.md - How to run checks: there is no test suite yet; run the MCP server with
cd mcp-server && pip install -r requirements.txt && python server.py, and CI checks live in.github/workflows/validate.yml - Related docs:
skills/database-integration/SKILL.md, oxmysql documentation
Filed by repo-audit/full-audit at 701824d. Severity: high. Effort: S. audit-key: bug|examples/playtime-tracker/server/main.lua|scalar_async
Activity
TMHSDigital commentedon Nov 21, 2026
Fixed in 3f2dbb0.
startSession now uses the callback-style
exports.oxmysql:scalarand ignores results for players who dropped or were already loaded; standalone mode starts sessions on the server-side playerJoining event; players already online are picked up on resource start; README example corrected.Verified: Reviewed against the oxmysql export signatures. Not run on a live FXServer (no server available in this environment).