> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Lobby invites

> Send and accept PlayFab Lobby invitations, use invitation listeners, and control who can invite others through lobby member and owner privileges.

This article provides an overview of Lobby invites and how to use them in the Lobby and Matchmaking SDK.

<Note>
  Only players (i.e. title\_player\_account PlayFab entities) can send or receive invites. Game servers (i.e. game\_server PlayFab entities) cannot. For more information on the how game servers interact with lobbies, see [Game Servers and Lobbies](/services/playfab/multiplayer/lobby/lobby-server-overview).
</Note>

## Invite types

There are two types of invites your game is likely to make use of.

1. [In-game invites](#joining-a-lobby-by-in-game-invites)
2. [Platform invites](#joining-a-lobby-by-platform-invites)

### Joining a lobby by in-game invites

* A member of a lobby may invite another player to that lobby directly via the lobby service.
* The lobby owner can choose to restrict sending invites to only the owner via the lobby property  **RestrictInvitesToLobbyOwner**
* This invite shares the lobby's connection string with the invited player.
* The invited player receives the invitation via **PFLobbyInviteReceivedStateChange** and can use the attached connection string to join the lobby.
* These invites work cross-platform but only work in-game.

### Joining a lobby by platform invites

* Members of the lobby can directly share the lobby's connection string with other players over platform-specific invite mechanisms.
* These invites don't work cross-platform but can be received without the recipient already running the game.
* Once the invited player receives the connection string via the platform mechanism, they can use the attached connection string to join the lobby.

## Example sending and receiving invites using the Lobby and Matchmaking SDK

Use **PFMultiplayerStartListeningForLobbyInvites** on the invite recipient to enable receiving in-game invites.

The invitation listener will change its status as **Listening** once it has been successfully set up.

```cpp theme={null}
HRESULT AllowInvitations(
    const PFEntityKey* entity)
{
    return PFMultiplayerStartListeningForLobbyInvites(g_pfmHandle, entity);
}

void HandleInvitationListenerStatusChange(
    const PFLobbyInvitationListenerStatusChangedStateChange& invitationListenerStateChange)
{
    PFLobbyInvitationListenerStatus status;
    HRESULT hr = PFMultiplayerGetLobbyInvitationListenerStatus(
        g_pfmHandle,
        &invitationListenerStateChange.listeningEntity,
        &status);
    assert(SUCCEEDED(hr));

    switch (status)
    {
        case PFLobbyInvitationListenerStatus::Listening:
        {
            Log("%s is listening for invitations", invitationListenerStateChange.listeningEntity.id);
            break;
        }
        case PFLobbyInvitationListenerStatus::NotAuthorized:
        {
            Log("Invitation listener not authorized!"); // this is likely an issue with the listener's entity token.
            break;
        }
        default:
    }
}
```

Use **PFLobbySendInvite** to send an invite to another PlayFab user via the lobby service.

The recipient will receive a **PFLobbyInviteReceivedStateChange**.

```cpp theme={null}
HRESULT SendInvite(PFLobbyHandle lobby, const PFEntityKey* sender, const PFEntityKey* receiver)
{
    return PFLobbySendInvite(lobby, sender, receiver, nullptr);
}

void HandleInvitationNotification(const PFLobbyInviteReceivedStateChange& invite)
{
    Log("%s invited to lobby by %s", invite.listeningEntity.id, invite.invitingEntity.id);
    // pass invite.connectionString to PFMultiplayerJoinLobby
}
```

## See also

* [Lobby and matchmaking](/services/playfab/multiplayer/lobby/lobby-and-matchmaking)
* [Find lobbies](/services/playfab/multiplayer/lobby/find-lobbies)
* [Join lobbies](/services/playfab/multiplayer/lobby/join-lobbies)
* [Lobby properties](/services/playfab/multiplayer/lobby/lobby-properties)


## Related topics

- [PFLobbyInviteListenerStatus](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/enums/pflobbyinvitelistenerstatus.md)
- [LobbyInviteListenerStatus](/services/playfab/multiplayer/lobby/unity-multiplayer-api-reference/PlayFab.Multiplayer/LobbyInviteListenerStatus.md)
- [PFMultiplayerStartListeningForLobbyInvites](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/functions/pfmultiplayerstartlisteningforlobbyinvites.md)
- [Join lobbies](/services/playfab/multiplayer/lobby/join-lobbies.md)
- [PFMultiplayerStopListeningForLobbyInvites](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/functions/pfmultiplayerstoplisteningforlobbyinvites.md)
