From 1e88e73082c6997fbd6a001922713ed414673fe9 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Fri, 28 Jul 2023 11:21:34 +0700 Subject: [PATCH] Add option for bridge to create new judge --- dmoj/settings.py | 1 + judge/bridge/judge_handler.py | 16 +++++++++++++--- requirements.txt | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/dmoj/settings.py b/dmoj/settings.py index 47abcb8..dea5179 100644 --- a/dmoj/settings.py +++ b/dmoj/settings.py @@ -381,6 +381,7 @@ BRIDGED_JUDGE_ADDRESS = [("localhost", 9999)] BRIDGED_JUDGE_PROXIES = None BRIDGED_DJANGO_ADDRESS = [("localhost", 9998)] BRIDGED_DJANGO_CONNECT = None +BRIDGED_AUTO_CREATE_JUDGE = False # Event Server configuration EVENT_DAEMON_USE = False diff --git a/judge/bridge/judge_handler.py b/judge/bridge/judge_handler.py index 1efd45a..5bfda23 100644 --- a/judge/bridge/judge_handler.py +++ b/judge/bridge/judge_handler.py @@ -123,11 +123,21 @@ class JudgeHandler(ZlibPacketHandler): def _authenticate(self, id, key): try: - judge = Judge.objects.get(name=id, is_blocked=False) + judge = Judge.objects.get(name=id) except Judge.DoesNotExist: - result = False + if settings.BRIDGED_AUTO_CREATE_JUDGE: + judge = Judge() + judge.name = id + judge.auth_key = key + judge.save() + result = True + else: + result = False else: - result = hmac.compare_digest(judge.auth_key, key) + if judge.is_blocked: + result = False + else: + result = hmac.compare_digest(judge.auth_key, key) if not result: json_log.warning( diff --git a/requirements.txt b/requirements.txt index 637c646..53228e7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,7 +26,7 @@ pyotp qrcode[pil] jsonfield @ git+https://github.com/DMOJ/jsonfield.git pymoss -packaging<23 +packaging<22 celery ansi2html @ git+https://github.com/DMOJ/ansi2html.git sqlparse