Server-authoritative economy: wire client to server; entry + rewards on hub
Server: - daily (/api/daily, /api/daily/claim) + shop (/api/shop/buy) + ChargeEntry - GameRoom (via IServiceScopeFactory) deducts ranked entry at match start and applies match rewards at match-over, broadcasting profile + reward over the hub - tested: daily, shop (owned-guard), ranked entry deduction pushed over hub Client: - SignalrService routes profile/coins/plan/daily/shop/match to the server (Bearer); onProfile/onReward hub events; guest/offline fall back to local - session-store syncs profile from hub; game-store serverReward; GameScreen shows live ranked reward from hub (no double submit), submits client-run games - single source of truth in live mode (no economy divergence) Postgres-ready via config (Provider=postgres); EnsureCreated for now. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+13
-1
@@ -12,7 +12,7 @@ import {
|
||||
startNextRound,
|
||||
} from "./hokm/engine";
|
||||
import { Card, GameState, Phase, Player, Rank, RoundResult, Seat, Suit, Team } from "./hokm/types";
|
||||
import { avatarEmoji, ServerGameState } from "./online/types";
|
||||
import { avatarEmoji, RewardResult, ServerGameState } from "./online/types";
|
||||
import type { OnlineService } from "./online/service";
|
||||
import { sound } from "./sound";
|
||||
|
||||
@@ -76,6 +76,8 @@ interface GameStore {
|
||||
|
||||
/** true when the match is driven by the live SignalR server. */
|
||||
live: boolean;
|
||||
/** reward pushed by the server for a server-run (ranked) match. */
|
||||
serverReward: RewardResult | null;
|
||||
|
||||
newMatch: (settings: GameSettings) => void;
|
||||
newOnlineMatch: (cfg: OnlineMatchConfig) => void;
|
||||
@@ -90,6 +92,7 @@ const AI_AVATARS = ["🦊", "🦁", "🦉", "🐯"];
|
||||
|
||||
let pending: ReturnType<typeof setTimeout> | null = null;
|
||||
let liveUnsub: (() => void) | null = null;
|
||||
let rewardUnsub: (() => void) | null = null;
|
||||
let liveSvc: OnlineService | null = null;
|
||||
function clearPending() {
|
||||
if (pending) {
|
||||
@@ -289,6 +292,7 @@ export const useGameStore = create<GameStore>((set, get) => {
|
||||
disconnectedSeat: null,
|
||||
reconnectDeadline: null,
|
||||
live: false,
|
||||
serverReward: null,
|
||||
|
||||
newMatch: (settings) => {
|
||||
clearPending();
|
||||
@@ -340,12 +344,15 @@ export const useGameStore = create<GameStore>((set, get) => {
|
||||
sound.init();
|
||||
liveSvc = service;
|
||||
if (liveUnsub) liveUnsub();
|
||||
if (rewardUnsub) rewardUnsub();
|
||||
liveUnsub = service.onState((s) => get().applyServerState(s));
|
||||
rewardUnsub = service.onReward((r) => set({ serverReward: r }));
|
||||
set({
|
||||
game: createInitialState({ names: ["شما", "", "", ""], targetScore: 7 }),
|
||||
started: true,
|
||||
mode: "online",
|
||||
live: true,
|
||||
serverReward: null,
|
||||
matchMeta: { ranked: true, stake: 0 },
|
||||
tally: freshTally(),
|
||||
turnDeadline: null,
|
||||
@@ -417,12 +424,17 @@ export const useGameStore = create<GameStore>((set, get) => {
|
||||
liveUnsub();
|
||||
liveUnsub = null;
|
||||
}
|
||||
if (rewardUnsub) {
|
||||
rewardUnsub();
|
||||
rewardUnsub = null;
|
||||
}
|
||||
liveSvc = null;
|
||||
set({
|
||||
game: createInitialState({ names: ["", "", "", ""], targetScore: 7 }),
|
||||
started: false,
|
||||
mode: "ai",
|
||||
live: false,
|
||||
serverReward: null,
|
||||
seatPlayers: [],
|
||||
tally: freshTally(),
|
||||
turnDeadline: null,
|
||||
|
||||
Reference in New Issue
Block a user