import websockets from swiftstory.Status import error from swiftstory.Game import Game class Client: def __init__(self, socket, game_manager): self.game = None self.game_manager = game_manager self.socket = socket self.player = None async def join_game(self, game_name, lang): if self.game is not None: return error('You are already in a game') if lang is None: lang = 'en' game = self.game_manager.join_game(game_name, lang) # XXX self.game will be assigned by game.try_join() if game is None: return error('Invalid language') return await game.try_join(self) async def play_white_card(self, card_id): if self.game is None: return error('You have to join a game first') return await self.game.try_play_card(self.player, card_id) async def pick_black_card(self): if self.game is None: return error('You have to join a game first') return await self.game.try_become_judge(self.player) async def collect_cards(self): if self.game is None: error('You have to join a game first') return await self.game.try_collect_cards(self.player) async def designate_card(self, card_id): if self.game is None: return error('You have to join a game first') return await self.game.try_designate_card(self.player, card_id) def view_player_cards(self): if self.game is None: return error('You have to join a game first') return self.game.try_view_player_cards(self.player) def view_played_cards(self): if self.game is None: return error('You have to join a game first') return self.game.try_view_played_cards(self.player) def view_black_card(self): if self.game is None: return error('You have to join a game first') return self.game.try_view_black_card(self.player) async def send_notification(self, message): try: await self.socket.send(message) except websockets.exceptions.ConnectionClosed: print("Recipient has disconnected.") async def disconnect(self): if self.player is not None: await self.game.disconnect(self.player)