summaryrefslogtreecommitdiff
path: root/swiftstory/Client.py
diff options
context:
space:
mode:
Diffstat (limited to 'swiftstory/Client.py')
-rw-r--r--swiftstory/Client.py38
1 files changed, 21 insertions, 17 deletions
diff --git a/swiftstory/Client.py b/swiftstory/Client.py
index bc347f9..5116f51 100644
--- a/swiftstory/Client.py
+++ b/swiftstory/Client.py
@@ -1,3 +1,4 @@
+import asyncio
import websockets
from swiftstory.Status import error
@@ -12,7 +13,7 @@ class Client:
self.socket = socket
self.player = None
- async def join_game(self, game_name, lang):
+ def join_game(self, game_name, lang):
if self.game is not None:
return error('You are already in a game')
@@ -25,27 +26,27 @@ class Client:
if game is None:
return error('Invalid language')
- return await game.try_join(self)
+ return game.try_join(self)
- async def play_white_card(self, card_id):
+ 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)
+ return self.game.try_play_card(self.player, card_id)
- async def pick_black_card(self):
+ 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)
+ return self.game.try_become_judge(self.player)
- async def collect_cards(self):
+ 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)
+ return self.game.try_collect_cards(self.player)
- async def designate_card(self, card_id):
+ 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)
+ return self.game.try_designate_card(self.player, card_id)
def view_player_cards(self):
if self.game is None:
@@ -62,12 +63,15 @@ class Client:
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.")
+ def register_notification(self, message):
+ async def f():
+ try:
+ await self.socket.send(message)
+ except websockets.exceptions.ConnectionClosed:
+ print("Recipient has disconnected.")
- async def disconnect(self):
+ asyncio.create_task(f())
+
+ def disconnect(self):
if self.player is not None:
- await self.game.disconnect(self.player)
+ self.game.disconnect(self.player)