From 91035c482ab6ffbec889f30cd9c3eeda235b173a Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 19 Mar 2023 21:50:20 +0800 Subject: [PATCH] feat: patch "/judge/submit" handler --- web/app/controllers/judge/submit.php | 226 +++++++++++++++++++++ web/app/controllers/judge/submit.php.patch | 62 ++++++ 2 files changed, 288 insertions(+) create mode 100644 web/app/controllers/judge/submit.php create mode 100644 web/app/controllers/judge/submit.php.patch diff --git a/web/app/controllers/judge/submit.php b/web/app/controllers/judge/submit.php new file mode 100644 index 0000000..52bf4ab --- /dev/null +++ b/web/app/controllers/judge/submit.php @@ -0,0 +1,226 @@ +the score gained by the hacked submission is not 100.\n"; + $esc_details = DB::escape(uojTextEncode($details)); + DB::update("update hacks set success = 0, details = '$esc_details' where id = {$hack['id']}"); + return false; + } + return true; + } + return false; + } + + + + if (isset($_POST['fetch_new']) && !$_POST['fetch_new']) { + die("Nothing to judge"); + } + if (!findSubmissionToJudge()) { + die("Nothing to judge"); + } + + $submission['id'] = (int)$submission['id']; + $submission['problem_id'] = (int)$submission['problem_id']; + $submission['problem_mtime'] = filemtime("/var/uoj_data/{$submission['problem_id']}"); + $submission['content'] = json_decode($submission['content']); + + if ($hack) { + $submission['is_hack'] = ""; + $submission['hack']['id'] = (int)$hack['id']; + $submission['hack']['input'] = $hack['input']; + $submission['hack']['input_type'] = $hack['input_type']; + } + + echo json_encode($submission); +?> diff --git a/web/app/controllers/judge/submit.php.patch b/web/app/controllers/judge/submit.php.patch new file mode 100644 index 0000000..638dc1d --- /dev/null +++ b/web/app/controllers/judge/submit.php.patch @@ -0,0 +1,62 @@ +--- UOJ-System/web/app/controllers/judge/submit.php 2022-12-30 09:54:05.452022649 +0800 ++++ UOJ-Luogu-RemoteJudge/web/app/controllers/judge/submit.php 2023-03-19 21:47:57.347852462 +0800 +@@ -85,7 +85,7 @@ + if (validateUploadedFile('hack_input') && validateUploadedFile('std_output')) { + dataAddExtraTest(queryProblemBrief($problem_id), $_FILES["hack_input"]["tmp_name"], $_FILES["std_output"]["tmp_name"]); + } else { +- error_log("hack successfully but received no data. id: ${_POST['id']}"); ++ error_log("hack successfully but received no data. id: {$_POST['id']}"); + } + } + } +@@ -115,12 +115,26 @@ + } + die(); + } ++ ++ $problem_ban_list = array(); ++ ++ if ($_POST['judger_name'] == "luogu_remote_judger") { ++ $problem_ban_list = array_map(function ($x) { return $x['id']; }, DB::selectAll("select id from problems where type != 'luogu'")); ++ } else { ++ $problem_ban_list = array_map(function ($x) { return $x['id']; }, DB::selectAll("select id from problems where type != 'local'")); ++ } ++ ++ $conds = " (true) "; ++ ++ if (!empty($problem_ban_list)) { ++ $conds .= " and problem_id not in (" . implode(",", $problem_ban_list) . ") "; ++ } + + $submission = null; + $hack = null; + function querySubmissionToJudge($status, $set_q) { +- global $submission; +- $submission = DB::selectFirst("select id, problem_id, content from submissions where status = '$status' order by id limit 1"); ++ global $submission, $conds; ++ $submission = DB::selectFirst("select id, problem_id, content from submissions where status = '$status' and $conds order by id limit 1"); + if ($submission) { + DB::update("update submissions set $set_q where id = {$submission['id']} and status = '$status'"); + if (DB::affected_rows() != 1) { +@@ -129,8 +143,8 @@ + } + } + function queryCustomTestSubmissionToJudge() { +- global $submission; +- $submission = DB::selectFirst("select id, problem_id, content from custom_test_submissions where judge_time is null order by id limit 1"); ++ global $submission, $conds; ++ $submission = DB::selectFirst("select id, problem_id, content from custom_test_submissions where judge_time is null and $conds order by id limit 1"); + if ($submission) { + DB::update("update custom_test_submissions set judge_time = now(), status = 'Judging' where id = {$submission['id']} and judge_time is null"); + if (DB::affected_rows() != 1) { +@@ -142,8 +156,8 @@ + } + } + function queryHackToJudge() { +- global $hack; +- $hack = DB::selectFirst("select id, submission_id, input, input_type from hacks where judge_time is null order by id limit 1"); ++ global $hack, $conds; ++ $hack = DB::selectFirst("select id, submission_id, input, input_type from hacks where judge_time is null and $conds order by id limit 1"); + if ($hack) { + DB::update("update hacks set judge_time = now() where id = {$hack['id']} and judge_time is null"); + if (DB::affected_rows() != 1) {