aboutsummaryrefslogtreecommitdiff
path: root/api/game/random.py
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-02-21 09:30:40 +0100
committerlonkaars <l.leblansch@gmail.com>2021-02-21 09:30:40 +0100
commit96f56b2154195191132fb43c5b27f0a7c2ce1bb6 (patch)
treea698c06ab5beac7bc65fb22529f7134aa2533b9c /api/game/random.py
parente1978a9b80f3f7f5a36ca4af5f6df62f494a0d6d (diff)
working game-id's
Diffstat (limited to 'api/game/random.py')
-rw-r--r--api/game/random.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/api/game/random.py b/api/game/random.py
index bbddedc..f57e4d6 100644
--- a/api/game/random.py
+++ b/api/game/random.py
@@ -4,6 +4,8 @@ from randid import new_uuid
import time
import json
import random
+from game.socket import io, games, game
+from auth.login_token import token_login
random_game = Blueprint('random', __name__)
@@ -11,10 +13,14 @@ random_game = Blueprint('random', __name__)
def index():
data = request.get_json()
+ token = request.cookies.get("token") or ""
user_id = data.get("user_id") or ""
- if not user_id:
+ if not user_id and not token:
print("a temporary user should be set up here")
+ if not user_id and token:
+ user_id = token_login(token)[0]
+
public_games = cursor.execute("select game_id from games where private = FALSE and status = \"wait_for_opponent\"").fetchall()
print(public_games)
if len(public_games) == 0:
@@ -27,5 +33,8 @@ def index():
timestamp = int( time.time() * 1000 )
cursor.execute("update games set player_2_id = ?, status = \"in_progress\", timestamp = ? where game_id = ?", (user_id, timestamp, game_id))
connection.commit()
+ games[game_id] = game(game_id, io)
+ print("random.py")
+ print(games)
return { "id": game_id }, 200