The entire progression backend (Elo rating, XP, gold, card shards, match
history, leaderboard) was unreachable for every real match played over the
only working transport ("local" SESSION_PROVIDER). POST /matches/:id/complete
requires MATCH_SERVER_SECRET, a secret no Unity client holds — and
MatchStateController.Finish() was a bare TODO that never called anything.
A fully played real match (host simulates, king tower falls, Finish() runs)
just vanished: no rating change, no XP/gold, no shards, no history entry.
Fix: add POST /sessions/:id/complete (JWT-authed), callable only by the
session's deterministic host (sessionStore.hostPlayerId) — the one client
that actually ran the authoritative simulation. It validates the reported
participants are exactly this session's participants, rejects an invalid
result pairing (e.g. both players "win"), and derives deckId/trophiesDelta
server-side rather than trusting them from the request. Internally it reuses
the same completeMatch() logic the trusted-server route already used (match
recording refactored into a shared function in modules/matches/index.ts).
Wired the Unity side for real: MatchStateController now raises
OnMatchFinished from Finish(), NetworkBootstrap exposes the joined SessionId,
and MatchSimulationController reports the result via the new
SessionClient.CompleteMatch on the host only.
Also closes a related matchmaking gap found while probing this: nothing
stopped a player from calling /matchmaking/queue again while already
matched into a live session, silently abandoning whoever they were paired
with (that opponent's session would never get a second participant and had
no way to detect or recover from it). /matchmaking/queue now rejects a
re-queue while an existing ticket's session is still live
(409 already_in_match), and /sessions/:id/complete clears both participants'
tickets on a successful completion so they're immediately free to queue for
a real next match instead of waiting out the session's 1h TTL.
Verified for real: real local Postgres + Redis, real `npx tsx src/index.ts`,
real HTTP + WS clients (two guest signups, deck create, queue, matcher-tick
pairing, WS relay connect, host/guest role assignment) driving the actual
new endpoints end to end — confirmed rating/XP/gold/shards/leaderboard/match
history all land correctly on a host-reported win/loss, confirmed the guest
cannot report, confirmed idempotent replay returns 409, confirmed an invalid
result pairing is rejected, confirmed the re-queue guard blocks the
ghost-opponent scenario and reproduced it being blocked, and confirmed both
players are freed to queue again right after a real completion. 115 unit +
14 integration tests still green, `tsc --noEmit` clean. Unity-side changes
verified by hand (brace/paren balance, call-site/type cross-check) — no
Unity Editor/dotnet/mono available in this sandbox.
Siegebreak Unity client
The fuller Siegebreak client scaffold (FPS-hero + tower-push) toward the PRD
vision. This is separate from the shipped MVP under the repo-root Assets/
(a runtime-generated Clash-Royale-like); see the root README.md
and DEVELOPMENT.md.
Requires the Unity editor to build/run (Unity 6 LTS). It is not covered by the repo's automated CI gates.
Backend SDK — Assets/Scripts/Services/
A working integration layer against the Node backend in ../services.
It uses only Unity built-ins (UnityWebRequest, JsonUtility,
System.Net.WebSockets) — no extra packages.
| File | Role |
|---|---|
BackendConfig |
REST base URL + ws(s):// subscribe URL builder. Default http://localhost:8080; override via BackendGateway's inspector field or SetBaseUrl. |
SessionStore |
Access/refresh token holder, persisted in PlayerPrefs. |
HttpApi |
UnityWebRequest GET/POST with JSON, bearer auth, and one transparent refresh+retry on 401. Awaitable. |
Dtos / JsonHelper |
JsonUtility-serializable API mirrors; array (de)serialization helper. |
AuthClient |
LoginGuest (device-bound) / LoginApple / LoginGoogle / Logout. |
MatchmakingClient |
QueueForMatch / CancelQueue / GetStatus. |
SessionClient |
GetSession(id) → allocated room + realtime provider. |
PlayerClient |
GetMe (progression + record) / GetMatchHistory. |
EconomyClient |
GetProducts / GetWallet / ValidatePurchase. |
MatchSubscription |
Real-time WS /matchmaking/subscribe; off-thread receive loop drained on the main thread via Update(). |
BackendGateway |
MonoBehaviour facade owning the clients + subscription; drives the subscription pump each frame. |
Usage
Drop a BackendGateway on a boot object (optionally set its API base URL), then:
var gw = BackendGateway.Instance;
// 1. Authenticate (tokens persist across launches).
if (!gw.IsAuthenticated)
await gw.Auth.LoginGuest();
// 2. Subscribe for the real-time match push, then queue.
gw.Subscription.OnMatched += sessionId => OnMatchFound(sessionId);
await gw.Subscription.Connect();
await gw.Matchmaking.QueueForMatch(deckId);
// 3. Poll is the backstop if the socket is unavailable.
var ticket = await gw.Matchmaking.GetStatus();
if (ticket != null && ticket.IsMatched)
OnMatchFound(ticket.sessionId);
// 4. Resolve the allocated room and hand it to the transport.
async void OnMatchFound(string sessionId)
{
await GetComponent<Siegebreak.Networking.NetworkBootstrap>()
.JoinMatch(sessionId, region: "eu");
}
The backend is authoritative for currency: EconomyClient.ValidatePurchase
returns null if the store receipt fails verification — never credit locally.
Local backend
cd ../services
docker compose up -d postgres redis
cp .env.example .env # IAP_MODE=dev is set for local purchase testing
npx prisma migrate deploy && npm run seed
npm run dev # http://localhost:8080