def receive_new_game_from_instructor(data): # Set all games to passed Games.objects.update(isCurrent=False) # Post only gameId here to current Games.objects(gameId=data).update(isCurrent=True) Users.objects(userType="Instructor").update(gamePlayed=data) # Remove all student users Users.objects(userType="Student").delete() send_broadcast_message_game_room(data)
def get_games(): games = Games.objects isCurrent = request.args.get('isCurrent') if isCurrent == 'true': isCurrent = True return jsonify(Games.objects(isCurrent=isCurrent)) elif isCurrent == 'false': isCurrent = False return jsonify(Games.objects(isCurrent=isCurrent)) else: return jsonify(games)
def delete_game(): game = request.get_json() deletedGame = Games.objects(gameId=game["gameId"]).first() if not deletedGame: return jsonify({'error': 'data not found'}) else: deletedGame.delete() return jsonify(deletedGame)
def get_running_game(): currentSession = request.sid gameData = Games.objects(isCurrent=True).only('gameId') currentGameIds = [] for g in gameData: currentGameIds.append(g.gameId) emit('notification_game_room', format(currentGameIds), room = currentSession)
def update_game(): game = request.get_json() updateGame = Games.objects(gameId=game["gameId"]).first() if not updateGame: return jsonify({'error': 'data not found'}) else: updateGame.update(startTime=game["startTime"], endTime=game["endTime"], numOfPlayer=game["numOfPlayer"], isCurrent=game["isCurrent"]) return jsonify(updateGame)
def end_game(data): gameData = Games.objects(gameId=data,isCurrent=True) for g in gameData: g.update(isCurrent=False) emit('notification_endGame', data, broadcast=True)
def get_game(id): game = Games.objects(gameId=id).first() return jsonify(game)