From e08dd78ccf05f9d5d768e5436fcfc5e8126356fe Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Fri, 4 Apr 2014 14:13:16 +0000 Subject: Steam: some improvements git-svn-id: http://svn.miranda-ng.org/main/trunk@8848 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Steam/src/steam_account.cpp | 114 +++++++++++++++++++++------------- 1 file changed, 71 insertions(+), 43 deletions(-) (limited to 'protocols/Steam/src/steam_account.cpp') diff --git a/protocols/Steam/src/steam_account.cpp b/protocols/Steam/src/steam_account.cpp index 8f9b932347..a08926cff3 100644 --- a/protocols/Steam/src/steam_account.cpp +++ b/protocols/Steam/src/steam_account.cpp @@ -1,51 +1,64 @@ #include "common.h" -void CSteamProto::LogInThread(void* param) +bool CSteamProto::IsOnline() { - CMStringA token(getStringA("TokenSecret")); - if (token.IsEmpty()) - { - ptrW username(getWStringA("Username")); - ptrA password(getStringA("Password")); + return m_iStatus > ID_STATUS_OFFLINE; +} - SteamWebApi::AuthorizationApi::Authorization authResult; - SteamWebApi::AuthorizationApi::Authorize(m_hNetlibUser, username, password, &authResult); - - if (authResult.IsEmailAuthNeeded()/* || authResult.captcha_needed*/) +void CSteamProto::Authorize(SteamWebApi::AuthorizationApi::AuthResult *authResult) +{ + ptrW username(getWStringA("Username")); + ptrA password(getStringA("Password")); + + // try to authorize + SteamWebApi::AuthorizationApi::Authorize(m_hNetlibUser, username, password, authResult); + if (authResult->IsEmailAuthNeeded() || authResult->IsCaptchaNeeded()) + { + do { - do + if (authResult->IsEmailAuthNeeded()) { - if (authResult.IsEmailAuthNeeded()) - { - GuardParam guard; + GuardParam guard; - //lstrcpy(guard.emailDomain, authResult.emaildomain); + lstrcpyA(guard.domain, authResult->GetEmailDomain()); - if (DialogBoxParam( - g_hInstance, - MAKEINTRESOURCE(IDD_GUARD), - NULL, - CSteamProto::GuardProc, - (LPARAM)&guard) != 1) - break; + if (DialogBoxParam( + g_hInstance, + MAKEINTRESOURCE(IDD_GUARD), + NULL, + CSteamProto::GuardProc, + (LPARAM)&guard) != 1) + break; - authResult.SetAuthCode(guard.code); - } - - //if (result->captcha_needed) - // ;// proto->fail - - SteamWebApi::AuthorizationApi::Authorize(m_hNetlibUser, username, password, &authResult); + authResult->SetAuthCode(guard.code); + } + + if (authResult->IsCaptchaNeeded()) + { + // todo: show captcha dialog + } - } while (authResult.IsEmailAuthNeeded()/* || auth->captcha_needed*/); - } + // try to authorize with emailauthcode or captcha taxt + SteamWebApi::AuthorizationApi::Authorize(m_hNetlibUser, username, password, authResult); + } while (authResult->IsEmailAuthNeeded() || authResult->IsCaptchaNeeded()); + } +} +void CSteamProto::LogInThread(void* param) +{ + CMStringA token(getStringA("TokenSecret")); + if (token.IsEmpty()/* && !this->IsOnline()*/) + { + SteamWebApi::AuthorizationApi::AuthResult authResult; + Authorize(&authResult); + // if some error if (!authResult.IsSuccess()) { + // todo: dosplay error message from authResult.GetMessage() + //ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_BADUSERID); m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, ID_STATUS_OFFLINE); return; - ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_BADUSERID); } token = authResult.GetToken(); @@ -53,30 +66,35 @@ void CSteamProto::LogInThread(void* param) setString("SteamID", authResult.GetSteamid()); } - SteamWebApi::LogInApi::LogIn login; - SteamWebApi::LogInApi::LogOn(m_hNetlibUser, token, &login); - - if (!login.IsSuccess()) + SteamWebApi::LoginApi::LoginResult loginResult; + SteamWebApi::LoginApi::Logon(m_hNetlibUser, token, &loginResult); + // if some error + if (!loginResult.IsSuccess()) { + // set status to offline m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, ID_STATUS_OFFLINE); return; } + else + { + setString("SessionID", loginResult.GetSessionId()); + setDword("MessageID", loginResult.GetMessageId()); + // set selected status + m_iStatus = m_iDesiredStatus; + ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iDesiredStatus); + } - setString("SessionID", login.GetSessionId()); - setDword("MessageID", login.GetMessageId()); - - m_iStatus = m_iDesiredStatus; - ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iDesiredStatus); - + // start pooling thread if (m_hPollingThread == NULL && !m_bTerminated) { m_bTerminated = false; m_hPollingThread = ForkThreadEx(&CSteamProto::PollingThread, NULL, NULL); } + // get contact list SteamWebApi::FriendListApi::FriendList friendList; - SteamWebApi::FriendListApi::Load(m_hNetlibUser, token, login.GetSteamId(), &friendList); + SteamWebApi::FriendListApi::Load(m_hNetlibUser, token, loginResult.GetSteamId(), &friendList); if (friendList.IsSuccess()) { @@ -91,4 +109,14 @@ void CSteamProto::LogInThread(void* param) } } } +} + +void CSteamProto::LogOutThread(void*) +{ + ptrA token(getStringA("TokenSecret")); + ptrA sessionId(getStringA("SessionID")); + + SteamWebApi::LoginApi::Logoff(m_hNetlibUser, token, sessionId); + + delSetting("SessionID"); } \ No newline at end of file -- cgit v1.2.3