prevent start from starting twice

This commit is contained in:
Thomas Rubini 2023-01-05 15:37:07 +01:00 committed by SIMAILA Djalim
parent ca18e58e9d
commit 8c6128d45e
2 changed files with 11 additions and 1 deletions

View File

@ -50,6 +50,7 @@ class Game:
self.game_id = None
self.owner = None
self.members = []
self.has_started = True
def set_owner(self, username):
self.owner = Member(username)

View File

@ -54,7 +54,16 @@ def start_game():
return {"error": 1, "msg": "No session"}
if not flask.session["is_owner"]:
return {"error": 1, "msg": "you are not the owner of this game"}
if game_logic.get_game(flask.session["game_id"]) == None:
game = game_logic.get_game(flask.session["game_id"])
if game == None:
return {"error": 1, "msg": "this game doesn't exist"}
if game.has_started:
return {"error": 1, "msg": "this game is already started"}
game.has_started = None
return {"error": 0}