question

juanrodriguezgiles avatar image
juanrodriguezgiles asked

Update Title Internal Data via CloudScript from Scheduled Task

Hi,

I'm trying to set up a Scheduled Task that runs a Cloud Script Azure Function. I want to update the Title Internal Data. Any feedback would be greatly appreciated. Here's my test code:

[FunctionName("TaskTest")]
        public static async Task Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log)
        {
            string body = await req.ReadAsStringAsync();
            ScheduledTaskFunctionExecutionContext<object> ctx = JsonConvert.DeserializeObject<ScheduledTaskFunctionExecutionContext<object>>(body);


            SetTitleDataRequest request = new SetTitleDataRequest
            {
                Key = "Test",
                Value = "1"
            };
            await PlayFabServerAPI.SetTitleInternalDataAsync(request);
        }

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

·
Seth Du avatar image
Seth Du answered

Referring to an Azure Function in Scheduled Tasks requires developers to register it on Game Manager, which means the function is potentially exposed to all players in the title.

Any player can execute this function if they figured out the function name, hence it is necessary to have a verification step before SetTitleInternalDataAsync is called.

I notice that you have defined ScheduledTaskFunctionExecutionContext and you may check the properties's value in "ctx" you have initialized, to make sure the context is not empty (when the function is triggered by other methods). You may also use context to check if the trigger source is title, instead of a player.

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

juanrodriguezgiles avatar image juanrodriguezgiles commented ·

Thanks for the info, i have updated the code but it's still failing when i try to run the task.

 public static async Task Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log)
        {
            string body = await req.ReadAsStringAsync();
            ScheduledTaskFunctionExecutionContext<object> ctx = JsonConvert.DeserializeObject<ScheduledTaskFunctionExecutionContext<object>>(body);


            if (ctx.TitleAuthenticationContext != null)
            {
                SetTitleDataRequest request = new SetTitleDataRequest
                {
                    Key = "Test",
                    Value = "1",
                    TitleId = ctx.TitleAuthenticationContext.Id
                };
                await PlayFabAdminAPI.SetTitleInternalDataAsync(request);
            }
        }



0 Likes 0 ·
error.png (58.8 KiB)
Seth Du avatar image Seth Du ♦ juanrodriguezgiles commented ·

What's the Title ID? I will take a look.

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.