From c321dafb82684eb35edaca2b4357bd52a5894eb3 Mon Sep 17 00:00:00 2001 From: legonzaur Date: Mon, 13 May 2024 15:05:41 +0200 Subject: [PATCH] Prevent games from starting with only one player Disabled with DEV_MODE=TRUE env var Fixes #9 --- src/controller/client.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/controller/client.py b/src/controller/client.py index e1c1e7d..8f2acf4 100644 --- a/src/controller/client.py +++ b/src/controller/client.py @@ -1,5 +1,6 @@ """Handles communication between one WebSocket tunnel and the game""" +import os from typing import Callable, Any, TYPE_CHECKING, Awaitable from pydantic import ValidationError @@ -165,10 +166,12 @@ class ClientController: but the game isn't yet started""" if message.type == "ready": self.player.ready = bool(message.data) + await self.player.notify_update() if all(p.ready for p in self.game_controller.game.players): - await self.game_controller.start_game() - else: - await self.player.notify_update() + if ("DEV_MODE" in os.environ) or len( + self.game_controller.game.players + ) > 1: + await self.game_controller.start_game() @vibe_check(Message) async def game_context(self, message: Message) -> None: