question

Dustin Adair avatar image
Dustin Adair asked

Invite friend to a game approach?

If I understand this correctly, the only way to handle a player inviting a friend to a game (when cross-platform) is to create a room with your ID, toss the friend's ID in your player data and make it so all idle players periodically (every 3-5 seconds?) poll all of their friends' data and see if they find their own ID listed, and if so, offer the opportunity to join that room and start the match. Push notifications aren't an option in a cross-platform situation and users aren't allowed to post data in other user's file so, as far as I know, this is the only approach. Is this correct?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

No, if you were polling all your friends' data at that rate, that could (for people with a lot of friends) rapidly exceed the rate limit on data calls.

We'll have a generic message system in place later on, but right now you actually can do this by posting the invite message to the other player's data space (Shared Group Data being a common place for this). You would do this via a Server API call in Cloud Script (http://api.playfab.com/Documentation/Server/method/UpdateSharedGroupData). So you could write it to the other player's Shared Group Data like so:

handlers.messageToPlayer = function (args) {
  var messageGroupId = args.toPlayerId + "_messages";
  var dataPayload = {};
  var keyString = currentPlayerId;
  dataPayload[keyString] = args.messageText;
  server.UpdateSharedGroupData(
    {
      "SharedGroupId": messageGroupId, "Data" : dataPayload
    }
  );
}

Care should be taken to not exceed the storage limit for the Shared Group Data though, so you should always delete the messages when processing them, as well as checking before you write that there aren't already too many outstanding messages.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Dustin Adair avatar image
Dustin Adair answered

Thanks for the info!

I'm still not clear on how this approach plays out. If you send the invite request to (for example) player_001, how does player_001 become aware of the invite? A constant polling (every 3-5 seconds) of their own shared group data? If so, then doesn't it still rack up the number of calls (albeit less than constantly polling all of your friend's data)?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Each player would need to do a periodic check of their Shared Group Data, to look for outstanding messages from others - say, every few mintues. That's around the same rate that larger services such as PSN or XBL do their "presence" checks, to look for available messages,

4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Dylan Hunt avatar image Dylan Hunt commented ·

^ Wonderful answer earlier with the cloud script example (which is also awesome since I'm still getting used to cloud script). Every few minutes? That seems very slow. "I sent you an invite man" then like 2 minutes later it pops up. Or is that just a mobile thing?

What about for PC? How often is "acceptable" to poll? Every 15s?

0 Likes 0 ·
Joshua Strunk avatar image Joshua Strunk Dylan Hunt commented ·

The longer polling time is not a mobile or PC thing, it is a backend service setup/style thing. PlayFab is not designed to handle real-time messaging, if every user in your game is constantly hammering PlayFab for data off the same sectors in their database it could result in degraded performance. (throttling).

1 Like 1 ·
brendan avatar image brendan Dylan Hunt commented ·

Shared Group Data and User Data are the same basic type of data, under the covers. It's just that SGD isn't player-specific, so it's a place you can put data for a small group of players, so that they're not all reading the data for each other player individually.

But yes, as Joshua said (and the other thread you started on this is really the best place for follow-ups on this - https://community.playfab.com/questions/9225/how-would-i-go-about-inviting-a-friend-to-a-party.html?childToView=9231#comment-9231), the service is not designed for that sort of behavior as a base. Custom contracts which provide for higher usage levels are an option, but otherwise I would recommend using a system that is designed for real-time experiences otherwise.

0 Likes 0 ·
Dylan Hunt avatar image Dylan Hunt brendan commented ·

"Shared Group Data and User Data are the same basic type of data, under the covers" ahh that explains it clearly, thanks!

As for messages like invite to group, I'll look for an alternative for something like this. Perhaps Steamworks allows for custom data for game invites.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.