From 52b0375050429a9931f3160032750da770ca578f Mon Sep 17 00:00:00 2001 From: Ryan Schmidt Date: Thu, 30 May 2024 22:17:16 -0700 Subject: [PATCH] Properly stop game if last player parts or quits during join phase --- src/wolfgame.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/wolfgame.py b/src/wolfgame.py index 6226ebfa..b5f500ef 100644 --- a/src/wolfgame.py +++ b/src/wolfgame.py @@ -529,6 +529,7 @@ def leave(var: Optional[GameState | PregameState], what: str, user: User, why=No return ps = get_players(var) + num_remaining = len(ps) - 1 # Only mark living players as disconnected, unless they were kicked if (user in ps or what == "kick") and var.in_game: reaper.DCED_LOSERS.add(user) @@ -546,13 +547,12 @@ def leave(var: Optional[GameState | PregameState], what: str, user: User, why=No population = "" if var.current_phase == "join": - lpl = len(ps) - 1 - if lpl < config.Main.get("gameplay.player_limits.minimum"): + if num_remaining < config.Main.get("gameplay.player_limits.minimum"): with locks.join_timer: from src.pregame import START_VOTES START_VOTES.clear() - if lpl <= 0: + if num_remaining <= 0: population = " " + messages["no_players_remaining"] else: population = " " + messages["new_player_count"].format(lpl) @@ -601,6 +601,11 @@ def leave(var: Optional[GameState | PregameState], what: str, user: User, why=No else: reaper.DISCONNECTED[user] = (datetime.now(), what) + if not var.in_game and num_remaining <= 0: + # chk_win handles ending game at 0 players if a game is running, don't need to do so here + from src.trans import stop_game + stop_game(var, log=False) + @hook("error") def on_error(cli, pfx, msg: str): if restart_program.restarting or msg.lower().endswith("(excess flood)"):