Skip to content

feat: add sqlite account storage and lossless game snapshots - #86

Open
Enn3Developer wants to merge 2 commits into
n/player-abstractionfrom
n/server-persistence
Open

feat: add sqlite account storage and lossless game snapshots#86
Enn3Developer wants to merge 2 commits into
n/player-abstractionfrom
n/server-persistence

Conversation

@Enn3Developer

Copy link
Copy Markdown
Owner

No description provided.

@Enn3Developer Enn3Developer added this to the 0.1.0 milestone Sep 5, 2026
@Enn3Developer Enn3Developer added type: feat New gameplay or feature work area: server OpenPolytopia.Server/ dedicated server area: common OpenPolytopia.Common/ shared library labels Sep 5, 2026
@Enn3Developer Enn3Developer self-assigned this Sep 5, 2026
@claude

claude Bot commented Sep 5, 2026

Copy link
Copy Markdown

Claude finished @Enn3Developer's task in 36s —— View job


Summary

Adds account persistence and lossless game snapshots so the server can survive restarts: a SQLite-backed ServerStore manages accounts/sessions/state, and Game gains snapshot/restore support for saving and reloading in-progress matches.

Changes

  • Common: Game.Persistence.cs adds Game.ToSnapshot()/Game.Restore(...) to capture and rebuild a full match (grid, troops, cities, players, tech tree progress) without re-running normal game setup.
  • Common: GameSnapshot.cs/PlayerSnapshot define the lossless, versioned (CURRENT_VERSION) DTO for a captured game.
  • Common: SnapshotEncoding.cs packs/unpacks the tile and troop arrays to/from little-endian byte blobs for DB storage.
  • Common: Score.cs adds an internal Restore(int) to overwrite a score during game restoration.
  • Server: ServerStore.cs adds a SQLite-backed store for accounts (PBKDF2-hashed passwords), sessions (hashed tokens, 30-day expiry, timing-safe login), and an opaque server-state blob (SaveState/LoadState).
  • Server csproj: adds Microsoft.Data.Sqlite and SQLitePCLRaw.bundle_e_sqlite3 dependencies.
  • Tests: GamePersistenceTest.cs and ServerStoreTest.cs cover snapshot round-tripping/validation and account/session/state behavior.

Worth a look

  • Game.Restore performs extensive validation (version, grid size, player id range/uniqueness, tribe registration, tech node membership, current-turn player existence) — worth checking all failure paths are actually exercised by the new tests.
  • ServerStore schema is versioned via PRAGMA user_version but only has a single migration step (create-from-scratch); there's no upgrade path beyond version 1 yet, which is fine for now but will need attention once the schema changes.
  • server_state is stored as a single opaque row (id=0) — no history/versioning of past states, so a corrupt or unexpected write there is unrecoverable other than via backup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: common OpenPolytopia.Common/ shared library area: server OpenPolytopia.Server/ dedicated server type: feat New gameplay or feature work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant