aboutsummaryrefslogtreecommitdiff
path: root/api/game/random.py
diff options
context:
space:
mode:
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