Skip to content

Sync: opt-in store_orders stream for refining store purchases - #403

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

blevouschurverantunt wants to merge 3 commits into
STFC-Mod:devfrom
blevouschurverantunt:feature/sync-store-orders

Conversation

@blevouschurverantunt

Copy link
Copy Markdown
Contributor

Builds on #401 (store bundles), which builds on #400 (protobuf wire-type fixes). Until those merge, the diff shows three commits; only the last one, 6978447, belongs to this PR.

What changed and why

Adds an opt-in sync option, store_orders, that sends one store_order record for each purchase order in the refining store categories. It is off by default, and only targets that enable it receive the records.

The game delivers the result of a purchase in two forms, and both are read:

  • a single order: platform entity group OrderVirtualGood, one Order;
  • a list of orders: platform entity group OrdersVirtualGood, an Orders message (repeated Order at field 1). A bulk purchase (a bulk refine) arrives this way: one response holds one order per bundle bought, each with its own order id and items of a single bundle id.

Every order of a list goes through exactly the same rules as a single order. An order that fails a rule is skipped on its own; the other orders of the list are still sent. The records of one response are published together. A payload that cannot be parsed sends nothing. The Order and Orders messages are added to zig/deps/protobuf_roots.txt.

Lists of other, non-refining purchases (for example several orders of other bundles in one response) produce nothing, because their bundles are not in a refining category.

[sync.targets.example]
store_orders = true

Record shape, with invented values:

{"type":"store_order","bid":30,"at":1700000100,"category":"refining_materials","tier":1,
 "paid":[{"rid":4000000000,"amount":2000}],
 "chests":[[{"id":21,"kind":"resource","qty":100},{"id":22,"kind":"resource","qty":5}],
           [{"id":21,"kind":"resource","qty":101},{"id":22,"kind":"resource","qty":5}]]}
  • bid: the bundle id.
  • at: Order.created, epoch seconds.
  • category: refining_materials or refining_ship_parts.
  • tier: the zero-based index of the price entry that was paid, in the order of the bundle's cost list.
  • paid: that price entry's resources, {rid, amount}.
  • chests: one list per order item, each the contents of that item's first customized content set as {id, kind, qty}. An item with no customized content gives [].
  • Every key is always present. One record per order. The order id is not part of the event or of any log line.

How the price is found: the order names the bundle but not the price, so the mod resolves it against the last store_bundle snapshot of the session. The category is the one that lists the bundle. The price is the one cost entry whose qty equals the number of order items. An order is sent only if all of these hold; otherwise the reason is logged at debug level without any id:

  • the order has an id, a creation time and at least one item;
  • the bundle id is non-zero and the same on every item;
  • a snapshot in this session lists the bundle, in a refining category (refining_materials or refining_ship_parts; anything else, such as alliance_games, is never sent);
  • exactly one price entry matches the item count, and it has resources.

The order id only keys the record. An order is not sent again while it is among the 300 most recent orders kept, whether it arrived alone or inside a list. Orders are a journal (delivered one per request, acknowledged per record, never removed by a later response), so an order pruned from it would be sent again if the game repeated its response.

The platform response is read when any of store_offers, store_bundles or store_orders is on. Store bundles are processed when store_bundles or store_orders is on, because orders resolve against them. A target still receives only the streams it enables.

Files: src/mod/config.h, src/mod/sync/{records.cc,state.cc,sync.cc,sync.h}, zig/deps/protobuf_roots.txt, 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 fmt, zig build mods build-tests -Dtarget=x86_64-windows-msvc, zig build test-sync test-mod test-codegen -Dtarget=x86_64-windows-msvc, the full ReleaseFast DLL build, and git diff --check.
  • Tests in tests/sync_logic.cc, store orders (single orders):
    • an order before any bundle snapshot sends nothing;
    • a refine order is sent with the exact record above, and the order id is not in it;
    • a repeated order is not sent again, even after the snapshot it resolves from has changed;
    • an item count that matches no price sends nothing;
    • two prices with the same quantity send nothing;
    • an alliance_games bundle and an unknown bundle send nothing;
    • mixed, zero-id, empty or incomplete orders send nothing;
    • an item without customized content gives an empty chest;
    • an order list handed to the single-order processor does not parse as an order and sends nothing;
    • after 300 newer orders, a pruned order can be sent again and a remembered one is not;
    • a target with only store_orders receives orders but not bundles.
  • Tests in tests/sync_logic.cc, store order lists:
    • a list of three orders of three bundles and different tiers gives three records with the right tier, price, chests and category, the same at, and no order id in any record; the identical list again sends nothing;
    • a list of 60 orders gives 60 records, and the identical list again sends nothing;
    • the same order first as a single result and then inside a list is sent once, and in the other order too;
    • a list mixing a refining order, an order of an unknown bundle, an order of a non-refining bundle, an order with mixed bundle ids and incomplete orders sends only the refining one;
    • an empty list, an empty payload and garbage bytes send nothing and do not crash;
    • an order repeated inside one list is sent once;
    • a target without store_orders receives no orders.
  • The wire types test gains two cases: hand-encoded bytes for OrderItem.bundleId and bundleVersion decode as fixed32, and an Orders message holds repeated orders at field 1.
  • The Drain test helper now collects every record of an upload instead of only the last upload of a type.
  • In game (Windows, ReleaseFast), against a private sync endpoint:
    • A bulk refine over three bundles in the materials store arrived as one OrdersVirtualGood list of three orders, 4 items each. It produced three store_order records, one per bundle: category refining_materials, tier index 2 of quantities 2/3/4, one paid line, 4 chests, the same at.
    • A bulk refine over five bundles in the ship parts store arrived as one list of five orders, with 3, 3, 3, 3 and 4 items. It produced five records, one per bundle: category refining_ship_parts, tier index 2 of quantities 1/2/3 (four orders) and 2/3/4 (one order), the same at.
    • Two bulk refines of one bundle each arrived as lists holding one order, with 9 and 3 items. Each produced one record: tier index 1 of quantities 6/9/12 and tier index 0 of quantities 3/4/5.
    • All ten records were stored by the endpoint exactly once; none was missing and none was doubled.
    • Three single refines, which arrive as OrderVirtualGood, each produced one correct record.

Settings and platforms

  • New option store_orders, off by default, under [sync] and per target. Nothing is sent unless a target opts in.
  • Volume: one record per refining order, sent when the purchase result arrives; a bulk purchase sends one record per order it contains. At most the 300 most recent are kept per session, and orders not yet delivered when a new session starts are dropped. Records are delivered one per request.
  • A request that got no answer is retried, so a record can arrive more than once. A record carries no order id; a repeat is identical, and bid and at together recognise it. This is documented in docs/FEATURES.md.
  • Because prices are resolved from the bundle snapshot, an order bought before the store's bundles were seen in the session is not sent.
  • The data is read-only and the client already receives it. There is no new hook, server call or game-side action.

🤖 Generated with Claude Code

blevouschurverantunt and others added 3 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>
New sync option `store_orders` (default false) and event type
`store_order`: one record per store order in the two refining store
categories, with the bundle, what was paid and what each chest granted.
The game delivers the result of a purchase in two forms, and both are read:
a single order (platform entity group OrderVirtualGood, one Order) and a
list of orders (OrdersVirtualGood, an Orders message), which is how a bulk
purchase arrives. Every order of a list goes through the same rules as a
single order; an order that fails them is skipped on its own and the others
are still sent. The records of one response are published together. The
Order and Orders messages are added to the generated protobuf roots.

Event: bid, at (Order.created, epoch seconds), category, tier, paid
[{rid, amount}] and chests [[{id, kind, qty}]], every key always present.
The order carries the bundle id but not the price, so the event is
resolved against the last store bundle snapshot of the session: the
category is the one listing the bundle (refining_materials or
refining_ship_parts only), the tier is the one cost entry whose quantity
equals the number of order items, and paid is that entry's resources.
Each order item gives one chest from its first customized content set.
An order is only sent when it has an id, a creation time and items, all
items share one non-zero bundle id, the bundle is listed in a refining
category, exactly one price matches the item count and it has resources;
the reason for a skip is logged at debug level without any id. A payload
that cannot be parsed sends nothing.

The order id only keys the record; it is not part of the event or of any
log line. An order is not sent again while it is among the 300 most recent
orders kept, whether it arrived alone or in a list: orders are a journal
(delivered one per request, acknowledged per record, and never removed by
a later response), so an order pruned from it would be sent again if the
game repeated its response. The platform response is read when any of
store_offers, store_bundles or store_orders is enabled, store bundles are
processed when either of the last two is, and each target receives only the
streams it enables.

Docs: a record carries no order id, so a retried record is identical and bid and
at together recognise it; only the 300 most recent orders are kept per
session, undelivered ones are dropped when a new session starts, and an
order is only recorded when the store bundles were received in the same
session.

Tests: single orders and their skip rules; a list of three orders of
different bundles and tiers; a list of 60 orders; the same order as a
single result and inside a list; a list mixing refining, unknown,
non-refining, mixed-bundle and incomplete orders; empty and unparseable
lists; the option off; and the wire types of Orders (repeated field 1) and
OrderItem.bundleId and bundleVersion (fixed32).

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