From a0a4fc2735ee6cab5149f45dfd9ca2751bf7d380 Mon Sep 17 00:00:00 2001 From: kulisak12 Date: Sun, 18 Sep 2022 14:28:01 +0200 Subject: [PATCH] =?UTF-8?q?Strategick=C3=A1:=20Fix=20nedefinovan=C3=BDch?= =?UTF-8?q?=20funkc=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- klient/client.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/klient/client.py b/klient/client.py index 35b028e..3a1ed40 100644 --- a/klient/client.py +++ b/klient/client.py @@ -84,11 +84,6 @@ def run_subprocess( def get_state(min_round: int, args) -> dict: """Iteratively try to get game data from the server.""" - state, wait_time = get_state_once() - while state is None: - time.sleep(wait_time) - state, wait_time = get_state_once() - def get_state_once() -> Tuple[Optional[dict], float]: try: res = requests.get(f"{args.server}/api/state", params={ @@ -107,6 +102,7 @@ def get_state(min_round: int, args) -> dict: state = res.json() if state["status"] == "ok": + logger.info("Received new state.") return state, 0 # retry after some time @@ -116,16 +112,16 @@ def get_state(min_round: int, args) -> dict: logger.info("Round didn't start yet.") return None, state["wait"] - logger.info("Received new state.") - return state, 0 + state, wait_time = get_state_once() + while state is None: + time.sleep(wait_time) + state, wait_time = get_state_once() + return state def send_turn(turn: dict, round: int, args) -> None: """Iteratively try to send turn to the server.""" - while not send_turn_once(): - time.sleep(TIME_BEFORE_RETRY) - def send_turn_once() -> bool: """Returns True if server answered.""" @@ -162,13 +158,16 @@ def send_turn(turn: dict, round: int, args) -> None: f" {member['id']}: {member['description']}" for member in response["members"] ] + logger.info("Turn accepted with warnings.") logger.warning( "Member warnings:\n" "\n".join(member_warns) ) - return True + while not send_turn_once(): + time.sleep(TIME_BEFORE_RETRY) + def log_server_error(res: requests.Response) -> None: logger.error(