"""Server configuration, read from environment variables.""" from __future__ import annotations import os from dataclasses import dataclass def _float(name: str, default: float) -> float: return float(os.environ.get(name, default)) def _int(name: str, default: int) -> int: return int(os.environ.get(name, default)) @dataclass(frozen=True) class Settings: # Shared secret the AI service has to present on /internal/ai. # Empty disables authentication (development only). ai_shared_secret: str = os.environ.get("AI_SHARED_SECRET", "") # Seconds to wait for the AI service before falling back to a random move. ai_decision_timeout: float = _float("AI_DECISION_TIMEOUT", 5.0) # Minimum "thinking" time of AI players so humans can follow the game. ai_move_delay: float = _float("AI_MOVE_DELAY", 0.8) # Pause after a completed trick before AI players continue. trick_pause: float = _float("TRICK_PAUSE", 1.8) # Sessions without a connection are dropped after this many seconds. session_ttl: float = _float("SESSION_TTL", 1800.0) # Maximum number of simultaneously existing lobbies. max_lobbies: int = _int("MAX_LOBBIES", 1000) # Comma separated list of allowed websocket origins; empty allows all. allowed_origins: tuple[str, ...] = tuple( origin.strip() for origin in os.environ.get("ALLOWED_ORIGINS", "").split(",") if origin.strip() ) log_level: str = os.environ.get("LOG_LEVEL", "INFO") settings = Settings()