question

My Studio avatar image
My Studio asked

Save data to other Player and shared data

Hello,

I am a new user of Playfab and I develop multiplayer game using Unity3D, I try to find right solution using PlayFab for game requirements. PlayFab covert most of our needs, but I have a question how to make next things:

  1. needed, Player1 save for Player2 data into TitleData. For example: Player1 attack a base of Player2 wher Player2 was offline. This event need to save and notify Player2.
  2. Is there any possibility to save data which is not linked to a user? For example, I need to keep battle statistics for a couple of days (what maps, how many people, results,etc.) All players should have access to these data.

Thanks

 

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

Sure thing:

1. The key is that you're not writing to Title Data, but rather some form of User Data or Shared Group Data. So, when player 1 attacks player 2 while 2 is offline, you can either write to player 2's User Read Only Data (where you're storing info on the state of their base), or to a Shared Group Data where you write the update from player 1 using that player's PlayFab ID as the Key. The latter is the recommendation, since it will help to prevent two different players writing to the same Key, and overwriting each others' data. That said, you are limited to 100 Keys in Shared Group Data, so each player should read the Shared Group Data list of changes and process them, deleting those Keys, on login, and a user whose Shared Group Data has grown too large due to not logging in for a long time should be considered "inactive", so that you don't keep adding more records to it.

We'll be providing for more asynchronous game-specific functionality later this year, which will help to simplify these scenarios.

2. Title Data and Content are the ways to store data which is intended to be accessed by all users, as it is designed to scale for that purpose. To provide stats to your community which is an aggregation of information across all users, you would need to collect a stream of events and aggregate that info, then update your Title Data with the results - often, this is done in a daily manner, updating the events for the previous day. Right now, the Appuri service Add-on would be one way to aggregate that info, but we'll also be updating shortly with a new events stream system (which you can see as a preview in our new Game Manager - https://n2.playfab.com) which will also allow you to do this.

10 |1200

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

My Studio avatar image
My Studio answered

Thank you for the feedback.

If I understand that Client API don't have access to User Read Only Data, right? We should use Server API to access this data and we should have a separate server for that, right?

About Shared Group Data (SGD) - can you please explain it more as it looks not clear for me. Player 1 (while he is offline) could be attacked by Player 2, Player 3, etc... up to 10 attacks from different attackers. Who can create Shared Group Data? Player 1? How the Player 2 will know SGD ID other players?

Or Player 2 should  create SGD and add there Player 1? And how the user will know that he addded to SGD? And if 10 players atacked then need to create 10 groups?

3 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.

huhund avatar image huhund commented ·

I'm trying to follow the steps above but I'm doing something wrong.

In postman I do:

* Login as Player2

* CreateSharedGroup with "SharedGroupId": "Player2_Shared"

I can see the shared data in the console and I can update it from postman logged in as Player2

Then I:

* Login as Player1

* GetSharedGroup with "SharedGroupId": "Player2_Shared"

That works fine. But when I want to write something there if fails:

UpdateSharedGroupData with "SharedGroupId": "Player2_shared", "Data": { "Player1_Attack": "Attack" }

I get:

"error": "NotAuthorized"

------

What is the correct way for Player1 to write to Player2 shared data group?

Best, Hu

0 Likes 0 ·
brendan avatar image brendan huhund commented ·

The Client API call can only write to the Shared Group if the player has been added to the ownership list of the group (https://api.playfab.com/documentation/server/method/AddSharedGroupMembers). Since anyone added to that can write anything to the Shared Group, we recommend not using that, and instead writing to the Shared Group only via Cloud Script (to prevent cheating).

0 Likes 0 ·
huhund avatar image huhund brendan commented ·

Yes! After some fiddling with cloud scripts I got it to work.

0 Likes 0 ·
brendan avatar image
brendan answered

Well, yes and no. You are correct that the client cannot write to User Read Only Data, or to a Shared Group Data that the player hasn't been explicitly added to. This is deliberate, so that you can have a secure place for data that cannot be written to by a hacked client.

And while the Server API can write to both those data stores, you don't need a separate server for that. You can create this logic in JavaScript handlers, and put it in Cloud Script in our service, where we run it on your behalf - that's also part of the free core service.

For the Shared Group Data, you would use a consistent naming pattern for the ID, and create the base data space when the player signs into the game for the first time. So, in your example, player 2 would create a Shared Group Data with the ID "{ {PlayFabId}}_attack", where { {PlayFabId}} is the PlayFab ID of player 2. Then, when player 1 attacks, he would write to that Shared Group Data with a Key of his own PlayFab ID and a Value containing any info needed about his attack. And all those writes would be via Cloud Script.

This would be a single Shared Group Data for the user, to hold the incoming attacks. With all the other users writing to a Key/Value pair using their PlayFab ID, you could then store attack info from 100 players (if a player attacked player 2 more than once while he's offline, he would update his own Key/Value pair at the end of the attack).

When player 2 next plays, he would read the contents of the Shared Group Data, apply those to his own local save info, and then clear the Shared Group Data.

1 comment
10 |1200

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

huhund avatar image huhund commented ·

I'm trying to follow the steps above but I'm doing something wrong.

In postman I do:

* Login as Player2

* CreateSharedGroup with "SharedGroupId": "Player2_Shared"

I can see the shared data in the console and I can update it from postman logged in as Player2

Then I:

* Login as Player1

* GetSharedGroup with "SharedGroupId": "Player2_Shared"

That works fine. But when I want to write something there if fails:

UpdateSharedGroupData with "SharedGroupId": "Player2_shared", "Data": { "Player1_Attack": "Attack" }

I get:

"error": "NotAuthorized"

------

What is the correct way for Player1 to write to Player2 shared data group?

Best, Hu

0 Likes 0 ·
My Studio avatar image
My Studio answered

Thanks a lot for the explanations. I have found solutios to resolve my tasks, looks like PlayFab is good tool to replace Parse. Hope PlayFab will be our one of the best tool for a long time ;)

10 |1200

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

potate avatar image
potate answered

Hi, this sounds great but what if the game he is developing is like Clash of Clans? How does the Shared group data method scale?

From the documentation, "Shared Group Data should not be used by groups larger than a dozen or so players, at most"

1 comment
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 commented ·

It would be greatly preferable to talk about specific feature designs using the details of the design, since when referencing an existing title in the market, different people will often have different perspectives on the features you have in mind.

Specific to this thread, Shared Group Data is not designed for use cases with many players.

Entity Objects and Files were designed for use by Groups (Clans/Teams/Guilds), and so can be used with upwards of 100 or so players.

There is no single, generic data system that can be updated by millions of users and read by millions of users, and have that data be always up-to-date. There are a number of systems designed for specific implementations, like the various ways you can use Redis, for example. In the case of PlayFab, we provide Title Data and a CDN service for cases where you update only occasionally - and only by a developer-driven action - and which can be used to serve data to all players. We'll be adding more systems tailored to different use cases in future updates.

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.