⬆️ ⬇️

We work with SteamWorks. Part 2

Today we will work with the interfaces Apps, Utils, as well as get acquainted with how to implement callbacks in our application. I recommend to get acquainted with the first part , before proceeding to the second.





To activate debug mode in steam, you need to add launch parameters:



-dev -console 


To display debug information from our application, go to the console that appears and write:

')

 log_ipc verbose <  .exe> 


We include the header file #include <windows.h> to use the necessary functions.

Using our test application from the first part, we will add the connection of the required interfaces.



 auto *Utils = (ISteamUtils001 *)Client->GetISteamUtils(pipe,STEAMUTILS_INTERFACE_VERSION_001); auto *Apps = (ISteamApps004 *)Client->GetISteamApps(user,pipe,STEAMAPPS_INTERFACE_VERSION_004); 


Let's try to get the time to buy the game on my steam account with the given ID, let's declare AppId_t,

which is of type uint32, we put in it the value 500 (Left 4 Dead).



 AppId_t l4d(500); 


We get the time of purchase and server time in unix timestamp format.



 int PurchaseTime = Apps->GetEarliestPurchaseUnixTime(l4d); int time = Utils->GetServerRealTime(); 


We convert unix timestamp into a convenient view for a person.



 time_t rawtime = time; time_t Ptime = PurchaseTime; struct tm timeinfo; char timebuf[32]; localtime_s( &timeinfo,&rawtime ); asctime_s (timebuf,32,&timeinfo); printf( "%s \n", timebuf ); localtime_s( &timeinfo,&Ptime); asctime_s (timebuf,32,&timeinfo); printf( "%s \n", timebuf); 


At the output I get 1 - the real time of the server, 2 - the time when I purchased the game.



 Sat Nov 10 09:51:15 2012 Sat Nov 22 17:03:45 2008 




Now let's try to get a list of friends and a unique (not changing link) to their profile.



 CSteamID curID; int friendcount = Friends->GetFriendCount(); for(int i = 0; i < friendcount; i++) { curID = Friends13->GetFriendByIndex(i, k_EFriendFlagAll); printf("%s - %llu\n", Friends->GetFriendPersonaName(curID), curID.ConvertToUint64()); } system("pause"); 


We get this conclusion:



 :REC: FabZen - 765611979787897xx DrLuke - 765611979853980xx [EM] Cooler_sk - 765611979862334xx Maryus - 765611979878419xx vorram - 765611979915317xx 0nb0ard - 765611979922297xx .......... 


I closed the last two digits with the <x> symbol, now this id can be substituted into steamcommunity.com/profiles/[id]



Let's get started with callbacks, all callbacks are listed in the FriendsCommon.h file in the OpenSteamWorks folder.



Until we press the Escape key, we get callback, compare it with the FriendChatMsg_t structure, if the condition is correct, allocate memory for the message line, receive the message, if the message type is normal or written through / me - compare the received string with “hello”, if identical - send greeting, clear the last callback and exit the program.



 CallbackMsg_t callBack; while (!GetAsyncKeyState(VK_ESCAPE)) { Sleep(1); if ( Steam_BGetCallback( pipe, &callBack ) ) { if(callBack.m_iCallback == FriendChatMsg_t::k_iCallback) { FriendChatMsg_t *pFriendMessageInfo = (FriendChatMsg_t *)callBack.m_pubParam; EChatEntryType eMsgType; char szData[k_cchFriendChatMsgMax]; memset(szData, 0, k_cchFriendChatMsgMax); Friends->GetChatMessage(pFriendMessageInfo>m_ulSenderID,pFriendMessageInfo>m_iChatID, szData,sizeof(szData),&eMsgType); if (eMsgType == k_EChatEntryTypeChatMsg || k_EChatEntryTypeEmote) { if (strcmp(szData, "hello") == 0 && (pFriendMessageInfo->m_ulSenderID != User->GetSteamID())){ Friends->SendMsgToFriend(pFriendMessageInfo->m_ulFriendID,k_EChatEntryTypeChatMsg,"hello my friend",22); Steam_FreeLastCallback(pipe); ExitProcess(0); } } } Steam_FreeLastCallback(pipe); } } 




An example callback to Trade Response (exchange request).



 if (callbackMsg.m_iCallback == TradeInviteReceived_t::k_iCallback) { TradeInviteReceived_t* pTradeInviteReceived = (TradeInviteReceived_t*) callbackMsg.m_pubParam; printf("Trade from %s, ID %u\n", pTradeInviteReceived->m_steamIDPartner.SteamRender(), pTradeInviteReceived->m_unTradeRequestID); //    Trade . } 




The next article will show you how to work with user achievements (ISteamUserStats) and the interface (ISteamScreenshots).

Source: https://habr.com/ru/post/158119/



All Articles