feat(core): add database player concurrency lock to prevent web/game race conditions - #908
Open
berrytern wants to merge 8 commits into
Open
feat(core): add database player concurrency lock to prevent web/game race conditions#908berrytern wants to merge 8 commits into
berrytern wants to merge 8 commits into
Conversation
berrytern
force-pushed
the
feat/player-concurrency-lock
branch
from
August 19, 2026 02:12
36ae6ef to
fd68403
Compare
Collaborator
|
you missing update db_version in schema.sql, and now have a small conflict in configmanager, fix ir please |
Open
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When external web applications (such as Account Access Controls - AACs, Web Shops, Character Bazaars, or custom administration APIs) perform transactional modifications on character data (e.g. updating stats, modifying skills, delivering depot items, deleting characters, or transferring ownership), a critical race condition occurs if the player attempts to log into the game client at the same time.
Currently, if a player connects while the database row is being mutated, the C++ engine loads the stale/intermediate state into RAM memory. Upon subsequent player save or logout, the RAM memory overwrites the database, causing item duplication, currency rollback, or data corruption.
This PR introduces an atomic, non-blocking Player Concurrency Lock mechanism directly in
IOLoginDataLoad::preLoadPlayer:togglePlayerLockandplayerLockTimeout(deadman switch / auto-healing).(is_locked, locked_at)for sub-millisecond query execution.Behaviour
Actual
savePlayeroverwrites the database with RAM state, leading to rollbacks and item duplication exploits.Expected
is_locked = 1andtime(nullptr) - locked_at < timeout,preLoadPlayerimmediately aborts the login handshake with zero RAM allocations.is_locked = 0), the player logs in normally and receives updated data.playerLockTimeout(default: 60s) without server intervention.Type of change
How Has This Been Tested
Test A: Lock active prevents character login
UPDATE players SET is_locked = 1, locked_at = UNIX_TIMESTAMP(), lock_reason = 'web_trade' WHERE id = 4;Player Paladin Sample login rejected: character is currently locked for a web/market transaction (reason: web_trade)Test B: Auto-healing / Expired Lock TTL (>60s) allows login
UPDATE players SET is_locked = 1, locked_at = UNIX_TIMESTAMP() - 120, lock_reason = 'crashed_web_op' WHERE id = 4;