question

brendan avatar image
brendan asked

Account merging

Question from a developer:

Let's say I have the option to sign in with Device ID and Facebook in my game. On two different devices, the player account was created with Device ID. Later, the player links one of those to Facebook. Later still, he wants to link the other device to Facebook. But those are two different accounts, so how do I handle the merge?

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.

ghanasyamkr avatar image ghanasyamkr commented ·

Is there an answer available for this?

,

Is there an example available for this?

0 Likes 0 ·
brendan avatar image
brendan answered

As account merging is very game specific (which stats should be taken? what values should be added? should inventory be added together? virtual currencies? etc.), we don't do any form of automatic account merging right now, though we may create a system for this in the future, if enough people say it's a priority for their title(s). My general advice on this is to provide the option to the player. So, if the player chooses to try to link Facebook, and you find that there's already an account using that authentication mechanism for the player, I would grab the info from the other account and offer the player the option of choosing one or the other. Then, you would unlink the account the player is abandoning from its current auth mechanism using an Unlink... call, and add it to the account they want to use with a Link... call. You could also grab any key info you need from the account being abandoned that way, including any inventory or VC you want to bring over. The key for that would be to control the merged data using Cloud Script, so that players can't use it as a cheating vector.

Basically, what you would have is a script where you pass in the PlayFab ID of the second account (the one going away), and use that plus the built-in currentPlayerId in the script to query all the things you need - inventory, data, stats, etc. Deciding what you do with those is the part that's going to be very title-specific - keeping the highest stat, adding together their VC, etc.

In order to secure this (to prevent people abusing it), there are two additional things you'll need to do:

1. Just before merging, while you have session tickets for both accounts on the local machine, write a randomly generated GUID to the User Data of both profiles from the client. When you start the merge, check that value on both accounts, to ensure they match. That's so that no one with a hacked client can send up a call to the Cloud Script with someone else's PlayFab ID, to try to steal their account by merging it into their own.

2. After you're done, set a value in User Internal Data to indicate that the account has been merged, so that it can't be merged again (gaining the items multiple times). Check that value at the start of the script, and if it's already set, don't allow the merge.

10 |1200

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

andrew@spryfox.com avatar image
andrew@spryfox.com answered

Great answer, thanks. And I guess I can tell if (eg) a facebook account has already been claimed from the error code when attempting to link? Or is there another better way? 

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

Correct - if you call LinkFacebookAccount using a token for a user who has already linked Facebook to another PlayFab profile, you'll get the error "AccountAlreadyLinked".

10 |1200

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

Mustumasti avatar image
Mustumasti answered

Could I add multiple devices to a single PlayFab account?

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

Yes, multiple devices can be linked to the same account. If you're linking multiple items of the same type (iOS, for example), there is one known issue in that you can only unlink the current device (last logged in device). We'll be updating to provide a better experience for that in an upcoming release.

10 |1200

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

Amar avatar image
Amar answered

It would be really useful to have a recipe code for Account merging, with an example (Unicorn Battle) maybe. I would like to have this piece of code as a core functionality to the PlayFab, and have ability to select fields in the GameManager when merging happens. 

This post is really helpful. 

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

Thanks, I'll add a backlog item for the tools team to put together an example.

10 |1200

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

Impaxive1aun avatar image
Impaxive1aun answered

Hi @Brendan. I think providing a code snippet is more helpful than sharing a detailed answer. Can you please share code for account merge implementation for Facebook? Thanks in advance.

10 |1200

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

Chris Parkinson avatar image
Chris Parkinson answered

Any update on an example for this question? Is best practice to offer them the choice of account and then "ForceLink" to that choice? Then we just handle the merged account data ourselves through a cloud script?

10 |1200

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

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.