aboutsummaryrefslogtreecommitdiff
path: root/api/game/new.py
diff options
context:
space:
mode:
Diffstat (limited to 'api/game/new.py')
-rw-r--r--api/game/new.py25
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