예제 #1
0
파일: server.py 프로젝트: alan-mj-lin/Mafia
def skip_turn(roomId):
    LOG.info(request.access_route[0] + ' requested ' + request.url)
    if request.method == 'OPTIONS':
        return build_preflight_response()
    elif request.method == 'PATCH':
        userId = request.cookies.get('userId')
        is_room_master = check_room_master(database, roomId, userId)
        if not is_room_master:
            return build_actual_response({"message": "Not room master"}, 400)
        valid_phase_shift = phase_shift(database, roomId)
        if not valid_phase_shift:
            return build_actual_response({"message": "Not valid phase shift"},
                                         400)
        return build_actual_response({"message": "Turn skipped"}, 200)
예제 #2
0
파일: server.py 프로젝트: alan-mj-lin/Mafia
def night_start(roomId):
    LOG.info(request.access_route[0] + ' requested ' + request.url)
    if request.method == 'OPTIONS':
        return build_preflight_response()
    elif request.method == 'PATCH':
        userId = request.cookies.get('userId')
        is_room_master = check_room_master(database, roomId, userId)
        if not is_room_master:
            return build_actual_response({"message": "Not room master"}, 400)
        voting_ended = night_start_write(database, roomId)
        if not voting_ended:
            return build_actual_response({"message": "Voting still ongoing"},
                                         400)
        return build_actual_response({"message": "Night started"}, 200)
예제 #3
0
파일: server.py 프로젝트: alan-mj-lin/Mafia
def end_vote_phase(roomId):
    LOG.info(request.access_route[0] + ' requested ' + request.url)
    if request.method == 'OPTIONS':
        return build_preflight_response()
    elif request.method == 'PATCH':
        userId = request.cookies.get('userId')
        is_room_master = check_room_master(database, roomId, userId)
        if not is_room_master:
            return build_actual_response({"message": "Not room master"}, 400)

        valid_vote_result = end_votes(database, roomId)
        if not valid_vote_result:
            return build_actual_response({"message": "Not enough votes"}, 200)
        return build_actual_response({"message": "Valid execution"}, 200)
예제 #4
0
파일: server.py 프로젝트: alan-mj-lin/Mafia
def game_start(roomId):
    LOG.info(request.access_route[0] + ' requested ' + request.url)
    if request.method == 'OPTIONS':
        return build_preflight_response()
    elif request.method == 'PATCH':
        userId = request.cookies.get('userId')
        is_room_master = check_room_master(database, roomId, userId)
        if not is_room_master:
            return build_actual_response({"message": "Not room master"}, 400)
        able_to_start = game_start_write(database, roomId)
        if not able_to_start:
            return build_actual_response({"message": "Not enough players"},
                                         400)
        return build_actual_response({"message": "Player roles shuffled"}, 200)
예제 #5
0
파일: server.py 프로젝트: alan-mj-lin/Mafia
def hang_action(roomId):
    LOG.info(request.access_route[0] + ' requested ' + request.url)
    if request.method == 'OPTIONS':
        return build_preflight_response()
    elif request.method == 'PATCH':
        userId = request.cookies.get('userId')
        is_room_master = check_room_master(database, roomId, userId)
        if is_room_master:
            return build_actual_response(
                {"message": "Room master cannot vote"}, 400)
        is_valid_target = vote(database, roomId, userId,
                               request.form.get('targetId'))
        if not is_valid_target:
            return build_actual_response(
                {"message": "Not valid target or already voted"}, 400)
        return build_actual_response({"message": "Vote Added"}, 200)