question

mzaku avatar image
mzaku asked

[CloudScript] Playfab Account Initialization

Greetings,

we're really happy with using PlayFab so far. The client and server APIs are both very clean and well implemented within the SDKs.

We're having a problem with account initialization using CloudScript and the server request limit of 15, though:

We're working on a TD / city building game similar to clash of clans and when initializing the account, we need to add more than 15 items to the player's inventory. Also, those items need to get customData for position, health etc.

So we need a request for creating a new character, which is the village (so we can easily drop the village's data later), a request for creating 20 items at once (but without customData) and then we need to iterate over those 20 items to fill them with customData.

Our current solution has the CloudScript sending a new request to itself, providing the itemInstanceIds and an iterator-index, which tells the script, at which index to continue filling the itemInstances with customData.

We're wondering though about concurrency: what happens, if the client sends two requests at once? Will the second request be handled inbetween? So, if he sends accountInit and sellBuilding and accountInit needs to call itself once, to exceed the request limit 15, could it happen, that it's handled in this order? accountInit1 -> sellBuilding -> accountInit2?

Also, is there already a standard solution for concurrent updates? So, is there a safe way for calling cloudscript without having to worry, that if the user for example changes two building's positions to the same spot at the same time, both get updated at the same time, assuming for both, that the spot is still empty?

I'm really looking forward to your response and further development with PlayFab.

Best regards,

Marc Zaku

Account ManagementCloudScriptlimitsPlayer Inventory
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.

mzaku avatar image mzaku commented ·

I believe that having a function that can bulk create or bulk change item custom data would not only solve the problem, but be pretty useful anyway (if there's no technical limitations)

0 Likes 0 ·

1 Answer

·
brendan avatar image
brendan answered

All requests to the service are handled independently. So if a client were to send two requests at once, there's no way to guarantee which will be completed first. The best way to manage requests for a client is to serialize them, so that you wait on the results of each request before issuing the next one. In cases where you need extremely low latency, I would recommend using a custom game server which manages the player state and periodically updates the main service data with the player state.

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.

mzaku avatar image mzaku commented ·

We already assumed that. We will do so on the client side, but is there a concept already for preventing hacked clients from cheating?

If there is let's say a cloudScript-function: moveBuilding(args: {itemId, positionX, positionY}, context) and it validates, that the space on the grid is empty and then moves the building to the position, is there a way to "lock" the game state, so there's no race conditions and other bugs happening, when a player hacks a client to send many requests at once, trying to pile up all their buildings on a single spot?

0 Likes 0 ·
brendan avatar image brendan mzaku commented ·

That's the problem - locks introduce another class of problem entirely (increasing complexity and cost). The system is designed to be as simple as possible, while providing you with the hooks needed to be as secure as you need to be. In the case of managing state information so that players can't cheat, the only really effective way to do that is by using a custom game server, so that the changes to the state are managed at a single source.

0 Likes 0 ·
mzaku avatar image mzaku commented ·

Oh, and thank you for the awesome support so far, Brendan! Your response rates are insane!

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.