merge: 최신 main을 transport 권한과 durable 검증에 최종 통합한다
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { enqueuePrivateMessageWebPush, GamePrisma } from '@sammo-ts/infra';
|
||||
import type { MessagePayload, MessageRecordDraft, MessageType } from '@sammo-ts/logic';
|
||||
|
||||
import type { DatabaseClient } from '../context.js';
|
||||
import { loadCurrentGameTime } from '../services/gameClock.js';
|
||||
import { enqueuePrivateMessageWebPush } from '@sammo-ts/infra';
|
||||
|
||||
export interface MessageView {
|
||||
id: number;
|
||||
@@ -203,3 +203,26 @@ export const invalidateMessages = async (db: DatabaseClient, ids: number[]): Pro
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const tombstoneMessages = async (db: DatabaseClient, ids: number[]): Promise<void> => {
|
||||
const uniqueIds = Array.from(new Set(ids.filter((id) => Number.isInteger(id) && id > 0)));
|
||||
if (uniqueIds.length === 0) return;
|
||||
|
||||
await db.$executeRaw(
|
||||
GamePrisma.sql`
|
||||
UPDATE message
|
||||
SET message = jsonb_set(
|
||||
jsonb_set(message, '{text}', to_jsonb(${'삭제된 메시지입니다.'}::text), true),
|
||||
'{option}',
|
||||
(
|
||||
CASE
|
||||
WHEN jsonb_typeof(message->'option') = 'object' THEN message->'option'
|
||||
ELSE '{}'::jsonb
|
||||
END
|
||||
) || jsonb_build_object('invalid', true),
|
||||
true
|
||||
)
|
||||
WHERE id IN (${GamePrisma.join(uniqueIds)})
|
||||
`
|
||||
);
|
||||
};
|
||||
|
||||
@@ -56,6 +56,7 @@ const zGeneralSettings = z.object({
|
||||
use_treatment: z.number().int().optional(),
|
||||
use_auto_nation_turn: z.number().int().optional(),
|
||||
use_auto_nation_diplomacy: z.number().int().min(0).max(1).optional(),
|
||||
use_auto_nation_war: z.number().int().min(0).max(1).optional(),
|
||||
use_auto_nation_promotion: z.number().int().min(0).max(1).optional(),
|
||||
use_auto_nation_finance: z.number().int().min(0).max(1).optional(),
|
||||
use_auto_nation_capital: z.number().int().min(0).max(1).optional(),
|
||||
@@ -218,6 +219,7 @@ const resolveUserSettings = (meta: Record<string, unknown>) => {
|
||||
// Ref가 NPC 군주에게만 수행하던 국가 운영은 사용자 군주에게 opt-in이다.
|
||||
// 누락된 값은 신규 게임과 기존 장수 모두 안전한 기본값(사용 안함)으로 해석한다.
|
||||
use_auto_nation_diplomacy: readNumber(readSetting('use_auto_nation_diplomacy'), 0),
|
||||
use_auto_nation_war: readNumber(readSetting('use_auto_nation_war'), 0),
|
||||
use_auto_nation_promotion: readNumber(readSetting('use_auto_nation_promotion'), 0),
|
||||
use_auto_nation_finance: readNumber(readSetting('use_auto_nation_finance'), 0),
|
||||
use_auto_nation_capital: readNumber(readSetting('use_auto_nation_capital'), 0),
|
||||
@@ -693,7 +695,13 @@ export const getGeneralContext = async (ctx: GameApiContext) => {
|
||||
export const generalRouter = router({
|
||||
adjustIcon: engineAuthedProcedure
|
||||
.input(
|
||||
z.object({ iconId: z.string().uuid().optional(), clientRequestId: z.string().uuid().optional() }).optional()
|
||||
z
|
||||
.object({
|
||||
iconId: z.string().uuid().optional(),
|
||||
resetToDefault: z.literal(true).optional(),
|
||||
clientRequestId: z.string().uuid().optional(),
|
||||
})
|
||||
.optional()
|
||||
)
|
||||
.mutation(({ ctx, input }) => {
|
||||
const userId = ctx.auth?.user.id;
|
||||
@@ -701,19 +709,41 @@ export const generalRouter = router({
|
||||
throw new TRPCError({ code: 'UNAUTHORIZED' });
|
||||
}
|
||||
const selected = input?.iconId ? ctx.auth?.user.icons?.find((icon) => icon.id === input.iconId) : undefined;
|
||||
if (input?.iconId && (!selected || ctx.auth?.user.canUseGeneralPicture === false)) {
|
||||
const resetToDefault = input?.resetToDefault === true;
|
||||
if (resetToDefault && input?.iconId) {
|
||||
throw new TRPCError({ code: 'BAD_REQUEST', message: '아이콘 선택과 기본 아이콘 초기화를 함께 요청할 수 없습니다.' });
|
||||
}
|
||||
if (!resetToDefault && !input?.iconId) {
|
||||
throw new TRPCError({ code: 'BAD_REQUEST', message: '적용할 활성 전용 아이콘을 선택해 주세요.' });
|
||||
}
|
||||
if (
|
||||
resetToDefault &&
|
||||
(ctx.auth?.user.picture !== 'default.jpg' || ctx.auth?.user.imageServer !== 0)
|
||||
) {
|
||||
throw new TRPCError({ code: 'FORBIDDEN', message: '현재 계정 아이콘이 기본 아이콘이 아닙니다.' });
|
||||
}
|
||||
if (!resetToDefault && (!selected || ctx.auth?.user.canUseGeneralPicture === false)) {
|
||||
throw new TRPCError({ code: 'FORBIDDEN', message: '사용 가능한 내 전용 아이콘이 아닙니다.' });
|
||||
}
|
||||
const iconRevision = ctx.auth?.user.iconUpdatedAt ?? (resetToDefault ? undefined : selected!.createdAt);
|
||||
if (!iconRevision) {
|
||||
throw new TRPCError({ code: 'PRECONDITION_FAILED', message: '계정 아이콘 변경 시각을 확인할 수 없습니다.' });
|
||||
}
|
||||
const projection = resetToDefault
|
||||
? {
|
||||
picture: 'default.jpg',
|
||||
imageServer: 0,
|
||||
revision: iconRevision,
|
||||
}
|
||||
: {
|
||||
picture: selected!.picture,
|
||||
imageServer: selected!.imageServer,
|
||||
revision: iconRevision,
|
||||
};
|
||||
return adjustAccountIconForUser(
|
||||
ctx,
|
||||
userId,
|
||||
selected
|
||||
? {
|
||||
picture: selected.picture,
|
||||
imageServer: selected.imageServer,
|
||||
revision: ctx.auth?.user.iconUpdatedAt ?? selected.createdAt,
|
||||
}
|
||||
: undefined,
|
||||
projection,
|
||||
true,
|
||||
input?.clientRequestId ?? ctx.requestId
|
||||
);
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
WAR_TRAIT_KEYS,
|
||||
} from '@sammo-ts/logic';
|
||||
import { readInheritancePoint, resolveInheritConstants } from '../../services/inheritance.js';
|
||||
import { loadAuthoritativeAccountIcon } from '../../services/accountIconSync.js';
|
||||
import { loadCurrentGameTime } from '../../services/gameClock.js';
|
||||
import { getSelectionPoolStatus, resolveSelectionMaxGeneral } from '@sammo-ts/game-engine/turn/selectPoolService.js';
|
||||
import {
|
||||
@@ -515,15 +514,17 @@ export const joinRouter = router({
|
||||
if (input.iconId && (!selectedIcon || auth.user.canUseGeneralPicture === false)) {
|
||||
throw new TRPCError({ code: 'FORBIDDEN', message: '사용 가능한 내 전용 아이콘이 아닙니다.' });
|
||||
}
|
||||
const accountIcon = input.pic
|
||||
? selectedIcon
|
||||
// 유저 장수에는 인증 token의 활성 전용 아이콘을 명시적으로 고른 경우만
|
||||
// 그림을 적용한다. Gateway 대표 그림은 shared preset일 수 있으므로
|
||||
// iconId 없는 fallback으로 사용하지 않는다.
|
||||
const accountIcon =
|
||||
input.pic && selectedIcon
|
||||
? {
|
||||
picture: selectedIcon.picture,
|
||||
imageServer: selectedIcon.imageServer,
|
||||
revision: auth.user.iconUpdatedAt ?? selectedIcon.createdAt,
|
||||
}
|
||||
: await loadAuthoritativeAccountIcon(ctx, userId)
|
||||
: null;
|
||||
: null;
|
||||
const commandRequestId = resolveJoinCreateRequestId(ctx.requestId, userId, input.clientRequestId);
|
||||
const result = await requestJoinCreateCommand(ctx, {
|
||||
type: 'joinCreateGeneral',
|
||||
@@ -535,7 +536,7 @@ export const joinRouter = router({
|
||||
leadership: input.leadership,
|
||||
strength: input.strength,
|
||||
intel: input.intel,
|
||||
pic: input.pic,
|
||||
pic: accountIcon !== null,
|
||||
character: input.character,
|
||||
profileId: ctx.profile.id,
|
||||
...(accountIcon
|
||||
|
||||
@@ -19,8 +19,8 @@ import {
|
||||
fetchMessagesFromMailbox,
|
||||
fetchOldMessagesFromMailbox,
|
||||
fetchMessageById,
|
||||
invalidateMessages,
|
||||
insertMessage,
|
||||
tombstoneMessages,
|
||||
type MessageView,
|
||||
} from '../../messages/store.js';
|
||||
import { getOwnedGeneral } from '../shared/general.js';
|
||||
@@ -40,11 +40,7 @@ const redactDiplomacyMessages = (messages: MessageView[], permission: number): M
|
||||
}
|
||||
return {
|
||||
...message,
|
||||
text: '(외교 메시지입니다)',
|
||||
option: {
|
||||
...(message.option ?? {}),
|
||||
invalid: true,
|
||||
},
|
||||
text: '조회 권한이 없는 외교 메시지입니다.',
|
||||
};
|
||||
});
|
||||
};
|
||||
@@ -303,7 +299,7 @@ export const messagesRouter = router({
|
||||
message.id,
|
||||
...(shouldDeleteReceiverCopy && typeof receiverMessageId === 'number' ? [receiverMessageId] : []),
|
||||
];
|
||||
await invalidateMessages(ctx.db, ids);
|
||||
await tombstoneMessages(ctx.db, ids);
|
||||
const receiverMailbox =
|
||||
shouldDeleteReceiverCopy && typeof receiverMessageId === 'number' && message.msgType === 'private'
|
||||
? message.payload.dest.generalId
|
||||
|
||||
@@ -153,11 +153,17 @@ export const getPersonnelInfo = accessAuthedProcedure.query(async ({ ctx }) => {
|
||||
const canChangePermissions = me.officerLevel === 12;
|
||||
const ambassadors = canChangePermissions
|
||||
? permissionCandidates.filter(
|
||||
(candidate) => candidate.permission === 'ambassador' || candidate.maxPermission === 4
|
||||
(candidate) =>
|
||||
candidate.permission === 'ambassador' ||
|
||||
(candidate.permission === 'normal' && candidate.maxPermission === 4)
|
||||
)
|
||||
: [];
|
||||
const auditors = canChangePermissions
|
||||
? permissionCandidates.filter((candidate) => candidate.permission === 'auditor' || candidate.maxPermission >= 3)
|
||||
? permissionCandidates.filter(
|
||||
(candidate) =>
|
||||
candidate.permission === 'auditor' ||
|
||||
(candidate.permission === 'normal' && candidate.maxPermission >= 3)
|
||||
)
|
||||
: [];
|
||||
const generalNameMap = new Map(mappedGenerals.map((general) => [general.id, general.name]));
|
||||
const awards = {
|
||||
|
||||
@@ -433,7 +433,6 @@ export const voteRouter = router({
|
||||
)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const general = await getMyGeneral(ctx);
|
||||
const openerName = ctx.auth?.user.username ?? general.name;
|
||||
const options = normalizeOptions(input.options);
|
||||
if (options.length === 0) {
|
||||
throw new TRPCError({ code: 'BAD_REQUEST', message: '항목이 없습니다.' });
|
||||
@@ -488,7 +487,7 @@ export const voteRouter = router({
|
||||
${multipleOptions},
|
||||
${input.revealMode},
|
||||
${general.id},
|
||||
${openerName},
|
||||
${general.name},
|
||||
${gameTime.now},
|
||||
${gameTime.tick === null ? null : BigInt(gameTime.tick)},
|
||||
${endAt},
|
||||
|
||||
@@ -40,7 +40,7 @@ export const loadAuthoritativeAccountIcon = async (
|
||||
export const adjustAccountIconForUser = async (
|
||||
ctx: GameApiContext,
|
||||
userId: string,
|
||||
selected?: AccountIconProjection,
|
||||
selected: AccountIconProjection,
|
||||
enforceCooldown = true,
|
||||
requestKey?: string
|
||||
): Promise<{
|
||||
@@ -48,10 +48,8 @@ export const adjustAccountIconForUser = async (
|
||||
generalId: number | null;
|
||||
updated: boolean;
|
||||
}> => {
|
||||
const projection = selected ?? (await loadAuthoritativeAccountIcon(ctx, userId));
|
||||
const requestId = selected
|
||||
? `general:adjustIcon:${userId}:manual:${requestKey ?? `${projection.revision}:${encodeURIComponent(projection.picture)}`}`
|
||||
: `general:adjustIcon:${userId}:${projection.revision}`;
|
||||
const projection = selected;
|
||||
const requestId = `general:adjustIcon:${userId}:manual:${requestKey ?? `${projection.revision}:${encodeURIComponent(projection.picture)}`}`;
|
||||
try {
|
||||
const result = await ctx.turnDaemon.requestCommand({
|
||||
type: 'adjustGeneralIcon',
|
||||
|
||||
Reference in New Issue
Block a user