Skip to content

Persist user units from unit archive#25

Open
Tom2096 wants to merge 3 commits into
decompfrontier:mainfrom
Tom2096:dev-persistent-units
Open

Persist user units from unit archive#25
Tom2096 wants to merge 3 commits into
decompfrontier:mainfrom
Tom2096:dev-persistent-units

Conversation

@Tom2096
Copy link
Copy Markdown

@Tom2096 Tom2096 commented May 26, 2026

Summary

  • add a curated unit archive loaded at server startup from archive_root/unit.json
  • add UserUnitService helpers for inserting and reading DB-backed UserUnitInfo fields
  • seed the first placeholder unit from the archive when a user has no local units
  • enable the user_units migration and generate archive structs from packet-generator

Packet-generator schema PR: decompfrontier/packet-generator#26

Testing

  • cmake --preset debug-win64
  • cmake --build . --config Debug

@Tom2096
Copy link
Copy Markdown
Author

Tom2096 commented May 26, 2026

TLDR:

  • Added a /deploy/archive/unit.json that acts as our unit archive (similar to unit MST, except it has only fields that we understand/uses - extend in the future)
  • Added a UserArchiver global singleton that reads unit.json and supports simple lookup APIs.
  • Added a UserUnitService static class that abstracts away adding/reading units to local SQL
  • Enabled the user units migration

@Tom2096
Copy link
Copy Markdown
Author

Tom2096 commented May 26, 2026

Screenshot 2026-05-26 125249

Working - stats pulled from unit.json

#include <vector>

/*!
* Packet-to-database bridge for packet structs backed by a SQL table.
Copy link
Copy Markdown
Author

@Tom2096 Tom2096 Jun 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts on why I think this is the simplest approach:

  • Schema consistency matters; it is the reason we use the packet generator. Reusing generated packet structs prevents separate database models and network packet models from drifting apart as the codebase evolves.

  • Most database operations are triggered by fields received from the client or used to build a response. Mapping packets directly to database columns lets us read and write those fields without repeatedly implementing fragile conversion logic.

  • Adding new fields to existing databases/new databases is painless: we just define the packet that interacts with the new fields, add the strict compile-time mapping, and the API will handle the rest.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants