From 281567422e698a5b86b5f8030e672d84a5d178c0 Mon Sep 17 00:00:00 2001 From: Jiri Kalvoda Date: Wed, 14 Sep 2022 00:14:06 +0200 Subject: [PATCH] =?UTF-8?q?Strategick=C3=A1:=20Roz=C5=A1=C3=AD=C5=99en?= =?UTF-8?q?=C3=AD=20API=20na=20moc=20brzy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- obsazovani.md | 5 +++-- server/hra/web/api.py | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/obsazovani.md b/obsazovani.md index 0252fc2..a3df049 100644 --- a/obsazovani.md +++ b/obsazovani.md @@ -11,9 +11,10 @@ Parametry: - `main` - Hlavní hra - `test_{0,1,..}` Testovací hra daného uživatele (číslo je jako který tým hrají) - round_id: To zjistí z otazu na stav +- min_round: Validní odpovědi pouze pokud je tento nebo pozdější tah, jinak "too-early" Stav: -GET na `/api/state?game=&token=` +GET na `/api/state?game=&token=&min_round=` ```json { status: "ok" @@ -39,7 +40,7 @@ GET na `/api/state?game=&token=` nebo { - status: "working" # Server počítá následující stav, klient má počkat + status: "working" nebo "too-early" # Server počítá následující stav nebo je některý z předchozích tahů, klient má počkat wait: # Jak dlouho má klient čekat, než se zeptá znovu } ``` diff --git a/server/hra/web/api.py b/server/hra/web/api.py index 5059925..0fe506b 100644 --- a/server/hra/web/api.py +++ b/server/hra/web/api.py @@ -35,6 +35,12 @@ def api_state(): team = get_context() game = team.game team_id = team.team_id + min_round = args_get("min_round", int, True) + if min_round is not None and min_round > game.current_round: + return json.dumps({ + "status": "too-early", + "wait": 5.0, + }) state = game.current_state() if state is None: return json.dumps({