websocket comm per json now
This commit is contained in:
@ -3,6 +3,7 @@ from app_instance import api
|
||||
from wiz_game import the_game
|
||||
from starlette.websockets import WebSocketDisconnect
|
||||
import asyncio
|
||||
import json
|
||||
|
||||
|
||||
playing_lock = asyncio.Lock()
|
||||
@ -74,14 +75,31 @@ async def websocket(ws):
|
||||
await ws.accept()
|
||||
the_game.websockets.append(ws)
|
||||
try:
|
||||
cmd = await ws.receive_text()
|
||||
fct, args = cmd.split()
|
||||
if fct == "playcard":
|
||||
p, c = map(int, args.split(':'))
|
||||
x = await ws.receive_json()
|
||||
print(x)
|
||||
fct = x['fct']
|
||||
if fct == 'playcard':
|
||||
print("play card :)")
|
||||
p = int(x['player'])
|
||||
c = int(x['card'])
|
||||
await play_card(p, c)
|
||||
elif fct == "setTrumpColor":
|
||||
player, color = args.split(':')
|
||||
elif fct == 'setTrumpColor':
|
||||
print("trump color :)")
|
||||
player = x['player']
|
||||
color = x['color']
|
||||
await set_trump_color(player, color)
|
||||
else:
|
||||
print("confused :(")
|
||||
|
||||
# cmd = await ws.receive_text()
|
||||
# fct, args = cmd.split()
|
||||
# if fct == "playcard":
|
||||
# p, c = map(int, args.split(':'))
|
||||
# await play_card(p, c)
|
||||
# elif fct == "setTrumpColor":
|
||||
# player, color = args.split(':')
|
||||
# await set_trump_color(player, color)
|
||||
|
||||
|
||||
except WebSocketDisconnect:
|
||||
the_game.websockets.remove(ws)
|
||||
|
Reference in New Issue
Block a user