YoYoGames / GMEXT-Steamworks

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

steam_user_get_auth_session_ticket UTF 8 HEX Fix #14

Closed CelaldoganGunes closed 1 year ago

CelaldoganGunes commented 1 year ago

Hello, As it is written in Steam API Docs, to be able to use the ticket that is received fromISteamUser::GetAuthSessionTicket, we need to convert it to a hex encoded UTF-8 string. image

Current version of the extension gives us a buffer but it is not in the required format. I edited the extension again and it gives us the ticket in the right format. And we can send this ticket directly to the Steam without editing it in GameMaker. I don't know how to send you my code, so I am creating this issue. I am not good at C++, because of that you may need to optimize some areas. I am waiting for you to add this to the extension, then I will test it in my macbook. (I developed this in my Windows computer and I don't know how to build dylib files.)

` HAuthTicket authTicket; YYEXPORT void steam_user_get_auth_session_ticket(RValue& Result, CInstance selfinst, CInstance otherinst, int argc, RValue arg)//(char data, double size) { static const uint32 MAX_TICKET_SIZE{ 1024 }; uint32 ticketSize{ 0 }; uint8 ticket[MAX_TICKET_SIZE];

authTicket = SteamUser()->GetAuthSessionTicket(ticket, MAX_TICKET_SIZE, &ticketSize);

//for (int i = 0; i < 100; i++)
//    DebugConsoleOutput("%i \n", ticket[i]);

Result.kind = VALUE_REAL;
if (authTicket == k_HAuthTicketInvalid)
{
    DebugConsoleOutput("Auth session ticket is invalid.\n");

    Result.val = -4;//noone
}
else
{
    DebugConsoleOutput("Auth session ticket is SUCCESS.\n");

    // My Code Starts Here

    int i;
    string hexTicket = "";
    char const hex_chars[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
    for (i = 0; i < ticketSize; i++) {

        char const byte = ticket[i];

        hexTicket += hex_chars[(byte & 0xF0) >> 4];
        hexTicket += hex_chars[(byte & 0x0F) >> 0];

    }

    //This writes the string value we need. I copied it from console and tested it and it works.
    const char* mainTicket = hexTicket.c_str();
    DebugConsoleOutput(mainTicket);
    DebugConsoleOutput("\n");

    int bufferID = CreateBuffer(hexTicket.size(), eBuffer_Format_Fixed, 1);
    BufferWriteContent(bufferID, 0, mainTicket, hexTicket.size());

    /*
        My Code Ends Here

        I am not good at c++ but this code works.
    */

    //Official Code of the extension
    //int bufferID = CreateBuffer(ticketSize, eBuffer_Format_Fixed, 1);
    //BufferWriteContent(bufferID, 0, ticket, ticketSize);

    Result.val = bufferID;
}

}`

GameMaker Code: var _buf = steam_user_get_auth_session_ticket(); AuthSessionTicket = buffer_read(_buf,buffer_string)

DiasFranciscoA commented 1 year ago

Thank you for the suggestion, but we won't be making this change to the code base. Leaving the AuthSessionTicket in it's original form allows for working with it in a more flexible way.

From what the image describes, the hex encoded UTF-8 string of the ticket should be sent as an HTTPS from your secure server so this has nothing to do with steamworks extension itself you can still follow the workflow:

  1. request this ticket using the GetAuthSessionTicket this will then return your a buffer with the data
  2. extract as a base64 string for example to keep it encoded
  3. send it over to your secure server
  4. create the HTTPS request after converting the base64 string to the required format (hex encoded UTF-8 string). ...