How To Test If A Player Can Purchase Your Game
A common flaw in lots of games is reacting to people hitting the “Buy Game” option and not making sure that user can actually purchase content. Almost worse is the common response that all you have to do is make sure the user is signed in to LIVE. That is wrong.
Child accounts, for example, can be set up to allow the user to be online but not be allowed to purchase the game. Remember that only the account that starts the game must be allowed unrestricted access to content. Other users can still join in and play. This means controller two might be Little Jonny who isn’t allowed to buy a game, but has a Silver LIVE account.
So here’s a little method I just wrote up that you can use all you want to determine if a given PlayerIndex matches up with someone allowed to buy your game:
public static bool CanPlayerBuyGame(PlayerIndex player)
{
SignedInGamer gamer = Gamer.SignedInGamers[player];
// if the player isn't signed in, they can't buy games
if (gamer == null)
return false;
// lastly check to see if the account is allowed to buy games
return gamer.Privileges.AllowPurchaseContent;
}
So steal this code and use it. You have to check the AllowPurchaseContent privilege to be absolutely sure a user is allowed to buy a game.
EDIT:
To make this cooler, let’s make an extension method for PlayerIndex that lets us do this:
public static class PlayerIndexExtensions
{
public static bool CanBuyGame(this PlayerIndex player)
{
SignedInGamer gamer = Gamer.SignedInGamers[player];
if (gamer == null)
return false;
return gamer.Privileges.AllowPurchaseContent;
}
}
So with this, all you have to do is a simple “if (PlayerIndex.One.CanBuyGame()) { }” and you’re all set. Gotta love C# 3.0.
Possibly Related Posts
(Automatically Generated)Basic Handling of Multiple Controllers
How To Make A Better Community Game
.NET Misconceptions Part 1
Need game assets?
Extending GamePadState

Can’t you just index into Gamer.SignedInGamers with a PlayerIndex without having to iterate through them?
SignedInGamer gamer = Gamer.SignedInGamers[player];
return gamer != null && gamer.IsSignedInToLive && gamer.Privileges.AllowPurchaseContent;
Ah yes you can. I always forget about that. I keep thinking that if controller 3 signs in they’ll be index 0, which they might be. But you are right; they have an overload that takes the PlayerIndex instead. Though, in essence, that’s likely what they’re doing under the hood. That or they really are sorting the gamers by index and then are just wrapping the cast to int in the PlayerIndex indexer.
I’ll just adjust the above code.
As for your other line, I’d personally use that, but I generally use more verbose code when doing samples. I find most people prefer it.
I suspect that’s what they’re doing under the hood, too. I mean, there are only up to four local players, so it’s pretty simple to iterate through them to find the appropriate PlayerIndex. And I do understand the motivation behind making your code more verbose. Explicit == good when explaining stuff.