How To: Add Support for Game Invitations
The XNA Framework player match multiplayer network session type enables players to invite friends to play a game online over LIVE. Games of this type are able to host other players when the session is joinable, when there are open slots, and when game invitations are enabled.
Gamers can accept game invitations from the message center or while viewing the friends list. In addition, a gamer can request to join an existing game session without an invitation by selecting Join Session In Progress while viewing the friends list.
When someone accepts an invitation for Xbox LIVE Community Games, but the game is not installed already on his or her computer, the invited player will be taken to the game offer. The offer enables the invited player to download the game and accept the invitation to start the game.
For creator games still waiting to pass peer review, the game invitation will be sent over the Xbox LIVE service to the other player. If the game is not installed the invited player will be prompted with a message indicating that he or she can get the game from the game creator.
To register for the InviteAccepted event
To respond to the InviteAccepted event
Two actions might result in the delivery of the NetworkSession.InviteAccepted event: either a player can view the friends list and accept an invitation, or a player without a game invitation can go to the friends list and select Join Session In Progress to request to join a friend's session.
If the gamer accepts an invitation or selects the Join Session In Progress option, an event notification will be sent to the game. When the game processes this notification, it is then sent to the registered event handler.
|If an invite is pending because the game automatically started in response to a cross-title invite, the method to handle the game invitation event will be called as soon as you subscribe to the event. Because of this, it is important to initialize everything upon which the event handler depends before it is registered.|
To display the game invitation user interface
Whenever the game is able to host other gamers, the Send Game Invite option button will automatically be displayed in the Xbox LIVE friends list. Because a gamer can send invitations at any point simply by pressing the Guide button and navigating to the friends list, it is usually not neccessary to use the Guide.ShowGameInvite method. As a result, adding a game logic call Guide.ShowGameInvite at a particular instance in a game as demonstrated here is optional, but this action may provide a more polished user experience.