Hi.
I am working on uploading leaderboard scores with Azure Functions in my Unity Game. For now I have succeeded (the Azure Function works perfectly), but I have one doubt.
This is the Azure Function:
namespace FuncionRankingPrueba1 { public static class RankingPrueba { [FunctionName("UpdateRanking2602V3")] public static async Task<dynamic> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { string name; string time; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); name = data?.FunctionArgument?.name; time = data?.FunctionArgument?.time; int timeint = int.Parse(time); var request = new UpdatePlayerStatisticsRequest { PlayFabId = data.CallerEntityProfile.Lineage.MasterPlayerAccountId, Statistics = new List<StatisticUpdate> { new StatisticUpdate { StatisticName = name, Value = timeint } } }; var apiSettings = new PlayFabApiSettings { TitleId = data.TitleAuthenticationContext.Id, DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY", EnvironmentVariableTarget.Process), }; var serverApi = new PlayFabServerInstanceAPI(apiSettings); return await serverApi.UpdatePlayerStatisticsAsync(request); } } }
I have added an Application Settings in Azure that is the PLAYFAB_DEV_SECRET_KEY, with my SECRET KEY found in Title Settings, so when Environment.GetEnvironmentVariable is called, it founds my DEV_SECRET_KEY. Without this, it doesn't work.
My question is: when I publish my game on the Play Store, do the players use my PLAYFAB_DEV_SECRET_KEY to update their score or do I need to change something of my azure function code?
For example this line of code.
DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY", EnvironmentVariableTarget.Process)
Do I also need to change any setting on the Azure Portal?
I don't know if the set up that I have right now is good for testing everything but not when a lot of players upload their scores once the game is on the Play Store.
Thanks.
Answer by Made Wang · Feb 28 at 07:36 AM
Your code doesn't need to be modified. Regarding PLAYFAB_DEV_SECRET_KEY, it is a global parameter you declare in the Azure portal, you can also declare any custom parameter in the Azure portal. And, because you are calling the serverAPI, you need to get the SECRET KEY, which is required both in AzureFunction and other servers. Are you worried about security? In fact, clients can only call this method, they can't know the content of the method, nor can they get the PLAYFAB_DEV_SECRET_KEY.
Thanks a lot. You are always there to answer my questions. Sorry if I ask too many. I am completely alone making my game and I have to take care of everything (Leaderboards, Security, Game Design, Level Design, 3D modeling, all the UI and UX, etc...) and it is a little bit overwhelming.
best practice for saving statistics for leaderboards 1 Answer
Can Cloud Code Access the Admin API 1 Answer
Update Statistic: invocation of cloud script function failed 1 Answer
CustomTags conditions,Custom tag in conditions 2 Answers
Advantages of CloudScript over Calling JavaScript from Node.js 1 Answer