Skip to content

Sync: opt-in store_bundles stream for the refining and alliance games stores - #401

Open
blevouschurverantunt wants to merge 2 commits into
STFC-Mod:devfrom
blevouschurverantunt:feature/sync-store-bundles
Open

blevouschurverantunt wants to merge 2 commits into
STFC-Mod:devfrom
blevouschurverantunt:feature/sync-store-bundles

Conversation

@blevouschurverantunt

Copy link
Copy Markdown
Contributor

What changed and why

Builds on #400 (protobuf wire-type fixes), which this needs for Cost.quantity, Bundle.sortOrder and the offer counts. Until that merges, the diff shows both commits; only the second one, 5cd3873, belongs to this PR.

Adds an opt-in sync option, store_bundles, that sends one store_bundle record per store category: the whole current list of bundles in that category. It is off by default, and only targets that enable it receive the records.

The categories are a fixed list: refining_materials, refining_ship_parts and alliance_games. Bundles in any other category are ignored. The data comes from the same platform bundles response that store_offers already reads. store_offers is unchanged.

[sync.targets.example]
store_bundles = true

Record shape, with invented values:

{"type":"store_bundle","category":"refining_materials","bundles":[
  {"bid":30,"sort":7,
   "cost":[{"qty":1,"res":[{"rid":4000000000,"amount":1000}]},
           {"qty":2,"res":[{"rid":4000000000,"amount":2000}]}],
   "req":[],
   "dynamic":[[{"id":21,"kind":"resource","qty":3},{"id":23,"kind":"resource","qty":9}]],
   "static":[{"id":22,"kind":"resource","qty":5}],
   "uses_left":-1,"same_left":-1,
   "valid_from":1700000000,"valid_until":null,"cooldown":false}]}
  • category: one of the three names above.
  • bundles: every bundle in the category, sorted by bundle id.
  • bid, sort: bundle id and sort order.
  • cost: price options in the order the game sends them. Each has qty (how many items that price buys) and res, a list of {rid, amount}.
  • req: requirements, each {type, id, amount}.
  • dynamic: lists of {id, kind, qty}, in wire order. static: one list of {id, kind, qty}.
  • uses_left, same_left: the decoded remaining counts. -1 is unlimited.
  • valid_from, valid_until: epoch seconds, or null when the game sends no time or 0.
  • cooldown: whether a cooldown is configured.
  • Every key is always present, and empty lists are sent as []. Numeric ids are sent as numbers and other ids as strings. No player, account or alliance identifier is included.

How it behaves:

  • A record is sent only when its category's list changes.
  • A response that does not contain a category keeps that category's last record. An empty response removes nothing.
  • Each processor runs only for its own option. The platform response is read when any target has store_offers or store_bundles on, and a target receives only the streams it enables.

Files: src/mod/config.h, src/mod/sync/{records.cc,state.cc,sync.cc,sync.h}, tests/sync_logic.cc, a row in docs/FEATURES.md and the English settings example.

Validation

  • Run locally on Windows with Zig 0.16: zig build mods build-tests -Dtarget=x86_64-windows-msvc, zig build test-sync test-mod test-codegen, the full ReleaseFast DLL build, and zig build fmt.
  • New test in tests/sync_logic.cc, store bundles, checks:
    • bundles and offers are separate events from one response;
    • one event per listed category, other categories ignored;
    • bundles are sorted by id;
    • an exact record for a refining bundle: cost and dynamic order kept, -1 counts, null times;
    • empty arrays are present;
    • seconds stay seconds and a zero time is null;
    • requirements and static contents for an alliance_games bundle;
    • store_offer output is unchanged;
    • an unchanged snapshot sends nothing;
    • a response with one category changes only that category and keeps the others;
    • an empty response removes nothing;
    • a target without store_bundles receives nothing from the stream.
  • In game (Windows, ReleaseFast), against a private sync endpoint, store_bundle records arrived for all three categories. The two refining categories arrive at login. alliance_games arrives when the player opens that store in game. Static item quantities can be -1 (a game sentinel seen on converter bundles); the mod passes it through unchanged.
  • Limits of that test:

Settings and platforms

  • New option store_bundles, off by default, under [sync] and per target. Nothing is sent unless a target opts in.
  • Volume: at most three records, one per category. Each carries the full list for its category and is sent again only when that list changes. Refining records come at login, the alliance_games record when the store is opened.
  • A target that turns the option on mid-session waits for the next store refresh, as with store_offers.
  • The data is read-only and the client already receives it. There is no new hook, server call or game-side action.
  • For sync-site maintainers: a qty of -1 on a static item is the game's own value, passed through unchanged.

🤖 Generated with Claude Code

blevouschurverantunt and others added 2 commits November 25, 2026 20:02
Several declared field types did not match what the game sends, so the
values decoded wrongly or as 0. Corrected, field by field:

- OfferDetails.validCount: int32 -> sint32 (zigzag)
- OfferDetails.sameRemainingCount: int32 -> sint32 (zigzag)
- Bundle.priority: uint32 -> fixed32
- Bundle.sortOrder: uint32 -> fixed32
- Cost.quantity: uint32 -> fixed32
- OrderItem.bundleId: uint32 -> fixed32
- OrderItem.bundleVersion: uint32 -> fixed32
- Resource.amountUlong: uint64 -> fixed64
- UserProfile.level: int32 -> fixed32
- UserProfile.levelLastAwarded: int32 -> fixed32

Visible effect: the store_offer event's valid_count and
same_remaining_count were read doubled (5 available arrived as 10) and
"unlimited" (-1) arrived as 1. They now carry the true values; the keys
are unchanged. The fixed32/fixed64 fields previously read 0. Store offer
prices fall back to Resource.amountUlong when Resource.amount is 0, so an
amount carried only in amountUlong now decodes instead of reading 0. In
the real store snapshots checked, every resource with amountUlong set also
had an equal amount, so prices there are unchanged; faction offers were
not among them.

The own-profile comment in records.cc and sync.h is updated: the record's
level is a fixed32 field and read 0 only because of the wrong type. The
in-memory level is still what the profile stream uses.

Tests decode hand-encoded wire bytes for each corrected field except
OrderItem.bundleId and bundleVersion, which no generated code reads yet,
and check the store_offer counts, including -1.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
New sync option `store_bundles` (default false) and event type
`store_bundle`, read from the same platform Bundles response as
`store_offers`, which is unchanged.

One event per category in a fixed list (refining_materials,
refining_ship_parts, alliance_games), carrying the whole snapshot of that
category's bundles sorted by bundle id. Each bundle has: bid, sort,
cost[{qty, res[{rid, amount}]}], req[{type, id, amount}],
dynamic[[{id, kind, qty}]], static[{id, kind, qty}], uses_left,
same_left, valid_from, valid_until and cooldown. Every key is always
present, cost and dynamic keep wire order, uses_left and same_left are
the decoded counts (-1 is unlimited), and valid_from/valid_until are
epoch seconds or null when the game sends no time or 0. No player,
account or alliance identifier is included.

The platform response is read when either store_offers or store_bundles
is enabled by any target; each processor runs only for its own option and
each target receives only the streams it enables. Unchanged snapshots are
not resent, and a response without a category keeps that category's last
record.

Docs: FEATURES.md row and the English example settings.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

1 participant