Skip to content

Instantly share code, notes, and snippets.

@Turupawn
Created November 8, 2018 23:02
Show Gist options
  • Save Turupawn/6e0f1ed22b31fd7b7ab12c0d4107f8c1 to your computer and use it in GitHub Desktop.
Save Turupawn/6e0f1ed22b31fd7b7ab12c0d4107f8c1 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
#include "steam/steam_api.h"
#include "steam/steamencryptedappticket.h"
#include "base64.h"
bool finish = false;
class CGameManager
{
public:
void RequestEncryptedAppTicket();
private:
void OnGetEncryptedAppTicket(EncryptedAppTicketResponse_t *pCallback, bool bIOFailure);
CCallResult<CGameManager, EncryptedAppTicketResponse_t> m_EncryptedAppTicketResponseCallResult;
};
void CGameManager::RequestEncryptedAppTicket()
{
std::cout<<"Requesting encrypted app ticket"<<std::endl;
SteamAPICall_t hSteamAPICall = SteamUser()->RequestEncryptedAppTicket(NULL, 0);
m_EncryptedAppTicketResponseCallResult.Set(hSteamAPICall, this, &CGameManager::OnGetEncryptedAppTicket);
}
void CGameManager::OnGetEncryptedAppTicket(EncryptedAppTicketResponse_t *pCallback, bool bIOFailure)
{
if (bIOFailure)
{
std::cout<<"There has been an IO Failure when requesting the Encrypted App Ticket."<<std::endl;
return;
}
switch (pCallback->m_eResult)
{
case k_EResultOK:
{
std::cout<<"Encrypted ticket retreived correctly from steam."<<std::endl;
uint8 rgubTicket[1024];
uint32 cubTicket;
if (SteamUser()->GetEncryptedAppTicket(rgubTicket, sizeof(rgubTicket), &cubTicket))
{
std::cout<<"Encoding ticket on base64"<<std::endl;
std::string encoded = base64_encode((unsigned char const *)rgubTicket, (unsigned int)cubTicket);
std::cout << "Ticket encoded: " << encoded << std::endl;
}
else
std::cout<<"GetEncryptedAppTicket failed."<<std::endl;
}
break;
case k_EResultNoConnection:
std::cout<<"Calling RequestEncryptedAppTicket while not connected to steam results in this error."<<std::endl;
break;
case k_EResultDuplicateRequest:
std::cout<<"Calling RequestEncryptedAppTicket while there is already a pending request results in this error."<<std::endl;
break;
case k_EResultLimitExceeded:
std::cout<<"Calling RequestEncryptedAppTicket more than once per minute returns this error."<<std::endl;
break;
}
finish = true;
}
int main()
{
SteamAPI_Init();
CGameManager game_manager;
game_manager.RequestEncryptedAppTicket();
while (!finish)
{
SteamAPI_RunCallbacks();
}
std::cout<<"Process finished"<<std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment