question

gage avatar image
gage asked

Adding Items / Currency via CloudScript

Hello,

Basically I came across the CloudScript service and seen it noted that it helps with anti-cheat. So what im trying to do is have the player call the "BuyItem" or "AddCurrency" methods via Unity. I have this done already with the Client versions of the playfab side but i just dont know how to transfer that to server and cloudscript.

CloudScript
10 |1200

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

1 Answer

·
Joshua Strunk avatar image
Joshua Strunk answered

It is hard to give specific advice without knowing what your "BuyItem" and "AddCurrency" calls do. I am going to assume you are talking about calling PlayFab.Client.PurchaseItem and PlayFabClient.AddUserVirtualCurrency?

PurchaseItem is already secure so unless you need to do something with the granted item (like set some custom data on the item instance) you should just keep using PurchaseItem from the client.

AddUserVirtualCurrency, however, is not. If you are wanting to set up some kind of purchase flow for the currency you can set up some bundles/chests in the PlayFab's item system and then use PurchaseItem to purchase the currency. If you need to grant currency to a user for testing you could also just grant it through the game manager.

So what if you want a secure way for some users to grant themselves currency from the game client? You would have the code calling "AddCurrency" now instead call PlayFab.Client.ExecuteCloudScript. This would call a CloudScript handler you have written which can check for some flag and then call server.AddUserVirtualCurrency.

Helpful Links

https://api.playfab.com/documentation/client/method/PurchaseItem

https://api.playfab.com/documentation/client/method/AddUserVirtualCurrency

https://api.playfab.com/documentation/client/method/ExecuteCloudScript

https://api.playfab.com/docs/tutorials/landing-automation/using-cloud-script

https://api.playfab.com/docs/tutorials/landing-automation/writing-custom-cloud-script

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

gage avatar image gage commented ·

Hi okay thank you.

Is there any documentation for the cloud script showcasing the way to call things. Like a web reference telling me what server.AddVirtualCurrency does and its return, parameters, etc. Or are these things you should know? I use that call in unity via the client api but when writing a CloudScript theres no intellisense so its hard to see whats available to call.

0 Likes 0 ·
brendan avatar image brendan gage commented ·

They're actually the same calls you see in the documentation (https://api.playfab.com/documentation/server), so you can see the request and response parameters there. To see an example of use, have a look at revision 1 in your Cloud Script in any title - we automatically put a sample script revision there in all titles.

0 Likes 0 ·
subzero911 avatar image subzero911 commented ·

What if player hacks the client and sends fake request "Add me 100500 golds"? How can CloudScript track this?

0 Likes 0 ·
brendan avatar image brendan subzero911 commented ·

All titles have the Client/AddUserVirtualCurrency API call turned off by default, specifically because that would make it trivially easy for a hacked client to cheat. If you have a scenario in which the client is allowed to say that some VC should be added to the player balance, we would recommend using a Cloud Script so that you can have appropriate checks in the server-side logic to make sure the player isn't cheating.

0 Likes 0 ·
subzero911 avatar image subzero911 brendan commented ·

Yes, I understand. And I ask: how to make these checks? How to track in CloudScript function whether user is cheating? There's no any hints in documentation about concrete implementation.

0 Likes 0 ·
Show more comments

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.