Endgame WS messages & docs

This commit is contained in:
Eden Kirin
2023-05-11 19:36:16 +02:00
parent 76ee207bce
commit d660845d30
6 changed files with 47 additions and 115 deletions

View File

@ -185,7 +185,7 @@ class GameEngine:
logging.info("Ding ding! Product selection countdown timer timeout")
self._purchase_countdown_timer = None
asyncio.run(
self.ws_server.send_product_selection_done_message()
self.ws_server.send_product_selection_timeout_message()
)
self.game_state = GameState.RUNNING
asyncio.run(self.send_game_dump())

View File

@ -6,13 +6,7 @@ from typing import Optional, TypeVar
from pydantic import Field
from pydantic.generics import GenericModel
from hopper.api.dto import (
BaseModel,
BoardDto,
DestinationDto,
PlayerDto,
PositionDto,
)
from hopper.api.dto import BaseModel, BoardDto, DestinationDto, PlayerDto, PositionDto
from hopper.enums import ObjectType
@ -65,6 +59,10 @@ class WSProductSelectionDoneMessage(WSMessage):
message: str = "product_selection_done"
class WSProductSelectionTimeoutMessage(WSMessage):
message: str = "product_selection_timeout"
class WSPlayerReachedDestinationMessage(WSMessage):
message: str = "player_reached_destination"
data: PlayerReachedDestinationDto

View File

@ -15,6 +15,7 @@ from hopper.models.ws_dto import (
WSMessage,
WSPlayerReachedDestinationMessage,
WSProductSelectionDoneMessage,
WSProductSelectionTimeoutMessage,
)
@ -63,7 +64,9 @@ class WSServer(Thread):
try:
# we're expecting nothing from client, but read if client sends a message
rcv_data = await websocket.recv()
await self.handle_rcv_message(client=websocket, raw_message=rcv_data)
await self.handle_rcv_message(
client=websocket, raw_message=rcv_data
)
except ConnectionClosedOK:
logging.info(f"Connection closed OK for client: {websocket.id}")
connected = False
@ -126,6 +129,10 @@ class WSServer(Thread):
message = WSProductSelectionDoneMessage()
await self.send_message_to_clients(message)
async def send_product_selection_timeout_message(self) -> None:
message = WSProductSelectionTimeoutMessage()
await self.send_message_to_clients(message)
async def run_async(self) -> None:
logging.info(
f"Starting FairHopper Websockets Server on {self.host}:{self.port}"