Ejemplo n.º 1
0
def get_answer_status(session_id):
    player_id = request.args.get(PLAYER_ID, None)
    round_id = request.args.get(ROUND_ID, None)
    question_id = request.args.get(QUESTION_ID, None)

    try:
        round_id = int(round_id)
        question_id = int(question_id)
    except:
        return _resp(fail("Bad question/round ID"))

    session = get_session(session_id)[OBJECT]

    question = session[ROUNDS][round_id][QUESTIONS][question_id]
    answers = question.get(ANSWERS, None)
    if answers is None:
        return _resp(fail("Question is not open"))

    mod = session[MODERATOR]
    players = get_players2(session)
    if player_id != mod:
        # scored questions will provide answers and wagers
        if question.get(SCORED, False):
            return _resp(get_answers_scored(players, answers, player_id))
        else:
            # unscored questions will provide only answered:true/false
            return _resp(get_answers_unscored(players, answers, player_id))

    else:
        # mod always gets complete player_id/answer/wager
        return _resp(get_answers_as_mod(players, answers))
Ejemplo n.º 2
0
def create_and_respond(endpoint, data):
    """
    try to create some object and return a failure/success resp
    """
    if endpoint == "session":
        return _resp(create_session(data))
    if endpoint == "player":
        return _resp(create_player(data))

    raise Exception(f"unsupported create '{endpoint}'")
Ejemplo n.º 3
0
def legal_wagers_for_player(session_id):
    player_id = request.args.get(PLAYER_ID, None)
    round_id = request.args.get(ROUND_ID, None)
    session = get_session(session_id)[OBJECT]

    try:
        round_id = int(round_id)
    except:
        return _resp(fail("Bad round ID"))

    return _resp(succeed(get_legal_wagers(session, round_id, player_id)))
Ejemplo n.º 4
0
def score_one_question(session_id):
    player_id = request.json.get(PLAYER_ID, None)

    is_mod = verify_mod(session_id, player_id)
    if not is_mod[SUCCESS]:
        return is_mod

    return _resp(score_question(session_id, request.json))
Ejemplo n.º 5
0
def get_session_state(session_id):
    req_state = request.args.get("current", None)
    if req_state is None:
        time.sleep(10)

    sleep_time = .5
    timeout_s = 90

    attempts = 0
    while attempts < (timeout_s / sleep_time):
        state = mongo.get_state(session_id)
        if str(state) != str(req_state):
            return _resp(succeed({"state": state}))
        time.sleep(sleep_time)
        attempts += 1

    return _resp(succeed({"state": req_state}))
Ejemplo n.º 6
0
def set_curr_r(session_id):
    player_id = request.json.get(PLAYER_ID, None)
    round_id = request.json.get(ROUND_ID, None)

    is_mod = verify_mod(session_id, player_id)
    if not is_mod[SUCCESS]:
        return is_mod

    return _resp(set_current_round(session_id, round_id))
Ejemplo n.º 7
0
def get_all_players_in_session(session_id):
    player_id = request.args.get(PLAYER_ID, False)
    data = get_players(session_id)
    if data[SUCCESS]:
        mod = data[MODERATOR]
        if mod != player_id:
            for player in data[OBJECT]:
                if player[ID] != player_id:
                    del player[ID]
    return _resp(data)
Ejemplo n.º 8
0
def get_and_respond(endpoint, object_id, player_id=None, prune=None):
    if endpoint == "session":
        data = get_session(object_id)
    if endpoint == "player":
        data = get_player(object_id)
    if endpoint == "current_question":
        data = get_current_question(object_id)
    if endpoint == "current_round":
        data = get_current_round(object_id)

    if prune is not None:
        prune(data, player_id)
    return _resp(data)
Ejemplo n.º 9
0
def get_current_scoreboard(session_id):
    caller_player_id = request.args.get(PLAYER_ID, None)

    scores = get_scoreboard(session_id)[OBJECT]

    ret = []
    for player_id in scores:
        player = get_player(player_id)
        pprint.pprint(player)
        player = player[OBJECT]
        score = {
            TEAM_NAME: player[TEAM_NAME],
            ICON: player.get(ICON, None),
            "score": scores[player_id]
        }
        if caller_player_id == player_id:
            score[PLAYER_ID] = player_id

        ret.append(score)

    print(ret)

    return _resp(succeed(ret))
Ejemplo n.º 10
0
def answer_one_question(session_id):
    return _resp(answer_question(session_id, request.json))
Ejemplo n.º 11
0
def update_and_respond(endpoint, object_id, data):
    if endpoint == "player":
        return _resp(update_player(object_id, data))

    raise Exception(f"unsupported create '{endpoint}'")
Ejemplo n.º 12
0
def remove_player_from_session(session_id):
    return _resp(remove_from_session(session_id, request.json))
Ejemplo n.º 13
0
def add_player_to_session(session_id):
    return _resp(add_to_session(session_id, request.json))