Files
core2026/app/game-api/src/auction/open.ts
T
Hide_D 630bc29100 fix: 특수 유저 커맨드의 Ref 호환 경계를 보강한다
수뇌 국가 설정과 NPC 정책을 actor-bound ENGINE mutation으로 옮기고, 추방·등용·점령·멸망·아이템 폐기의 특수 분기를 Ref와 맞춘다.

요청 ID를 사용자·프로필별로 격리하고 토너먼트 손상 projection을 fail-closed하며 실제 DB 및 Ref 차등 회귀를 보강한다.
2026-08-24 12:10:57 +00:00

56 lines
1.8 KiB
TypeScript

import { TRPCError } from '@trpc/server';
import type { GameApiContext } from '../context.js';
import { loadCurrentGameTime } from '../services/gameClock.js';
import { throwIfCommandRejected } from '../router/shared/turnDaemon.js';
import { buildAuctionTimerKeys } from './keys.js';
import { resolveAuctionTimerScore } from './scheduler.js';
export type OpenAuctionInput =
| {
auctionType: 'BUY_RICE' | 'SELL_RICE';
amount: number;
closeTurnCnt: number;
startBidAmount: number;
finishBidAmount: number;
}
| {
auctionType: 'UNIQUE_ITEM';
amount: number;
itemKey: string;
};
export const openAuctionWithDaemon = async (
ctx: GameApiContext,
userId: string,
generalId: number,
input: OpenAuctionInput,
requestId?: string
): Promise<{ auctionId: number; closeAt: string }> => {
const result = await ctx.turnDaemon.requestCommand({
type: 'auctionOpen',
...(requestId ? { requestId } : {}),
userId,
generalId,
...input,
});
throwIfCommandRejected(result);
if (!result || result.type !== 'auctionOpen') {
throw new TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: 'Unexpected response' });
}
if (!result.ok) {
throw new TRPCError({ code: 'BAD_REQUEST', message: result.reason });
}
const timerKeys = buildAuctionTimerKeys(ctx.profile.name);
const closeAt = new Date(result.closeAt);
const gameTime = await loadCurrentGameTime(ctx.db);
await ctx.redis.zAdd(timerKeys.timerKey, [
{ score: resolveAuctionTimerScore(gameTime, closeAt), value: String(result.auctionId) },
]);
return {
auctionId: result.auctionId,
closeAt: result.closeAt,
};
};