I don't want that a player updates his country data and display name frequently. I use this code to create the data. For example:
var resultprofile = await PlayFabClientAPI.UpdateUserDataAsync(new UpdateUserDataRequest() { Data = new Dictionary<string, string>() { {"Country", "Germany"} } }); var resultupdate = await PlayFabClientAPI.UpdateUserTitleDisplayNameAsync(new UpdateUserTitleDisplayNameRequest() { DisplayName = "Bart Simpson" });
You can enter your PlayFab display name and country in my application when you start it the first time. Then, this code is executed. After that, it is no more possible to run this code in my application. But would it still be possible that a player could update the country data and display name somehow because it is always allowed in the Client Profile Options in Game Manager?
Is it possible to only allow creating/updating the PlayFab display name and country once(when the player starts the game the very first time)?
If not, is it at least possible to reduce updating it at once a month?
EDIT:
I get another error message. What is wrong with PlayerProfile?
Raw event JSON { "EventName": "player_executed_cloudscript", "Source": "CloudScript", "FunctionName": "UpdateDisplayname", "CloudScriptExecutionResult": { "FunctionName": "UpdateDisplayname", "Revision": 20, "FunctionResult": null, "FunctionResultTooLarge": null, "Logs": [], "LogsTooLarge": null, "ExecutionTimeSeconds": 0.024806699999999998, "ProcessorTimeSeconds": 0, "MemoryConsumedBytes": 40784, "APIRequestsIssued": 1, "HttpRequestsIssued": 0, "Error": { "Error": "JavascriptException", "Message": "JavascriptException", "StackTrace": "TypeError: Cannot read property 'PlayerProfile' of undefined\n at handlers.UpdateDisplayname (BFD0A-main.js:9:32)" } }, "EventNamespace": "com.playfab", "EntityType": "player", "TitleId": "BFD0A", "EntityId": "A8C95897B42FE00A", "EventId": "6c8d1d5e2dcf404c981cc5780948a2c2", "SourceType": "BackEnd", "Timestamp": "2019-09-18T11:12:41.9851659Z", "History": null, "CustomTags": null, "Reserved": null, "PlayFabEnvironment": { "Vertical": "master", "Cloud": "main", "Application": "logicserver", "Commit": "41925c5" } }
My cloudScript:
handlers.UpdateDisplayname = function (args, context) { var NewDisplayname = args.DesiredDisplayname; var resultprofile = server.GetPlayerProfile({PlayFabID: currentPlayerId, ProfileConstraints: {ShowDisplayName: true}}) var CurrentDisplayName = ""; if (resultprofile.Error == null) { if (resultprofile.Result.PlayerProfile != null) { CurrentDisplayName = resultprofile.Result.PlayerProfile.DisplayName; if ((CurrentDisplayName == null) || (CurrentDisplayName == "")) UpdateUserTitleDisplayNameFromCloudScript(NewDisplayname, currentPlayerId); else log.info("You already have a display name. It's not possible to change it:" + CurrentDisplayName.toString()); } } } function UpdateUserTitleDisplayNameFromCloudScript(DesiredDisplayname, PlayFabId) { var contentBodyTemp = { "DisplayName": DesiredDisplayname, "PlayFabId": PlayFabId }; let url = "https://BFD0A.playfabapi.com/Admin/UpdateUserTitleDisplayName"; let method = "POST"; let contentBody = `{"PlayFabId": "${PlayFabId}", "DisplayName": "${DesiredDisplayname}"}`; let contentType = "application/json"; let headers = { "X-SecretKey": "..." }; let responseString = http.request(url, method, contentBody, contentType, headers); let responseJSONObj = JSON.parse(responseString); return (responseJSONObj.data); }
Client code:
private async Task UpdateDisplayname() { var result = await PlayFabClientAPI.ExecuteCloudScriptAsync(new ExecuteCloudScriptRequest() { FunctionName = "UpdateDisplayname", FunctionParameter = new { DesiredDisplayname = "Mynewdisplayname" }, GeneratePlayStreamEvent = true }); if (result.Error != null) Console.WriteLine(result.Error.Error.ToString()); else Console.WriteLine("Your new displayname: " + "Mynewdisplayname"); }