Skip to content

Instantly share code, notes, and snippets.

@Turupawn
Last active January 16, 2018 01:32
Show Gist options
  • Save Turupawn/fc8c7d63c75464bb517d844e41147d40 to your computer and use it in GitHub Desktop.
Save Turupawn/fc8c7d63c75464bb517d844e41147d40 to your computer and use it in GitHub Desktop.
Steamowrks Browse Example
#include <iostream>
#include "steam_api.h"
class CGameManager
{
public:
void CreateQueryUserUGCRequest();
bool finished = false;
AppId_t nCreatorAppID = (AppId_t)517510;
AppId_t nConsumerAppID = (AppId_t)517510;
uint32 unPage = (uint32)1;
private:
void onUGCQueryCompleted(SteamUGCQueryCompleted_t *pCallback, bool bIOFailure);
CCallResult<CGameManager, SteamUGCQueryCompleted_t> m_SteamUGCQueryCompletedCallResult;
};
//We fire the request by linking a query handle with a CGameManager function member callback
//In order to do so, we create a query by providing the sort, filters and page parameters
void CGameManager::CreateQueryUserUGCRequest()
{
std::cout << "Getting items..." << std::endl;
AccountID_t unAccountID = SteamUser()->GetSteamID().GetAccountID();
UGCQueryHandle_t handle = SteamUGC()->CreateQueryUserUGCRequest(unAccountID, k_EUserUGCList_Subscribed, k_EUGCMatchingUGCType_Items, k_EUserUGCListSortOrder_SubscriptionDateDesc, nCreatorAppID, nConsumerAppID, unPage );
SteamAPICall_t hSteamAPICall = SteamUGC()->SendQueryUGCRequest( handle );
m_SteamUGCQueryCompletedCallResult.Set(hSteamAPICall, this,&CGameManager::onUGCQueryCompleted);
}
//Once the callback is triggered, we can go through the data using the GetQueryUGCResult function
void CGameManager::onUGCQueryCompleted(SteamUGCQueryCompleted_t *pCallback, bool bIOFailure)
{
if(pCallback->m_eResult == k_EResultOK && bIOFailure)
{
std::cout<<"error: "<<pCallback->m_eResult<<std::endl;
return;
}
std::cout << "Listing items" << std::endl;
std::cout << "=============" << std::endl;
SteamUGCDetails_t pDetails;
for(int i=0; i<(int)pCallback->m_unNumResultsReturned;i++)
{
SteamUGC()->GetQueryUGCResult( pCallback->m_handle, i, &pDetails );
std::cout << "Id: \t" << pDetails.m_nPublishedFileId << std::endl;
std::cout << "Title:\t" << pDetails.m_rgchTitle << std::endl;
}
finished = true;
std::cout<<std::endl;
std::cout<<"Num results returned: "<<pCallback->m_unNumResultsReturned<<std::endl;
std::cout<<"Total matching results: "<<pCallback->m_unTotalMatchingResults<<std::endl;
std::cout<<"Is data cached: "<<pCallback->m_bCachedData<<std::endl;
}
int main()
{
if(SteamAPI_Init())
{
CGameManager gameManager;
gameManager.CreateQueryUserUGCRequest();
while(!gameManager.finished)
{
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