question

hulosowanie7 avatar image
hulosowanie7 asked

CloudScript Authentication

Hey!

Please help me make an Authentication CloudScript with game (I mean that the players using "Repeater" are not able to CALL CloudScript unlimited times)

I have something like this:

CloudScript:

handlers.SetCodeDeposit = function(context)

{ var previousState = {};

var getPlayerInfo = server.GetUserData ({ PlayFabId: currentPlayerId, Keys: ["Code"], });

if(getPlayerInfo.Data.hasOwnProperty("Code"))

{ previousState = getPlayerInfo.Data["Code"].Value; }

if(!getPlayerInfo.Data.hasOwnProperty("Code"))

{ var setPlayerInfo = server.UpdateUserData({ PlayFabId: currentPlayerId, Data: { ["Code"]:JSON.stringify(Math.floor(Math.random() * 1000000)) } });

var getPlayerInfo = server.GetUserData ({ PlayFabId: currentPlayerId, Keys: ["Code"], });

previousState = getPlayerInfo.Data["Code"].Value; }

return(((previousState * previousState) - 1337) * 3); }

In Unity C#:

code = Math.Sqrt((double.Parse(cloudResult.FunctionResult.ToString()) / 3) + 1337).ToString();

But it doesn't work (someone hacked and get "code" and was able to set a good code during CALL)

Please help me!!!

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

·
Xiao Zha avatar image
Xiao Zha answered

Since you save the “Code” in the player data, which can be obtained and modified by client through Get User Data API and Update User Data API. If you don’t want the “Code” to be modified by client, you can use player read only data or player internal data to save the “Code”, then use Get User Internal Data and Get User Read Only Data to get the “Code” and use Update User Internal Data and Update User Read Only Data to modify the “Code”.

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.