Exemple #1
0
def update_data_main_page():
    """return json with information about:

    - users who wait second player
    - games which does now

    the structure of dictionary is:
    { 'users':{ 'id1':'username1',
                'id2':'username2'},

      'games': { 'id':[user1, user2],
                 'id':[user1, user2]}}
    """
    if request.method == 'POST':
        current_user = "******"
        if request.cookies.has_key('session_id'):
            cookie_session = request.cookies.get('session_id')
            update_user(**{ 'session_id': cookie_session, 'time': True })
            user_status = get_user_status(cookie_session)
            if user_status == 1:
                return jsonify(user_status=user_status)
            if user_status == 0:
                user = get_user_by_session(cookie_session)
                if user:
                    current_user = user.user_name
        users = get_wait_users()
        list_username = {}
        for user in users:
            list_username[str(user.id)] = user.user_name
        games = get_begin_games()
        user_server = get_user_id(cookie_session)
        return jsonify(users=list_username, 
                       games=games, 
                       current_user=current_user, 
                       user_server=user_server)
Exemple #2
0
def send_state_field():
    """return the current snapshot field from database
    """
    if request.method == 'POST':
        if request.cookies.has_key('session_id'):
            cookie_session = request.cookies.get('session_id')
            update_user(**{ 'session_id': cookie_session, 'time': True })
            field = get_field_dictionary(cookie_session)
            user_status = get_user_status(cookie_session)
            number_watch_user = get_watch_users(cookie_session)
            return jsonify(field=field,
                           status=user_status,
                           number_watch_user=number_watch_user)