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

# Handling protocol activation to start a game by using 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)](https://docs.xbox.com/services/xbox-services/multiplayer/mpm/concepts/flowcharts/live-mpm-on-protocol-activation.md).

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](https://docs.xbox.com/reference/system/xgameactivation/functions/xgameactivationregisterforevent.md). With the invite handle, call [XblMultiplayerManagerJoinLobby](https://docs.xbox.com/reference/live/xsapi-c/multiplayer_manager_c/functions/xblmultiplayermanagerjoinlobby.md).

If the invited user isn't added via [XblMultiplayerManagerLobbySessionAddLocalUser](https://docs.xbox.com/reference/live/xsapi-c/multiplayer_manager_c/functions/xblmultiplayermanagerlobbysessionaddlocaluser.md), [XblMultiplayerManagerJoinLobby](https://docs.xbox.com/reference/live/xsapi-c/multiplayer_manager_c/functions/xblmultiplayermanagerjoinlobby.md) fails and provides the xuid that the invite was sent for by calling [XblMultiplayerEventArgsXuid](https://docs.xbox.com/reference/live/xsapi-c/multiplayer_manager_c/functions/xblmultiplayereventargsxuid.md) 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](https://docs.xbox.com/reference/live/xsapi-c/multiplayer_manager_c/functions/xblmultiplayermanagerlobbysessionsetsynchronizedhost.md) 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](https://docs.xbox.com/reference/live/xsapi-c/multiplayer_manager_c/functions/xblmultiplayermanagerlobbysessionsetlocalmemberconnectionaddress.md).

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

- [Multiplayer Manager example code (contents)](https://docs.xbox.com/services/xbox-services/multiplayer/mpm/how-to/live-mm-howto-nav.md)
- [Multiplayer Manager overview](https://docs.xbox.com/services/xbox-services/multiplayer/mpm/live-multiplayer-manager-overview.md)
- [Handling protocol activation (flowchart)](https://docs.xbox.com/services/xbox-services/multiplayer/mpm/concepts/flowcharts/live-mpm-on-protocol-activation.md)
- [Receiving invites](https://docs.xbox.com/services/xbox-services/multiplayer/invites/how-to/live-invites-receive.md)
- [Multiplayer Manager flowcharts (contents)](https://docs.xbox.com/services/xbox-services/multiplayer/mpm/concepts/flowcharts/live-mm-flowcharts-nav.md)
