mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-06 12:53:44 +00:00
Every character gets a save generation in charxml. A world bumps it when it loads the character for play, and every save from that world only goes through while the stored generation is still the one it loaded or last saved (and moves it on). Dashboard edits, restores and maintenance writes bump it too. A world that lost the character to another world (a disconnect noticed late, a zone transfer, an instance migration) or to a dashboard edit can no longer overwrite the newer data: the save is refused, logged and audited as stale_save_refused, the world stops saving that character and a player still connected to it is disconnected with the save failure reason so they reload. Fixes #639 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 lines
624 B
SQL
9 lines
624 B
SQL
/* Stale save guard: bumped whenever a world loads a character to play it, a world saves it or the dashboard writes it.
|
|
A world only saves over the generation it loaded or last saved; an older world's save is refused. Only added when
|
|
it is not there yet. */
|
|
SET @dlu_column = (SELECT IF(COUNT(*) = 0, 'ALTER TABLE charxml ADD COLUMN save_generation BIGINT NOT NULL DEFAULT 0', 'DO 0') FROM information_schema.columns
|
|
WHERE table_schema = DATABASE() AND table_name = 'charxml' AND column_name = 'save_generation');
|
|
PREPARE dlu_column_stmt FROM @dlu_column;
|
|
EXECUTE dlu_column_stmt;
|
|
DEALLOCATE PREPARE dlu_column_stmt;
|