Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Steamworks.h"
- #include <iostream>
- #include <iomanip>
- void ShowError( TSteamError *err )
- {
- if ( !IS_STEAM_ERROR( (*err) ) )
- return;
- printf("Error: %s\n", err->szDesc);
- getchar();
- exit( 0 );
- }
- int main()
- {
- void* steam_library = dlopen("libsteam.so", RTLD_LAZY);
- FactoryFn fn = (FactoryFn)dlsym(steam_library, "_f");
- dlclose(steam_library);
- ISteam006 *steam = (ISteam006*)fn( "Steam006" );
- if ( !steam )
- {
- printf("Unable to get ISteam006.\n");
- return 0;
- }
- TSteamError error;
- // Either of these work, the difference and params for Ex are unknown.
- //if ( !steam->StartEngine( &error ) )
- // ShowError( &error );
- if ( !steam->StartEngineEx( &error, false, false ) )
- ShowError( &error );
- if ( !steam->Startup( STEAM_USING_ALL, &error ) )
- ShowError( &error );
- const char *userName = "limetech";
- const char *passWord = "hurrdurrderp";
- SteamCallHandle_t handle = steam->Login( userName, passWord, 1, &error );
- if ( handle == STEAM_INVALID_CALL_HANDLE )
- ShowError( &error );
- if ( !steam->BlockingCall( handle, 100, &error ) )
- ShowError( &error );
- char szUser[ 255 ];
- uint32 userChars;
- TSteamGlobalUserID globalId;
- if ( !steam->GetUser( szUser, sizeof( szUser ), &userChars, &globalId, &error ) )
- ShowError( &error );
- char szEmailAddress[ 255 ];
- uint32 emailChars;
- if ( !steam->GetCurrentEmailAddress( szEmailAddress, sizeof( szEmailAddress ), &emailChars, &error ) )
- ShowError( &error );
- szUser[userChars]='\0';
- printf("User: %s\n", szUser);
- szEmailAddress[emailChars]='\0';
- printf("Email address: %s\n", szEmailAddress);
- printf("Steam2 - Logged on!\n");
- void* steamclient_library = dlopen("steamclient.so", RTLD_LAZY);
- CreateInterfaceFn factory = (CreateInterfaceFn)dlsym(steamclient_library, "CreateInterface");
- dlclose(steamclient_library);
- if ( !factory )
- {
- std::cout << "Unable to load steamclient factory." << std::endl;
- return 0;
- }
- ISteamClient009 *steamClient = (ISteamClient009 *)factory( STEAMCLIENT_INTERFACE_VERSION_009, NULL );
- IClientEngine *clientEngine = (IClientEngine *)factory( CLIENTENGINE_INTERFACE_VERSION, NULL );
- HSteamPipe hPipe;
- HSteamUser hUser = clientEngine->CreateGlobalUser( &hPipe );
- if ( !hUser || !hPipe )
- {
- std::cout << "Unable to connect to global user." << std::endl;
- return 0;
- }
- IClientUser *clientUser = (IClientUser *)clientEngine->GetIClientUser( hUser, hPipe, CLIENTUSER_INTERFACE_VERSION );
- IClientFriends *clientFriends = (IClientFriends *)clientEngine->GetIClientFriends( hUser, hPipe, CLIENTFRIENDS_INTERFACE_VERSION );
- ISteam2Bridge002 *steam2Bridge = (ISteam2Bridge002 *)steamClient->GetISteamGenericInterface( hUser, hPipe, STEAM2BRIDGE_INTERFACE_VERSION_002 );
- CSteamID steamId;
- steamId.SetFromSteam2( &globalId, steam2Bridge->GetConnectedUniverse() );
- clientUser->SetEmail( szEmailAddress );
- clientUser->SetLoginInformation( userName, passWord, false );
- // This starts the thread causeing the crash.
- clientUser->LogOn( steamId );
- ELogonState state = clientUser->GetLogonState();
- while ( state == k_ELogonStateLoggingOn )
- {
- state = clientUser->GetLogonState();
- }
- CallbackMsg_t callBack;
- while ( true )
- {
- if ( Steam_BGetCallback( hPipe, &callBack ) )
- {
- switch (callBack.m_iCallback)
- {
- case SteamServersConnected_t::k_iCallback:
- {
- printf("Steam3 - Logged on!\n");
- clientUser->SetComputerInUse();
- clientUser->SetSelfAsPrimaryChatDestination();
- clientFriends->SetPersonaState( k_EPersonaStateOnline );
- break;
- }
- }
- Steam_FreeLastCallback( hPipe );
- }
- sleep(10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement