Prerequisite
To receive game invite notifications on a Windows PC, install the XBOX Game Bar. The XBOX Game Bar app is installed by default on Windows 10, OS version 1903 or later. Select Windows Key+G to launch the XBOX Game Bar app to verify that it’s installed correctly.If XBOX Game Bar isn’t installed on your Windows PC, you can install it from the Microsoft Store.
Registering for multiplayer protocol
Registering for multiplayer protocol tells the system how to launch your game when the user accepts a multiplayer game invite. To register the multiplayer protocol, you need to add aMultiplayerProtocol element to your MicrosoftGame.config file as shown in the following code.
Executable attribute as shown in the following code.
Registering for multiplayer game invite callbacks
The
XGameInviteRegisterForEvent and XGameInviteUnregisterForEvent APIs are now deprecated. Use XGameActivationRegisterForEvent and XGameActivationUnregisterForEvent instead. For migration guidance, see XGameActivation.Flat C
inviteUri that’s passed into the OnActivation() handler method in the sample code above from the XGameActivationRegisterForEvent callback. Then the title must wait for the RegisterAppStateChangeNotification which notifies when the game has fully resumed before the title proceeds to operate on the session by using the details that are provided in the inviteUri.
For more information about RegisterAppStateChangeNotification, see XBOX Game Life Cycle (NDA topic).
Parsing inviteUri from XGameActivationCallback
When your game receives the XGameActivationCallback event with an activation type ofAcceptedGameInvite, you can access the inviteUri string from the XGameActivationInfo structure. The inviteUri is in one of the following formats.
For accepting a game invite
When the user accepts a game invite, the game receives the game invite callback with aninviteUri as shown in the following code.
inviteHandleAcceptindicates that the callback was initiated because the user accepted a game invite.handleis the invite handle you use to join the multiplayer session.invitedXuidis the ID of the XBOX services user who’s invited to the multiplayer session.senderXuidis the ID of the XBOX services user who sent the game invite.contextis the additional (optional) context the sender might have included.
For joining a game session in progress
When the user attempts to join a multiplayer session, the game would receive an invite callback with aninviteUri as shown in the following code.
activityHandleJoinindicates that the callback was initiated because the user accepted a game invite.handleis the activity handle you use to join the multiplayer session.joinerXuidis the ID of the XBOX services user who’s attempting to join the multiplayer session.joineeXuidis the ID of the XBOX services user who’s currently in the multiplayer session.
Joining a multiplayer game session with handleId
Using Multiplayer Manager
If you’re using Multiplayer Manager, you can join the user to the multiplayer session by using the XblMultiplayerManagerJoinLobby API and passing in thehandleId that’s extracted from the inviteUri. You can also use the xblUserHandle for the invitedXuid as shown in the following code.
Flat C
Using Multiplayer API directly
If you’re using Multiplayer API, use the following steps to configure multiplayer sessions and invites for your title.- Fetch the multiplayer session document by using the XblMultiplayerGetSessionByHandleAsync API and pass it in the
handleId. - Join the local user to the multiplayer session document by using the XblMultiplayerSessionJoin API.
- Write the multiplayer session document to the service to commit this change by using the XblMultiplayerWriteSessionByHandleAsync API.
