I have spent today learning Cloudscript Functions and implementing Playfab Server API calls via Azure Functions but I was hoping to find additional resources other than the quckstart guide to further my understanding on writing clean code and best practices. Are there additional resources someone could provide?
For instance, I specifically wrote an Azure Function in C# for a "Two-way Friend Confirmation" following some of the guide lines found in this post. Sure it works, however, I am curious if I am overlooking anything in terms of a cleaner/more efficient way to write it and if there is any issue (regarding security) getting another player's PlayFabId through the client?
I get another player's Playfab Id through a Client API call in Unity and pass it to this Cloudscript Function:
namespace NetworkSystem.FriendRequest { public static class FriendRequest { [FunctionName("FriendRequest")] public static async Task<dynamic> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { var context = JsonConvert.DeserializeObject <FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync()); dynamic args = context.FunctionArgument; string senderID = context.CallerEntityProfile.Lineage.MasterPlayerAccountId; string targetID = args["friendID"]; PlayFabSettings.staticSettings.DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY", EnvironmentVariableTarget.Process); PlayFabSettings.staticSettings.TitleId = Environment.GetEnvironmentVariable("PLAYFAB_TITLE_ID", EnvironmentVariableTarget.Process); //Create Step One Request var addTargetFriend = new PlayFab.ServerModels.AddFriendRequest { PlayFabId = senderID, FriendPlayFabId = targetID }; //Step One: Add Target As Friend To Sender var stepOne = await PlayFabServerAPI.AddFriendAsync(addTargetFriend); if(stepOne.Error != null) { return stepOne.Error; } //Create Step Two Request var setTargetTag = new PlayFab.ServerModels.SetFriendTagsRequest { PlayFabId = senderID, FriendPlayFabId = targetID, Tags = new List<string>() }; //Add Desired Tag For Request setTargetTag.Tags.Add("Pending"); //Step Two: Add Tag To Target var stepTwo = await PlayFabServerAPI.SetFriendTagsAsync(setTargetTag); if(stepTwo.Error != null) { return stepTwo.Error; } //Create Step Three Request var addSenderFriend = new PlayFab.ServerModels.AddFriendRequest { PlayFabId = targetID, FriendPlayFabId = senderID }; //Step Three: Add Sender As Friend To Target var stepThree = await PlayFabServerAPI.AddFriendAsync(addSenderFriend); if (stepThree.Error != null) { return stepThree.Error; } //Create Step Four Request var setSenderTag = new PlayFab.ServerModels.SetFriendTagsRequest { PlayFabId = targetID, FriendPlayFabId = senderID, Tags = new List<string>() }; //Add Desired Tag For Request setSenderTag.Tags.Add("Requested"); //Step Four: Add Tag To Sender var stepFour = await PlayFabServerAPI.SetFriendTagsAsync(setSenderTag); if (stepFour.Error != null) { return stepFour.Error; } //Return a message if the function has executed properly return new {message = $"Friend Request Pending For User: {targetID}"}; } } }