Created
September 1, 2015 08:52
-
-
Save raincode00/0e0a0e1870e71005ee24 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _CRT_SECURE_NO_WARNINGS | |
#include <Windows.h> | |
#include "steam/steam_api.h" | |
#include <string> | |
#include <iostream> | |
#include <iomanip> | |
#include <sstream> | |
static char authTicketCallbackCalled = false; | |
static char authTicketCallbackError = false; | |
// a class that does nothing other than register itself as a Steam | |
// callback listener when it is constructed | |
class AuthTicketListener { | |
public: | |
AuthTicketListener() | |
// initializing this member object is what actually | |
// registers our callback | |
: mAuthSessionTicketResponse( | |
this, | |
&AuthTicketListener::OnAuthSessionTicketResponse) { | |
} | |
// callback when our AuthSessionTicket is ready | |
// this macro declares our callback function for us AND | |
// defines our member object | |
STEAM_CALLBACK( | |
// class that the callback function is in | |
AuthTicketListener, | |
// name of callback function | |
OnAuthSessionTicketResponse, | |
// type of callback | |
GetAuthSessionTicketResponse_t, | |
// name of the member object | |
mAuthSessionTicketResponse); | |
}; | |
void AuthTicketListener::OnAuthSessionTicketResponse( | |
GetAuthSessionTicketResponse_t *inCallback) { | |
std::cout << "OnAuthSessionTicketResponse" << std::endl; | |
authTicketCallbackCalled = true; | |
if (inCallback->m_eResult != k_EResultOK) { | |
authTicketCallbackError = true; | |
} | |
} | |
int main() { | |
if (!SteamAPI_Init()) { | |
MessageBoxA(NULL, "steam init failed.", "error", 0); | |
exit(1); | |
} | |
unsigned char buf[4096]; | |
unsigned int buf_size; | |
AuthTicketListener *listener = new AuthTicketListener(); | |
auto ticket = SteamUser()->GetAuthSessionTicket(buf, 4096, &buf_size); | |
std::ostringstream hex_ticket; | |
while (!authTicketCallbackCalled) { | |
Sleep(100); | |
SteamAPI_RunCallbacks(); | |
} | |
for (unsigned int i = 0; i < buf_size; i++) { | |
hex_ticket << std::setfill('0') << std::setw(2) << std::uppercase << std::hex << int(buf[i]); | |
} | |
std::cout << "ticket: " << hex_ticket.str() << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment