> ## 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.

# Handle protocol activation with Multiplayer Manager

> Use XBOX Multiplayer Manager to handle protocol activation when a player accepts a game invite or joins from a gamercard, including lobby join handling.

This topic describes using Multiplayer Manager to handle protocol activation.

*Activation* is when the system automatically starts a game in response to another action. This is typically done when a player accepts a game invite from another player.

Your title can get protocol-activated in the following ways.

* A user accepts a game invite
* A user selects "Join Game" from a player's gamercard

This scenario covers how to handle the protocol activation when your title is launched, a player joins the lobby, and a game is in progress (if one exists).

For a flowchart of the protocol activation process, see [Handling protocol activation (flowchart)](/services/xbox-services/multiplayer/mpm/concepts/flowcharts/live-mpm-on-protocol-activation).

When a player accepts a game invite or joins a friend's game through the player's gamercard, the game is launched on their device by using protocol activation.
After the game starts, get the invite handle by using [XGameActivationRegisterForEvent](/reference/system/xgameactivation/functions/xgameactivationregisterforevent). With the invite handle, call [XblMultiplayerManagerJoinLobby](/reference/live/xsapi-c/multiplayer_manager_c/functions/xblmultiplayermanagerjoinlobby).

If the invited user isn't added via [XblMultiplayerManagerLobbySessionAddLocalUser](/reference/live/xsapi-c/multiplayer_manager_c/functions/xblmultiplayermanagerlobbysessionaddlocaluser), [XblMultiplayerManagerJoinLobby](/reference/live/xsapi-c/multiplayer_manager_c/functions/xblmultiplayermanagerjoinlobby) fails and provides the xuid that the invite was sent for by calling [XblMultiplayerEventArgsXuid](/reference/live/xsapi-c/multiplayer_manager_c/functions/xblmultiplayereventargsxuid) with the `JoinLobbyCompleted` event.

After joining the lobby, we recommend setting the local member's connection address and any custom properties for the member.
You can also set the host via [XblMultiplayerManagerLobbySessionSetSynchronizedHost](/reference/live/xsapi-c/multiplayer_manager_c/functions/xblmultiplayermanagerlobbysessionsetsynchronizedhost) if one doesn't exist.

Finally, the Multiplayer Manager auto-joins the user into the game session if a game is already in progress and has room for the invitee.
The title is notified through the `JoinGameCompleted` event, providing an appropriate error code and message.

#### Flat C API

```cpp theme={null}
#include <XTaskQueue.h>
#include <XGameActivation.h>  
  
XTaskQueueHandle g_taskQueue;  
XTaskQueueRegistrationToken g_activationToken;  
  
void CALLBACK OnActivation(void* context, const XGameActivationInfo* activationInfo)  
{  
    if (activationInfo->type == XGameActivationType::AcceptedGameInvite)
    {
        if (activationInfo->inviteUri != nullptr)
        {
            std::string inviteString(activationInfo->inviteUri);
            auto pos = inviteString.find("handle=");
            auto inviteHandeId = inviteString.substr(pos + 7, 36);
            // Now, call XblMultiplayerManagerJoinLobby.
        }
    }
}  
  
void InitializeGame()  
{  
    XGameActivationRegisterForEvent(g_taskQueue, nullptr, OnActivation, &g_activationToken);  
}  
  
void ShutdownGame()  
{  
    XGameActivationUnregisterForEvent(g_activationToken, true);  
}  
```

```cpp theme={null}
HRESULT hr = XblMultiplayerManagerLobbySessionSetLocalMemberConnectionAddress(
    xblUserHandle, connectionAddress, context);
```

For more information, see [XblMultiplayerManagerLobbySessionSetLocalMemberConnectionAddress](/reference/live/xsapi-c/multiplayer_manager_c/functions/xblmultiplayermanagerlobbysessionsetlocalmemberconnectionaddress).

Multiplayer Manager performs the following functions.

* Register Real-Time Activity and multiplayer subscriptions.
* Join lobby session.
* Existing lobby state cleanup.
* Join all local players as active.
* Upload secure device address (SDA).
* Set member properties.
* Register for session change events.
* Set lobby session as active session.
* Join game session (if one exists).
* Use a transfer handle.


## Related topics

- [How to](/services/xbox-services/multiplayer/mpm/how-to/index.md)
- [Handling protocol activation (flowchart)](/services/xbox-services/multiplayer/mpm/concepts/flowcharts/live-mpm-on-protocol-activation.md)
- [Multiplayer Manager example code](/services/xbox-services/multiplayer/mpm/how-to/live-mm-howto-nav.md)
- [Sending invites](/services/xbox-services/multiplayer/invites/how-to/live-invites-send.md)
- [Multiplayer Manager flowcharts](/services/xbox-services/multiplayer/mpm/concepts/flowcharts/live-mm-flowcharts-nav.md)
