Fix auth hashing and lobby runtime handling
Some checks failed
ci / tests (push) Has been cancelled

This commit is contained in:
dan
2025-12-25 03:30:51 +03:00
parent 46a07f548b
commit e5e52ed1fe
5 changed files with 20 additions and 14 deletions

View File

@@ -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:

View File

@@ -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

View File

@@ -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,

View File

@@ -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)

View File

@@ -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")