Attempt to fix #12

This commit is contained in:
2024-05-12 11:05:09 +02:00
parent 4e7381ba33
commit cc42815cce
2 changed files with 9 additions and 2 deletions
+7 -2
View File
@@ -1,6 +1,6 @@
"""Handles communication between one WebSocket tunnel and the game""" """Handles communication between one WebSocket tunnel and the game"""
from typing import Callable, Any, TYPE_CHECKING from typing import Callable, Any, TYPE_CHECKING, Awaitable
from pydantic import ValidationError from pydantic import ValidationError
from websockets.server import WebSocketServerProtocol from websockets.server import WebSocketServerProtocol
@@ -45,6 +45,8 @@ class ClientController:
track_connection: Callable track_connection: Callable
on_message = Callable[[Message], Awaitable[None]]
def __init__( def __init__(
self, self,
game_controller: "GameController", game_controller: "GameController",
@@ -53,7 +55,10 @@ class ClientController:
self.websocket = websocket self.websocket = websocket
self.game_controller = game_controller self.game_controller = game_controller
self.game_controller.clients.append(self) self.game_controller.clients.append(self)
self.on_message = lambda _: None self.on_message = self.on_message_stub
async def on_message_stub(self, message: Message):
pass
async def close(self): async def close(self):
"""Remove self from Game broadcasting list""" """Remove self from Game broadcasting list"""
+2
View File
@@ -158,4 +158,6 @@ class LobbyClientController:
) )
async def game_context(self, message: Message) -> None: async def game_context(self, message: Message) -> None:
if self.game_client is None:
return
await self.game_client.on_message(message) await self.game_client.on_message(message)