YoYoGames / GMEXT-Steamworks

Repository for GameMaker's Steamworks Extension
Other
65 stars 12 forks source link

[WIKI] Add info on how to convert Steam Auth Ticket for Web Api to hex string #104

Closed KhanDevelopsGames closed 1 day ago

KhanDevelopsGames commented 3 days ago

The wiki for steam_user_get_auth_ticket_for_web_api lacks important info on how to convert the received byte array to a hex string. I was able to do it myself after a few hours, but adding the information to the wiki directly will save the time of a lot of devs.

Here is the code i have used, should it be of any help:

Convert Functions:

function steam_auth_bufferToHex(_buffer)
{
    if(!buffer_exists(_buffer))
    {
        return "BUFFER NOT AVAILABLE";  
    }

    var _hexString = "";
    var _byte = 0;
    var _bufferSize = buffer_get_size(_buffer)
    buffer_seek(_buffer, buffer_seek_start,0);  
    for(var _i = 0; _i<_bufferSize;_i++)
    {           
        _byte = buffer_read(_buffer, buffer_u8);
        _hexString += byte_to_hex(_byte);           
    }       
    return _hexString;
}

function byte_to_hex(_byte)
{
    var _initialValue = string(ptr(_byte));
    if(_initialValue = "null")
    {
        return "00";    
    }   
    return string_delete(_initialValue,1,string_length(_initialValue)-2)
}

Aync - Steam Event:

//handle Steam auth
var _event = async_load[?"event_type"];
if(_event = "ticket_for_web_api_response")
{
    var _success = async_load[?"success"];  
    if(_success)
    {
        var _receivedTicketBuffer = async_load[?"auth_ticket_buffer"];      
        var _hexString = steam_auth_bufferToHex(_receivedTicketBuffer);     
        scr_server_account_loginWithSteam(_hexString); //Send HTTP request with your hex converted Auth Ticket to your Server   
    }
    else
    {
        steam_user_cancel_auth_ticket(user_receiveSteamWepApiTicket); //Cancel the auth ticket if something goes wrong.
    }
}
DiasFranciscoA commented 1 day ago

This as been added to both the WIKI and offline docs (available on next relase of steamwork)