This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,11 +47,16 @@ 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")]
|
||||
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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user