question

Justin Enayat avatar image
Justin Enayat asked

Converting playfab login system to linked steam system?

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.

apisPlayer DataAccount ManagementLeaderboards and Statistics
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Justin Enayat avatar image Justin Enayat commented ·

Oh and I must add I have thoroughly searched the internet about this, the documentation(s) did not solve this problem for me. Again I'm new and did not know what to do with the information given in the Playfab/Steam documentation.

0 Likes 0 ·

1 Answer

·
Justin Enayat avatar image
Justin Enayat answered

I figured it out. This is the working login code:

    void Login()
    {
        if (SteamManager.Initialized)
        {
            var request = new LoginWithSteamRequest
            {
                CreateAccount = true,
                InfoRequestParameters = new GetPlayerCombinedInfoRequestParams
                {
                    GetPlayerProfile = true,
                    GetUserAccountInfo = true
                },
                SteamTicket = GetSteamAuthTicket(),
            }; 
            PlayFabClientAPI.LoginWithSteam(request, OnSuccess, OnError);
        }
    }
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

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.