Initially, I set my game up to create and reference player profiles via the unique device identifier:
void Login() { var request = new LoginWithCustomIDRequest { CustomId = SystemInfo.deviceUniqueIdentifier, CreateAccount = true, InfoRequestParameters = new GetPlayerCombinedInfoRequestParams { GetPlayerProfile = true } }; PlayFabClientAPI.LoginWithCustomID(request, OnSuccess, OnError); }
Using this, it all works. But I recently realized the downsides of having it only log in and identify players depending on what device they are using. I'm trying now to have it log the player in via Steam, but I'm having some trouble.
public string GetSteamAuthTicket() { byte[] ticketBlob = new byte[1024]; uint ticketSize; HAuthTicket hTicket = SteamUser.GetAuthSessionTicket(ticketBlob, ticketBlob.Length, out ticketSize); Array.Resize(ref ticketBlob, (int)ticketSize); StringBuilder sb = new StringBuilder(); foreach (byte b in ticketBlob) { sb.AppendFormat("{0:x2}", b); } return sb.ToString(); } void Login() { if (SteamManager.Initialized) { PlayFabClientAPI.LoginWithSteam(new LoginWithSteamRequest { CreateAccount = true, SteamTicket = GetSteamAuthTicket() }, OnSuccess, OnError); } }
When using this instead of the first code for logging in, it creates the player in Playfab, however, it does not update the display name, nor does it work with my existing code. This is what I use to send leaderboard data:
if (levelName == "TestLevel") { PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest() { FunctionName = "SendTimeTestLevel", FunctionParameter = new { timeSend = time }, GeneratePlayStreamEvent = false, }, OnCloudUpdateStats, OnErrorShared); }
Cloud script it calls:
handlers.SendTimeTestLevel = function (args, context) { var request = { PlayFabId: currentPlayerId, Statistics: [{ StatisticName: "TestLevel", Value: args.timeSend }] }; var playerStatResult = server.UpdatePlayerStatistics(request); return{messageValue: "Updated stats for TestLevel"} };
I have set up all the Steam stuff in the store, such as App ID's, API keys, etc. However, I am pretty new to coding, I'd really appreciate input on how to make it so that the game will log people in and get their player data based on the Steam account they are logged into instead of what device they are using.