feat: Ref 호환 접속 제한과 벌점 초기화 구현

실행 중인 프로필에서만 접속 벌점을 누적하고 제한 임계값과 대상 경로를 Ref 순서에 맞춘다. 자기 턴 명령 성공 시 순간 점수를 같은 flush에서 초기화하며 월간 누적 감쇠는 유지한다. 제한 중 메인 자동 갱신과 실시간 구독을 중지하고 수동 갱신 성공 시 복구한다.
This commit is contained in:
2026-08-15 18:49:41 +00:00
parent a99f8166eb
commit 48d94e5ff2
29 changed files with 982 additions and 232 deletions
@@ -914,6 +914,7 @@ export const createDatabaseTurnHooks = async (
let persistedVisibleLogs: PersistedVisibleLogRow[] = [];
let visibleLogFloor = directLogFloor;
const {
accessScoreResetGeneralIds,
generals,
cities,
nations,
@@ -1012,6 +1013,13 @@ export const createDatabaseTurnHooks = async (
world.gameTickToDate(state.clockTick ?? state.lastTurnTick ?? 0)
);
if (accessScoreResetGeneralIds.length > 0) {
await prisma.generalAccessLog.updateMany({
where: { generalId: { in: accessScoreResetGeneralIds } },
data: { refreshScore: 0 },
});
}
if (inheritancePointAdjustments.length > 0) {
const grouped = new Map<string, { userId: string; key: string; amount: number }>();
for (const entry of inheritancePointAdjustments) {
@@ -2,7 +2,7 @@ import type { TurnCheckpoint, TurnProcessor, TurnRunBudget, TurnRunResult } from
import { getNextTickTime } from '../lifecycle/getNextTickTime.js';
import type { InMemoryTurnWorld } from './inMemoryWorld.js';
import type { TurnGeneral } from './types.js';
import { asNumber, asRecord } from '@sammo-ts/common';
import { asNumber, asRecord, calculateAccessRefreshLimit } from '@sammo-ts/common';
export interface InMemoryTurnProcessorOptions {
tickMinutes?: number;
@@ -50,6 +50,9 @@ export class InMemoryTurnProcessor implements TurnProcessor {
const isBudgetExpired = () => Date.now() >= deadlineMs;
this.world.setCheckpoint(checkpoint);
this.world.updateWorldMeta({
refreshLimit: calculateAccessRefreshLimit(this.world.getState().tickSeconds),
});
let processedGenerals = 0;
let processedTurns = 0;
@@ -97,6 +100,9 @@ export class InMemoryTurnProcessor implements TurnProcessor {
if (executionError !== undefined) {
throw executionError;
}
// Ref의 updateTurnTime()은 장수 명령이 성공한 뒤 그 장수의
// 순간 벌점을 같은 턴 flush에서 초기화한다.
this.world.markGeneralAccessScoreReset(general.id);
processedGenerals += 1;
nextCheckpoint = {
turnTime: executedAt.toISOString(),
+16
View File
@@ -115,6 +115,7 @@ export interface InMemoryGameClockState {
}
export interface TurnWorldChanges {
accessScoreResetGeneralIds: number[];
generals: TurnGeneral[];
cities: City[];
nations: Nation[];
@@ -156,6 +157,7 @@ export interface InMemoryTurnWorldStateSnapshot {
dirtyNationIds: number[];
dirtyTroopIds: number[];
dirtyDiplomacyKeys: string[];
accessScoreResetGeneralIds: number[];
createdGeneralIds: number[];
createdNationIds: number[];
createdTroopIds: number[];
@@ -419,6 +421,7 @@ export class InMemoryTurnWorld {
private readonly dirtyNationIds = new Set<number>();
private readonly dirtyTroopIds = new Set<number>();
private readonly dirtyDiplomacyKeys = new Set<string>();
private readonly accessScoreResetGeneralIds = new Set<number>();
private readonly createdGeneralIds = new Set<number>();
private nextLegacyGeneralScanOrder = 0;
private readonly createdNationIds = new Set<number>();
@@ -606,6 +609,7 @@ export class InMemoryTurnWorld {
dirtyNationIds: Array.from(this.dirtyNationIds),
dirtyTroopIds: Array.from(this.dirtyTroopIds),
dirtyDiplomacyKeys: Array.from(this.dirtyDiplomacyKeys),
accessScoreResetGeneralIds: Array.from(this.accessScoreResetGeneralIds),
createdGeneralIds: Array.from(this.createdGeneralIds),
createdNationIds: Array.from(this.createdNationIds),
createdTroopIds: Array.from(this.createdTroopIds),
@@ -644,6 +648,7 @@ export class InMemoryTurnWorld {
this.replaceSet(this.dirtyNationIds, restored.dirtyNationIds);
this.replaceSet(this.dirtyTroopIds, restored.dirtyTroopIds);
this.replaceSet(this.dirtyDiplomacyKeys, restored.dirtyDiplomacyKeys);
this.replaceSet(this.accessScoreResetGeneralIds, restored.accessScoreResetGeneralIds ?? []);
this.replaceSet(this.createdGeneralIds, restored.createdGeneralIds);
this.replaceSet(this.createdNationIds, restored.createdNationIds);
this.replaceSet(this.createdTroopIds, restored.createdTroopIds);
@@ -693,6 +698,12 @@ export class InMemoryTurnWorld {
};
}
markGeneralAccessScoreReset(generalId: number): void {
if (Number.isSafeInteger(generalId) && generalId > 0) {
this.accessScoreResetGeneralIds.add(generalId);
}
}
changeTurnTerm(tickMinutes: number): void {
if (!Number.isInteger(tickMinutes) || tickMinutes <= 0) {
throw new Error('Turn term must be a positive integer.');
@@ -1512,8 +1523,12 @@ export class InMemoryTurnWorld {
}));
const pendingYearbookSnapshots = structuredClone(this.pendingYearbookSnapshots);
const pendingUnificationFinalizations = structuredClone(this.pendingUnificationFinalizations);
const accessScoreResetGeneralIds = Array.from(this.accessScoreResetGeneralIds).sort(
(left, right) => left - right
);
return {
accessScoreResetGeneralIds,
generals,
cities,
nations,
@@ -1542,6 +1557,7 @@ export class InMemoryTurnWorld {
}
acknowledgeDirtyState(changes: TurnWorldChanges): void {
for (const id of changes.accessScoreResetGeneralIds) this.accessScoreResetGeneralIds.delete(id);
for (const general of changes.generals) this.dirtyGeneralIds.delete(general.id);
for (const city of changes.cities) this.dirtyCityIds.delete(city.id);
for (const nation of changes.nations) this.dirtyNationIds.delete(nation.id);