feat: 국가 메타 업데이트 기능 추가 및 관련 로직 구현
This commit is contained in:
@@ -282,6 +282,18 @@ const normalizeCommand = (envelope: TurnDaemonCommandEnvelope): TurnDaemonComman
|
||||
top4,
|
||||
};
|
||||
}
|
||||
case 'setNationMeta': {
|
||||
if (typeof command.nationId !== 'number' || !command.updates || typeof command.updates !== 'object') {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
type: 'setNationMeta',
|
||||
requestId: envelope.requestId,
|
||||
nationId: command.nationId,
|
||||
updates: command.updates as Record<string, unknown>,
|
||||
expectedUpdatedAt: typeof command.expectedUpdatedAt === 'string' ? command.expectedUpdatedAt : undefined,
|
||||
};
|
||||
}
|
||||
case 'getStatus': {
|
||||
const requestId = typeof command.requestId === 'string' ? command.requestId : envelope.requestId;
|
||||
return { type: 'getStatus', requestId };
|
||||
|
||||
@@ -41,6 +41,52 @@ interface TournamentRewardFinalizer {
|
||||
finalize(command: Extract<TurnDaemonCommand, { type: 'tournamentReward' }>): Promise<TurnDaemonCommandResult>;
|
||||
}
|
||||
|
||||
async function handleSetNationMeta(
|
||||
ctx: CommandHandlerContext,
|
||||
command: Extract<TurnDaemonCommand, { type: 'setNationMeta' }>
|
||||
): Promise<TurnDaemonCommandResult> {
|
||||
const { world, hooks } = ctx;
|
||||
const nation = world.getNationById(command.nationId);
|
||||
if (!nation) {
|
||||
return {
|
||||
type: 'setNationMeta',
|
||||
ok: false,
|
||||
nationId: command.nationId,
|
||||
reason: '국가 정보를 찾을 수 없습니다.',
|
||||
};
|
||||
}
|
||||
|
||||
const meta = (nation.meta ?? {}) as Record<string, unknown>;
|
||||
const currentUpdatedAt = typeof meta._updatedAt === 'string' ? meta._updatedAt : undefined;
|
||||
if (command.expectedUpdatedAt && currentUpdatedAt && command.expectedUpdatedAt !== currentUpdatedAt) {
|
||||
return {
|
||||
type: 'setNationMeta',
|
||||
ok: false,
|
||||
nationId: command.nationId,
|
||||
reason: 'CONFLICT',
|
||||
currentUpdatedAt,
|
||||
};
|
||||
}
|
||||
|
||||
const updatedAt = new Date().toISOString();
|
||||
const nextMeta = {
|
||||
...meta,
|
||||
...command.updates,
|
||||
_updatedAt: updatedAt,
|
||||
};
|
||||
|
||||
world.updateNation(command.nationId, {
|
||||
meta: nextMeta,
|
||||
});
|
||||
await flushWorld(world, hooks);
|
||||
return {
|
||||
type: 'setNationMeta',
|
||||
ok: true,
|
||||
nationId: command.nationId,
|
||||
updatedAt,
|
||||
};
|
||||
}
|
||||
|
||||
async function handleTroopJoin(
|
||||
ctx: CommandHandlerContext,
|
||||
command: Extract<TurnDaemonCommand, { type: 'troopJoin' }>
|
||||
@@ -614,6 +660,8 @@ export const createTurnDaemonCommandHandler = (options: {
|
||||
return handleTournamentBettingPayout(ctx, command);
|
||||
case 'tournamentReward':
|
||||
return handleTournamentReward(ctx, command);
|
||||
case 'setNationMeta':
|
||||
return handleSetNationMeta(ctx, command);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user