Skip to content

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

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

Enn3Developer wants to merge 2 commits into
masterfrom
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 37s —— View job


Summary

Adds persistence for the server: a SQLite-backed ServerStore for accounts/sessions/state, and a lossless snapshot format so an in-progress Game can be saved and restored across server restarts.

Changes

  • common: Game.ToSnapshot() / Game.Restore() capture and rebuild all mutable game state (grid tiles, troops, cities, players, turn/score/researched techs) while re-deriving static content (tribes, tech tree shape, definitions) from the caller.
  • common: GameSnapshot/PlayerSnapshot DTOs plus SnapshotEncoding for little-endian packing of tile/troop/city arrays into BLOBs, versioned via GameSnapshot.CURRENT_VERSION.
  • common: Score.Restore(int) added to let Game.Restore set a score directly instead of only accumulating via AddScore.
  • server: New ServerStore (SQLite via Microsoft.Data.Sqlite) handling account registration/login/session resume/logout (PBKDF2 password hashing, SHA-256 session tokens, timing-safe compare) and an opaque SaveState/LoadState blob for server state.
  • server: OpenPolytopia.Server.csproj adds Microsoft.Data.Sqlite and SQLitePCLRaw.bundle_e_sqlite3 package references.
  • tests: New GamePersistenceTest.cs and ServerStoreTest.cs covering snapshot round-tripping, restore validation errors, and store account/session behavior.

Worth a look

  • Game.Restore throws on many malformed-snapshot cases (version mismatch, bad grid size, unknown tribe/tech, dangling turn holder) — worth confirming all validation paths are exercised by the new tests.
  • ServerStore schema is versioned (SCHEMA_VERSION = 1) but Migrate() only creates the initial schema; there's no upgrade path yet for future schema changes.
  • SaveState/LoadState treat the server state as an opaque string blob with no versioning of its own, unlike the game snapshot format.

Base automatically changed from n/player-abstraction to master September 6, 2026 18:02
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