Invites in XNA Game Studio 3.0

Invites in XNA Game Studio 3.0

  • Comments 3

One of my favorite Xbox LIVE features is how you can go into your friends list, see what game people are playing, then join their current network session with just a couple of button presses. Or you can send an invite to a friend, asking them to come join your session.

If you made a networked game with the 2.0 XNA Framework, you probably noticed this wasn't enabled. I'm happy to report we fixed that for our 3.0 release.

The code you have to write to support invites is as minimal as we could make it. First, you subscribe to the InviteAccepted event, typically in your game constructor:

    NetworkSession.InviteAccepted += OnInviteAccepted;

This event handler should quit the current session (if any) and then join the new one:

    void OnInviteAccepted(object sender, InviteAcceptedEventArgs args)
    {
// Quit the current session if (networkSession != null)
{ networkSession.Dispose();
networkSession = null;
}
// Join the new session
networkSession = NetworkSession.JoinInvited(maxLocalGamers); }

That's it! The act of hooking up the InviteAccepted event will enable the "Invite to Game" and "Join Session In Progress" options in the Guide.

This code path is the same regardless of whether one player sends an invite to another, then the second player accepts it, or whether the second player chooses "Join Session In Progress" from their friends list, without the first player being directly involved. You can think of these two scenarios as pull vs. push, but your game handles them both using the same InviteAccepted event.

There is no need to confirm with the user before processing the event, because the Guide will have already taken care of that before it was delivered to you.

The really cool thing (and the part that caused the most tearing-out-of-hair while I was implementing it :-) is what happens when your friend is playing a different game to you, or if they are in the Dashboard and not playing any game at all.

On Xbox, if the target game is already installed, we will automatically reboot into it, then deliver the invite event as soon as it starts up.

If the invite is for an Xbox Creators game (one that is in development or peer review), and the target game is not installed, we just display a message saying the invite could not be delivered because the game was not found.

For Xbox Community games, on the other hand (ones that have made it through peer review and are being played by end users), when the target game is not installed we bring up a message asking if they want to download it. We take them to the appropriate Marketplace page, wait for the download to finish, then automatically launch the new game and deliver the invite.

This is a great way to encourage viral distribution. Make a fun multiplayer game that supports invites, convince one person to give it a go, and they can spread it to all their friends simply by sending invites!

On Windows, there is no good way for us to automatically find and launch the correct game even if it is installed locally, so we just bring up a message saying "please run game XXX". If you launch the correct game within a few minutes, the invite will be delivered when it starts up.

  • Shawn said:

    "This is a great way to encourage viral distribution. Make a fun multiplayer game that supports invites, convince one person to give it a go, and they can spread it to all their friends simply by sending invites!"

    I'm not quite sure how this would work. By way of example, lets imagine person A has the game and is playing it and they invite their firend, person B, to join him.

    Person B doesn't have the game, so when they receive the invite what choices do they have?

    Presumably they are given the choice to either accept or reject the invite? If so then surely accepting means that they have to buy a game they've probably never seen or tried before?

    I can't imagine many people will buy without having tried it first?

  • If the trial version of the game supports online play, it's just a matter of A inviting B, B downloading the trial version, then A & B playing together.

  • FlyingWaffle said:

    "If the trial version of the game supports online play, it's just a matter of A inviting B, B downloading the trial version, then A & B playing together."

    I thought trial versions of community games were treated as if you had a silver XBL membership. Do trial versions allow online trial play? If not then does that mean that an online multiplayer focused game, that doesn't have a single player component won't be able to have a trial version? Or is a game required to have some form of a trial version?

Page 1 of 1 (3 items)
Leave a Comment
  • Please add 6 and 4 and type the answer here:
  • Post