diff --git a/services/common/auth.py b/services/common/auth.py index 5816293..da69ac6 100644 --- a/services/common/auth.py +++ b/services/common/auth.py @@ -8,7 +8,7 @@ from passlib.context import CryptContext from .settings import settings -pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") +pwd_context = CryptContext(schemes=["pbkdf2_sha256"], deprecated="auto") def hash_password(password: str) -> str: diff --git a/services/common/db.py b/services/common/db.py index 5ddb29e..ad0be1c 100644 --- a/services/common/db.py +++ b/services/common/db.py @@ -3,7 +3,8 @@ from __future__ import annotations from contextlib import contextmanager from sqlalchemy import create_engine -from sqlalchemy.orm import Session, sessionmaker +from sqlalchemy.orm import sessionmaker +from sqlmodel import Session from .settings import settings diff --git a/services/game/app.py b/services/game/app.py index 0ff05b9..50c8a86 100644 --- a/services/game/app.py +++ b/services/game/app.py @@ -95,7 +95,7 @@ def _trade_to_schema(trade: TradeOffer) -> TradeOfferSchema: def _build_state(game: Game, runtime) -> GameStateSchema: - if game.status != "running" or runtime is None: + if game.status != "running" or runtime is None or runtime.env is None: return GameStateSchema( id=game.id, name=game.name, diff --git a/services/game/runtime.py b/services/game/runtime.py index 26afc13..566d602 100644 --- a/services/game/runtime.py +++ b/services/game/runtime.py @@ -17,7 +17,7 @@ from services.game.models import Game, GameEvent, TradeOffer @dataclass class GameRuntime: game: Game - env: CatanEnv + env: Optional[CatanEnv] = None action_index: int = 0 def next_action_index(self) -> int: @@ -47,14 +47,19 @@ class GameRuntimeManager: slots = game.slots.get("slots", []) names = [slot.get("name") for slot in slots if slot.get("name")] colors = [slot.get("color", "player") for slot in slots if slot.get("name")] - config = GameConfig(player_names=names, colors=colors, seed=game.seed) - env = CatanEnv(config) - events = session.exec( - select(GameEvent).where(GameEvent.game_id == game_id, GameEvent.applied == True).order_by(GameEvent.idx) - ).all() - for event in events: - action = Action(ActionType(event.action_type), event.payload) - env.step(action) + if game.status == "running" and len(names) >= 2: + config = GameConfig(player_names=names, colors=colors, seed=game.seed) + env = CatanEnv(config) + events = session.exec( + select(GameEvent).where(GameEvent.game_id == game_id, GameEvent.applied == True).order_by(GameEvent.idx) + ).all() + else: + env = None + events = [] + if env is not None: + for event in events: + action = Action(ActionType(event.action_type), event.payload) + env.step(action) action_index = events[-1].idx if events else 0 return GameRuntime(game=game, env=env, action_index=action_index) diff --git a/tests/conftest.py b/tests/conftest.py index 2b2c0b8..8d84022 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,8 +4,8 @@ from typing import Generator import pytest from sqlalchemy import create_engine -from sqlalchemy.orm import Session, sessionmaker -from sqlmodel import SQLModel +from sqlalchemy.orm import sessionmaker +from sqlmodel import SQLModel, Session @pytest.fixture(scope="session")