async def join_game(request, persistence):
    """Join a game and provide a name."""
    game_id = request.match_info['game_id']
    json = await request.json(loads=loads_or_empty)

    try:
        player_name = json['name']
    except KeyError:
        return json_response({'error': 'Must provide a name.'}, status=400)

    if len(player_name) < 1:
        return json_response({'error': 'The name must not be empty.'}, status=400)

    player_session = await get_session(request)
    player_id = get_or_assign_id(player_session)

    try:
        persistence.add_player(game_id, player_id, player_name)
    except NoSuchGame:
        return json_response({'error': 'There is no such game.'}, status=404)
    except PlayerNameTaken:
        return json_response({'error': 'There is already a player with such name in the game.'},
                             status=409)
    except PlayerAlreadyRegistered:
        return json_response({'error': 'The client is already registered in this game.'},
                             status=409)

    return json_response({'game': persistence.serialize_game(game_id)})
async def add_game(request, persistence):
    """
    Create a new game.

    The user will become the moderator of the game.
    """
    json = await request.json(loads=loads_or_empty)

    try:
        available_cards = json['cards']
    except KeyError:
        return json_response({'error': 'No card set provided.'}, status=400)

    moderator_name = json.get('moderator_name', '')
    if moderator_name == '':
        return json_response({'error': 'Moderator name not provided.'}, status=400)

    if len(available_cards) < 2:
        return json_response({'error': 'Cannot play with less than 2 cards.'}, status=400)

    moderator_session = await get_session(request)
    # Get or assign the moderator id:
    moderator_id = get_or_assign_id(moderator_session)
    game_id = get_random_id()
    persistence.add_game(game_id, moderator_id, moderator_name, coerce_cards(available_cards))

    return json_response({'game_id': game_id, 'game': persistence.serialize_game(game_id)})