From eda5874ecb4b58a7212d62cef8c3605f8baff824 Mon Sep 17 00:00:00 2001 From: Nils G <nils.gondermann@ruhr-uni-bochum.de> Date: Tue, 7 Apr 2020 15:31:56 +0200 Subject: [PATCH] Added closed flag to rooms and http status code response 410 GONE --- controllers/room.py | 5 ++++- models/f_room.py | 5 +++-- modules/http_util.py | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/controllers/room.py b/controllers/room.py index 6e2cfc8..5747644 100644 --- a/controllers/room.py +++ b/controllers/room.py @@ -1,5 +1,5 @@ from parameter_util import JSON_BODY, JSON_CONTAINS -from http_util import FAIL, CODE_JSON, CODE_MISSING, CODE_SEMANTIC +from http_util import FAIL, CODE_JSON, CODE_MISSING, CODE_SEMANTIC, CODE_GONE from room_util import ROOM_GET, PLAYERS_GET import random @@ -43,6 +43,9 @@ def status(): if not room_record: return(FAIL(CODE_SEMANTIC)) + if room_record.closed: + return(FAIL(CODE_GONE)) + players = PLAYERS_GET(room_record) json = {"players": players} diff --git a/models/f_room.py b/models/f_room.py index 3b4e794..6ac77f6 100644 --- a/models/f_room.py +++ b/models/f_room.py @@ -7,13 +7,14 @@ db.define_table( Field('hashcode', 'string', notnull=True), Field('player_max', 'integer', notnull=True), Field('creation', 'datetime', default=request.now, notnull=True), - Field('heartbeat', 'datetime', default=request.now, notnull=True) + Field('heartbeat', 'datetime', default=request.now, notnull=True), + Field('closed', 'boolean', default=False) ) def generateRoomCode(): code = None - while not code or db(db.Room.code == code).count() > 0: + while not code or db((db.Room.code == code) & (db.Room.closed == False)).count() > 0: code = "" for i in range(4): # Removed characters which could be confused like 0 and O diff --git a/modules/http_util.py b/modules/http_util.py index e641fd6..3a9ca10 100644 --- a/modules/http_util.py +++ b/modules/http_util.py @@ -2,6 +2,7 @@ from gluon import * CODE_MISSING = 400 CODE_JSON = 406 +CODE_GONE = 410 CODE_SEMANTIC = 422 def FAIL(_code): -- GitLab