diff options
author | lonkaars <l.leblansch@gmail.com> | 2021-02-12 18:56:52 +0100 |
---|---|---|
committer | lonkaars <l.leblansch@gmail.com> | 2021-02-12 18:56:52 +0100 |
commit | 5f391aadbcc818ab7fa13312fb2ee04ed02983c6 (patch) | |
tree | 59a50473839a26370b6d1a51cb430adb49b26536 /api/game/new.py | |
parent | b8f3a658253bb5991a3d034733b685cc7d543704 (diff) |
base /api/game/new
Diffstat (limited to 'api/game/new.py')
-rw-r--r-- | api/game/new.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/api/game/new.py b/api/game/new.py new file mode 100644 index 0000000..6f777e3 --- /dev/null +++ b/api/game/new.py @@ -0,0 +1,25 @@ +from flask import Blueprint, request, make_response +from main import cursor, connection +from randid import new_uuid +import time +import json + +new_game = Blueprint('new', __name__) + +@new_game.route('/new', methods = ['POST']) +def index(): + data = request.get_json() + + user_id = data.get("user_id") or "" # maybe set up a temporary user here? + game_settings = data.get("settings") or "" + + if not user_id: + print("a temporary user should be set up here") + + game_id = new_uuid("games") + timestamp = int( time.time() * 1000 ) + + cursor.execute("insert into games values (?, NULL, NULL, ?, NULL, NULL, ?, NULL, NULL, NULL, \"wait_for_opponent\", ?) ", (game_id, user_id, timestamp, json.dumps(game_settings))) + connection.commit() + + return { "id": game_id }, 200 |