fix(game): undo an interrupted script so a character does not lose or replay progress (#143)

* fix(game): make character store writes atomic so concurrent updates are not lost

* fix(game): refuse a scripted move that would leave the map

* fix(game): remember which way a character was facing across a relogin

* fix(game): undo an interrupted script so the next login does not replay it

* docs: record the script rollback and the atomic store writes

* chore(game): cut the script recovery comments back

* fix(game): roll a disconnected script back once, after the battle flush
This commit is contained in:
Fiereu authored and GitHub committed 2026-08-09 13:39:39 +02:00
1 parent 94bf65e208
commit e8baac972c
20 files changed
+540 -105

No files matched your search

@@ -41,6 +41,10 @@ flush immediately, and a disconnect also evicts the character from memory
once its last write succeeded. So the database always trails memory by a few
seconds at most, and only connected players are cached.
Writes are atomic per character, since scripts write from their own coroutine
while packets are answered on another. A write aimed at a character an eviction
already removed is refused and logged rather than dropped quietly.
## Dev data seeding
Dev seed data (the `admin`/`test` accounts, and the developer bit on the
+8 -3
View File
@@ -137,13 +137,18 @@ lock is released even when a script throws.
| Outcome | What happens |
| --- | --- |
| `CancellationException` | Rethrown. Cancellation must not be swallowed. |
| `NotImplementedError` | Logged at info as "Script not ported yet". This is the `TODO("port ...")` stub firing, and it is expected, not a bug. |
| Any other `Exception` | Logged at error with the stack trace. |
| `CancellationException` | Rethrown, and the character is rolled back. Cancellation must not be swallowed. |
| `NotImplementedError` | Logged at info as "Script not ported yet". This is the `TODO("port ...")` stub firing, and it is expected, not a bug. A stub wrote nothing, so nothing is rolled back. |
| Any other `Exception` | Logged at error with the stack trace, and the character is rolled back. |
In all three cases the `finally` closes the dialog, so a broken script leaves the
player able to move rather than stuck in a box.
A rollback puts the character back to the snapshot taken when the script
started. A scene writes its story state as it goes but only advances its scene
var at the end, so a script that never finishes would otherwise leave half its
effects behind and replay the scene on the next login.
## Scripts are per player
Nothing a script does is broadcast. `ScriptMovementService` sends its movement