コード例 #1
0
ファイル: __main__.py プロジェクト: williamjacksn/pblive
def socket_pass_question():
    user = data.admins[
        flask.request.sid] if flask.request.sid in data.admins else data.users[
            flask.request.sid]

    if isinstance(user.session.questions[user.session.question_num],
                  data.RandomQuestion):
        # Re-randomise answerer
        user.session.questions[
            user.session.question_num].answerer = random.choice([
                other_user for _, other_user in data.users.items()
                if other_user.session == user.session and other_user.colour
            ])

        # Relay change
        for _, other_user in data.iterate_users():
            if other_user.session == user.session and other_user.colour:
                flask_socketio.emit('update',
                                    render_question(
                                        other_user, other_user.session,
                                        other_user.session.question_num),
                                    room=other_user.sid)
                flask_socketio.emit('update_left',
                                    render_sidebar(other_user, user.session),
                                    room=other_user.sid)
        for _, _admin in data.iterate_admins():
            if _admin.session == user.session:
                flask_socketio.emit('update',
                                    render_question_admin(
                                        _admin.session,
                                        _admin.session.question_num),
                                    room=_admin.sid)
                flask_socketio.emit('update_left',
                                    render_sidebar(_admin, user.session),
                                    room=_admin.sid)
コード例 #2
0
ファイル: __main__.py プロジェクト: williamjacksn/pblive
def do_goto_question(_session, question_num):
    # Cleanup old question
    if isinstance(_session.questions[_session.question_num],
                  data.SpeedQuestion):
        if _session.questions[_session.question_num].timer_thread is not None:
            _session.questions[_session.question_num].timer_thread.stop()

    _session.question_num = question_num

    # Do work for some questions
    if isinstance(_session.questions[question_num], data.RandomQuestion):
        _session.questions[question_num].answerer = random.choice([
            other_user for _, other_user in data.users.items()
            if other_user.session == _session and other_user.colour
        ])

    # Relay change
    for _, other_user in data.iterate_users():
        if other_user.session == _session and other_user.colour:
            flask_socketio.emit('update',
                                render_question(other_user, _session,
                                                _session.question_num),
                                room=other_user.sid)
            flask_socketio.emit('update_left',
                                render_sidebar(other_user, _session),
                                room=other_user.sid)
    for _, _admin in data.iterate_admins():
        if _admin.session == _session:
            flask_socketio.emit('update',
                                render_question_admin(_session,
                                                      _session.question_num),
                                room=_admin.sid)
            flask_socketio.emit('update_left',
                                render_sidebar(_admin, _session),
                                room=_admin.sid)
コード例 #3
0
def socket_answer(question_num, answer):
    user = data.users[flask.request.sid]

    if question_num == user.session.question_num:
        if isinstance(user.session.questions[user.session.question_num], data.SpeedQuestion):
            if question_num in user.answers:
                # Only one shot!
                return

        user.answers[question_num] = answer

        if isinstance(user.session.questions[user.session.question_num], data.MCQQuestion):
            flask_socketio.emit('update', render_question(user, user.session, user.session.question_num), room=user.sid)

        # Hurry!
        if isinstance(user.session.questions[user.session.question_num], data.SpeedQuestion):
            if user.session.questions[user.session.question_num].timer_thread is None:
                user.session.questions[user.session.question_num].timer_thread = data.SpeedQuestionTimerThread(
                    flask.copy_current_request_context(do_goto_question), user.session, user.session.question_num + 1)
                user.session.questions[user.session.question_num].timer_thread.start()

        # Relay change
        for _, other_user in data.iterate_users():
            if other_user.session == user.session:
                flask_socketio.emit('update_left', render_sidebar(other_user, user.session), room=other_user.sid)
                if isinstance(user.session.questions[user.session.question_num], data.SpeedQuestion):
                    flask_socketio.emit('update', render_question(other_user, user.session, user.session.question_num),
                                        room=other_user.sid)
        for _, _admin in data.iterate_admins():
            if _admin.session == user.session:
                flask_socketio.emit('update', render_question_admin(user.session, user.session.question_num),
                                    room=_admin.sid)
                flask_socketio.emit('update_left', render_sidebar(_admin, user.session), room=_admin.sid)
コード例 #4
0
def relay_color_change(_user, _data):
    for _, other_user in _data.iterate_users():
        if other_user != _user and other_user.session == _user.session:
            flask_socketio.emit('update_left', render_sidebar(other_user, _user.session), room=other_user.sid)
            if not other_user.colour:
                flask_socketio.emit('update', flask.render_template('colour_picker.html', session=_user.session),
                                    room=other_user.sid)
    for _, _admin in data.iterate_admins():
        if _admin.session == _user.session:
            flask_socketio.emit('update_left', render_sidebar(_admin, _user.session), room=_admin.sid)
コード例 #5
0
def socket_answer(question_num, answer):
    user = data.sids_to_user[flask.request.sid]

    if user.session.questions[user.session.question_num].revealed:
        return

    if question_num == user.session.question_num:
        user.answers[question_num] = answer[0]

        if isinstance(user.session.questions[user.session.question_num],
                      data.MCQQuestion):
            flask_socketio.emit('update',
                                render_question(user, user.session,
                                                user.session.question_num),
                                room=user.sid)

        # Relay change
        for _, other_user in data.iterate_users():
            if other_user.session == user.session:
                flask_socketio.emit('update_left',
                                    render_sidebar(other_user, user.session),
                                    room=other_user.sid)
                if isinstance(
                        user.session.questions[user.session.question_num],
                        data.SpeedQuestion):
                    flask_socketio.emit('update',
                                        render_question(
                                            other_user, user.session,
                                            user.session.question_num),
                                        room=other_user.sid)
        for _, _admin in data.iterate_admins():
            if _admin.session == user.session:
                flask_socketio.emit('update',
                                    render_question_admin(
                                        user.session,
                                        user.session.question_num),
                                    room=_admin.sid)
                flask_socketio.emit('update_left',
                                    render_sidebar(_admin, user.session),
                                    room=_admin.sid)
コード例 #6
0
def do_goto_question(_session, question_num):
    _session.question_num = question_num

    # Relay change
    for _, other_user in data.iterate_users():
        if other_user.session == _session and other_user.username:
            flask_socketio.emit('update',
                                render_question(other_user, _session,
                                                _session.question_num),
                                room=other_user.sid)
            flask_socketio.emit('update_left',
                                render_sidebar(other_user, _session),
                                room=other_user.sid)
    for _, _admin in data.iterate_admins():
        if _admin.session == _session:
            flask_socketio.emit('update',
                                render_question_admin(_session,
                                                      _session.question_num),
                                room=_admin.sid)
            flask_socketio.emit('update_left',
                                render_sidebar(_admin, _session),
                                room=_admin.sid)