From 3401cd75bff5a8ea9ff68e8057c6af2cb2b4f5b9 Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 5 Sep 2022 15:36:10 +0800 Subject: [PATCH] judge: respect hack subtask configured score --- packages/hydrojudge/src/flow.ts | 11 +++++++---- packages/hydrooj/src/handler/judge.ts | 2 +- packages/hydrooj/src/interface.ts | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/hydrojudge/src/flow.ts b/packages/hydrojudge/src/flow.ts index 3c6e59d0c..7c93bc4cd 100644 --- a/packages/hydrojudge/src/flow.ts +++ b/packages/hydrojudge/src/flow.ts @@ -89,10 +89,13 @@ export const runFlow = async (ctx: Context, task: Task) => { const runner = task.judgeCase(subtask.cases.find((i) => i.input === ctx.meta.hackRejudge)); const res = await runner(ctx, ctxSubtask, runner); if (res) ctx.next({ case: res }); - ctx.end({ - status: ctxSubtask.status === STATUS.STATUS_ACCEPTED ? STATUS.STATUS_ACCEPTED : STATUS.STATUS_HACKED, - score: 97, - }); + const totalScore = Math.sum(ctx.config.subtasks.map((i) => i.score)); + if (ctxSubtask.status !== STATUS.STATUS_ACCEPTED) { + ctx.end({ + status: STATUS.STATUS_HACKED, + score: totalScore - subtask.score, + }); + } else ctx.end({ nop: true }); } else { const tasks = []; for (const sid in ctx.config.subtasks) tasks.push(judgeSubtask(ctx.config.subtasks[sid], sid, task.judgeCase)(ctx)); diff --git a/packages/hydrooj/src/handler/judge.ts b/packages/hydrooj/src/handler/judge.ts index 959748657..c2f066bbd 100644 --- a/packages/hydrooj/src/handler/judge.ts +++ b/packages/hydrooj/src/handler/judge.ts @@ -206,7 +206,7 @@ class JudgeConnectionHandler extends ConnectionHandler { if (msg.key !== 'ping' && msg.key !== 'prio') logger[['status', 'next'].includes(msg.key) ? 'debug' : 'info']('%o', msg); if (msg.key === 'next') await next(msg); else if (msg.key === 'end') { - await end({ judger: this.user._id, ...msg }).catch((e) => logger.error(e)); + if (!msg.nop) await end({ judger: this.user._id, ...msg }).catch((e) => logger.error(e)); this.processing = null; await this.newTask(); } else if (msg.key === 'status') { diff --git a/packages/hydrooj/src/interface.ts b/packages/hydrooj/src/interface.ts index 5340d5106..868d13133 100644 --- a/packages/hydrooj/src/interface.ts +++ b/packages/hydrooj/src/interface.ts @@ -539,6 +539,7 @@ export interface JudgeResultBody { memory?: number; message?: string | JudgeMessage; compilerText?: string; + nop?: boolean; } export interface Task {