diff options
author | lonkaars <l.leblansch@gmail.com> | 2021-02-22 12:48:38 +0100 |
---|---|---|
committer | lonkaars <l.leblansch@gmail.com> | 2021-02-22 12:48:38 +0100 |
commit | 32aaaf92f2c06214abdc93e3cede07e067df6b88 (patch) | |
tree | 1b98d9e7605278311aa76880614ba17361f69285 /api/game/random.py | |
parent | ae4e74ccde82388cca5e874539bb132e23fc1e92 (diff) |
added columns to games + cleanup function
Diffstat (limited to 'api/game/random.py')
-rw-r--r-- | api/game/random.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/api/game/random.py b/api/game/random.py index 52a6d1f..ab4323d 100644 --- a/api/game/random.py +++ b/api/game/random.py @@ -23,16 +23,17 @@ def index(): public_games = cursor.execute("select game_id from games where private = FALSE and status = \"wait_for_opponent\"").fetchall() + timestamp = int( time.time() * 1000 ) + if len(public_games) == 0: game_id = new_uuid("games") - cursor.execute("insert into games values (?, NULL, \"\", ?, NULL, NULL, 0, NULL, NULL, NULL, \"wait_for_opponent\", \"default\", FALSE) ", (game_id, user_id)) + cursor.execute("insert into games values (?, NULL, \"\", ?, NULL, NULL, ?, NULL, ?, NULL, NULL, NULL, \"wait_for_opponent\", \"default\", FALSE, FALSE) ", (game_id, user_id, timestamp, timestamp)) connection.commit() player_1 = True else: game_id = random.choice(public_games)[0] - 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)) + cursor.execute("update games set player_2_id = ?, status = \"in_progress\", started = ?, last_activity = ? where game_id = ?", (user_id, timestamp, timestamp, game_id)) connection.commit() players = cursor.execute("select player_1_id, player_2_id from games where game_id = ?", [game_id]).fetchone() |