summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-05-27 22:08:58 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-05-27 22:08:58 +0000
commita2cbb34b00f6de9d7f5d49fad02dc6f94ccf81db (patch)
treee8e41d62fff06e8bdfd535404a5ec7957d3ae5f6
parentd2a5706a5c4ed7620030377ffe32f093b14d3177 (diff)
Steam: reworked login
git-svn-id: http://svn.miranda-ng.org/main/trunk@13865 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--protocols/Steam/src/api/authorization.h54
-rw-r--r--protocols/Steam/src/api/rsa_key.h11
-rw-r--r--protocols/Steam/src/steam_account.cpp265
-rw-r--r--protocols/Steam/src/steam_dialogs.cpp2
-rw-r--r--protocols/Steam/src/steam_dialogs.h2
-rw-r--r--protocols/Steam/src/steam_login.cpp300
-rw-r--r--protocols/Steam/src/steam_proto.cpp2
-rw-r--r--protocols/Steam/src/steam_proto.h6
-rw-r--r--protocols/Steam/src/steam_utils.cpp12
-rw-r--r--protocols/Steam/src/version.h4
10 files changed, 335 insertions, 323 deletions
diff --git a/protocols/Steam/src/api/authorization.h b/protocols/Steam/src/api/authorization.h
index e7b2ee8c39..d3ebc8246c 100644
--- a/protocols/Steam/src/api/authorization.h
+++ b/protocols/Steam/src/api/authorization.h
@@ -4,55 +4,27 @@
class AuthorizationRequest : public HttpRequest
{
public:
- AuthorizationRequest(const char *username, const char *password, const char *timestamp) :
- HttpRequest(REQUEST_POST, STEAM_WEB_URL "/mobilelogin/dologin")
+ AuthorizationRequest(const char *username, const char *password, const char *timestamp, const char *twofactorcode, const char *guardCode, const char *guardId = "", const char *captchaId = "-1", const char *captchaText = "") :
+ HttpRequest(REQUEST_POST, STEAM_WEB_URL "/mobilelogin/dologin/")
{
flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP;
- char data[1024];
- mir_snprintf(data, SIZEOF(data),
- "username=%s&password=%s&oauth_client_id=3638BFB1&oauth_scope=read_profile write_profile read_client write_client&captchagid=-1&rsatimestamp=%s",
- ptrA(mir_urlEncode(username)),
- ptrA(mir_urlEncode(password)),
- timestamp);
+ AddHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
+ AddHeader("Referer", STEAM_WEB_URL "/mobilelogin/dologin?oauth_client_id=3638BFB1&oauth_scope=read_profile%20write_profile%20read_client%20write_client");
- SetData(data, strlen(data));
- AddHeader("Content-Type", "application/x-www-form-urlencoded");
- }
-
- AuthorizationRequest(const char *username, const char *password, const char *timestamp, const char *guardCode) :
- HttpRequest(REQUEST_POST, STEAM_WEB_URL "/mobilelogin/dologin")
- {
- flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP;
-
- char data[1024];
- mir_snprintf(data, SIZEOF(data),
- "username=%s&password=%s&emailauth=%s&loginfriendlyname=MirandaNG&oauth_client_id=3638BFB1&oauth_scope=read_profile write_profile read_client write_client&captchagid=-1&rsatimestamp=%s",
- ptrA(mir_urlEncode(username)),
+ CMStringA data(CMStringDataFormat::FORMAT,
+ "password=%s&username=%s&twofactorcode=%s&emailauth=%s&loginfriendlyname=%s&oauth_client_id=3638BFB1&captchagid=%s&captcha_text=%s&emailsteamid=%s&rsatimestamp=%s&rememberlogin=false&donotcache=%lld",
ptrA(mir_urlEncode(password)),
- guardCode,
- timestamp);
-
- SetData(data, strlen(data));
- AddHeader("Content-Type", "application/x-www-form-urlencoded");
- }
-
- AuthorizationRequest(const char *username, const char *password, const char *timestamp, const char *captchaId, const char *captchaText) :
- HttpRequest(REQUEST_POST, STEAM_WEB_URL "/mobilelogin/dologin")
- {
- flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP;
-
- char data[1024];
- mir_snprintf(data, SIZEOF(data),
- "username=%s&password=%s&emailauth=&captchagid=%s&captcha_text=%s&oauth_client_id=3638BFB1&oauth_scope=read_profile write_profile read_client write_client&rsatimestamp=%s",
ptrA(mir_urlEncode(username)),
- ptrA(mir_urlEncode(password)),
+ twofactorcode,
+ guardCode,
+ "Miranda%20NG",
captchaId,
ptrA(mir_urlEncode(captchaText)),
- timestamp);
-
- SetData(data, strlen(data));
- AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ guardId,
+ timestamp,
+ time(NULL));
+ SetData(data.GetBuffer(), data.GetLength());
}
};
diff --git a/protocols/Steam/src/api/rsa_key.h b/protocols/Steam/src/api/rsa_key.h
index 6b938a48ef..1cf33d15ab 100644
--- a/protocols/Steam/src/api/rsa_key.h
+++ b/protocols/Steam/src/api/rsa_key.h
@@ -1,15 +1,18 @@
#ifndef _STEAM_REQUEST_RSA_KEY_H_
#define _STEAM_REQUEST_RSA_KEY_H_
-class RsaKeyRequest : public HttpRequest
+class GetRsaKeyRequest : public HttpRequest
{
public:
- RsaKeyRequest(const char *username) :
- HttpRequest(REQUEST_GET, STEAM_WEB_URL "/mobilelogin/getrsakey")
+ GetRsaKeyRequest(const char *username) :
+ HttpRequest(REQUEST_POST, STEAM_WEB_URL "/mobilelogin/getrsakey/")
{
flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP;
- AddParameter("username", (char*)username);
+ AddHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
+
+ CMStringA data(CMStringDataFormat::FORMAT, "username=%s&donotcache=%lld", ptrA(mir_urlEncode(username)), time(NULL));
+ SetData(data.GetBuffer(), data.GetLength());
}
};
diff --git a/protocols/Steam/src/steam_account.cpp b/protocols/Steam/src/steam_account.cpp
deleted file mode 100644
index bbf144fc61..0000000000
--- a/protocols/Steam/src/steam_account.cpp
+++ /dev/null
@@ -1,265 +0,0 @@
-#include "stdafx.h"
-
-bool CSteamProto::IsOnline()
-{
- return m_iStatus > ID_STATUS_OFFLINE && m_hPollingThread;
-}
-
-bool CSteamProto::IsMe(const char *steamId)
-{
- ptrA mySteamId(getStringA("SteamID"));
- if (!lstrcmpA(steamId, mySteamId))
- return true;
-
- return false;
-}
-
-void CSteamProto::OnGotRsaKey(const NETLIBHTTPREQUEST *response)
-{
- if (response == NULL)
- return;
-
- // load rsa key parts
- JSONROOT root(response->pData);
- if (!root)
- return;
-
- JSONNODE *node = json_get(root, "success");
- if (!json_as_bool(node)) {
- return;
- }
-
- node = json_get(root, "publickey_mod");
- ptrA modulus(mir_u2a(ptrT(json_as_string(node))));
-
- // exponent "010001" is used as constant in CSteamProto::RsaEncrypt
- /*node = json_get(root, "publickey_exp");
- ptrA exponent(mir_u2a(ptrT(json_as_string(node))));*/
-
- node = json_get(root, "timestamp");
- ptrA timestamp(mir_u2a(ptrT(json_as_string(node))));
- setString("Timestamp", timestamp);
-
- // encrcrypt password
- ptrA base64RsaEncryptedPassword;
- ptrA password(getStringA("Password"));
-
- DWORD error = 0;
- DWORD encryptedSize = 0;
- if ((error = RsaEncrypt(modulus, password, NULL, encryptedSize)) != 0)
- {
- debugLogA("CSteamProto::OnGotRsaKey: encryption error (%lu)", error);
- return;
- }
-
- BYTE *encryptedPassword = (BYTE*)mir_calloc(encryptedSize);
- if ((error = RsaEncrypt(modulus, password, encryptedPassword, encryptedSize)) != 0)
- {
- debugLogA("CSteamProto::OnGotRsaKey: encryption error (%lu)", error);
- return;
- }
-
- base64RsaEncryptedPassword = mir_base64_encode(encryptedPassword, encryptedSize);
- mir_free(encryptedPassword);
-
- setString("EncryptedPassword", base64RsaEncryptedPassword);
- setString("RsaTimestamp", timestamp);
-
- // run authorization request
- ptrA username(mir_utf8encodeW(getWStringA("Username")));
-
- PushRequest(
- new AuthorizationRequest(username, base64RsaEncryptedPassword, timestamp),
- &CSteamProto::OnAuthorization);
-}
-
-void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response)
-{
- if (response == NULL)
- {
- SetStatus(ID_STATUS_OFFLINE);
- return;
- }
-
- JSONROOT root(response->pData);
-
- JSONNODE *node = json_get(root, "success");
- if (json_as_bool(node) == 0)
- {
- node = json_get(root, "message");
- ptrT message(json_as_string(node));
-
- // Always show error notification
- ShowNotification(TranslateTS(message));
-
- if (!mir_tstrcmpi(message, _T("Incorrect login.")))
- {
- // We can't continue with incorrect login/password
- SetStatus(ID_STATUS_OFFLINE);
- return;
- }
-
- node = json_get(root, "emailauth_needed");
- if (json_as_bool(node) > 0)
- {
- node = json_get(root, "emailsteamid");
- ptrA guardId(mir_u2a(ptrT(json_as_string(node))));
-
- node = json_get(root, "emaildomain");
- ptrA emailDomain(mir_utf8encodeW(ptrT(json_as_string(node))));
-
- CSteamGuardDialog guardDialog(this, emailDomain);
- if (!guardDialog.DoModal())
- return;
-
- ptrA username(mir_utf8encodeW(getWStringA("Username")));
- ptrA password(getStringA("EncryptedPassword"));
- ptrA timestamp(getStringA("RsaTimestamp"));
-
- PushRequest(
- new AuthorizationRequest(username, password, timestamp, guardDialog.GetGuardCode()),
- &CSteamProto::OnAuthorization);
- return;
- }
-
- node = json_get(root, "captcha_needed");
- if (json_as_bool(node) > 0)
- {
- node = json_get(root, "captcha_gid");
- ptrA captchaId(mir_u2a(ptrT(json_as_string(node))));
-
- GetCaptchaRequest *request = new GetCaptchaRequest(captchaId);
- NETLIBHTTPREQUEST *response = request->Send(m_hNetlibUser);
- delete request;
-
- CSteamCaptchaDialog captchaDialog(this, (BYTE*)response->pData, response->dataLength);
- if (!captchaDialog.DoModal())
- {
- CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response);
- SetStatus(ID_STATUS_OFFLINE);
- return;
- }
-
- ptrA username(mir_utf8encodeW(getWStringA("Username")));
- ptrA password(getStringA("EncryptedPassword"));
- ptrA timestamp(getStringA("RsaTimestamp"));
-
- PushRequest(
- new AuthorizationRequest(username, password, timestamp, captchaId, captchaDialog.GetCaptchaText()),
- &CSteamProto::OnAuthorization);
- return;
- }
-
- delSetting("EncryptedPassword");
- delSetting("RsaTimestamp");
- SetStatus(ID_STATUS_OFFLINE);
- return;
- }
-
- delSetting("EncryptedPassword");
- delSetting("RsaTimestamp");
-
- node = json_get(root, "login_complete");
- if (!json_as_bool(node))
- {
- SetStatus(ID_STATUS_OFFLINE);
- return;
- }
-
- node = json_get(root, "oauth");
- JSONROOT nroot(_T2A(ptrT(json_as_string(node))));
-
- node = json_get(nroot, "steamid");
- ptrA steamId(mir_u2a(ptrT(json_as_string(node))));
- setString("SteamID", steamId);
-
- node = json_get(nroot, "oauth_token");
- ptrA token(mir_u2a(ptrT(json_as_string(node))));
- setString("TokenSecret", token);
-
- node = json_get(nroot, "webcookie");
- ptrA cookie(mir_u2a(ptrT(json_as_string(node))));
-
- delSetting("Timestamp");
- delSetting("EncryptedPassword");
-
- PushRequest(
- new GetSessionRequest(token, steamId, cookie),
- &CSteamProto::OnGotSession);
-
- PushRequest(
- new LogonRequest(token),
- &CSteamProto::OnLoggedOn);
-}
-
-void CSteamProto::OnGotSession(const NETLIBHTTPREQUEST *response)
-{
- if(response == NULL)
- return;
-
- for (int i = 0; i < response->headersCount; i++)
- {
- if (lstrcmpiA(response->headers[i].szName, "Set-Cookie"))
- continue;
-
- std::string cookies = response->headers[i].szValue;
- size_t start = cookies.find("sessionid=") + 10;
- size_t end = cookies.substr(start).find(';');
- std::string sessionId = cookies.substr(start, end - start + 10);
- setString("SessionID", sessionId.c_str());
- break;
- }
-}
-
-void CSteamProto::HandleTokenExpired()
-{
- // Notify error to user
- ShowNotification(_T("Steam"), TranslateT("Connection token expired. Please login again."));
-
- // Delete expired token
- delSetting("TokenSecret");
-
- // Set status to offline
- SetStatus(ID_STATUS_OFFLINE);
-}
-
-void CSteamProto::OnLoggedOn(const NETLIBHTTPREQUEST *response)
-{
- if (response == NULL)
- {
- // Probably timeout or no connection, we can do nothing here
- SetStatus(ID_STATUS_OFFLINE);
- return;
- }
-
- JSONROOT root(response->pData);
-
- JSONNODE *node = json_get(root, "error");
- ptrT error(json_as_string(node));
- if (mir_tstrcmpi(error, _T("OK")) || response->resultCode == HTTP_STATUS_UNAUTHORIZED)
- {
- // Probably expired TokenSecret
- HandleTokenExpired();
- return;
- }
-
- node = json_get(root, "umqid");
- setString("UMQID", ptrA(mir_u2a(ptrT(json_as_string(node)))));
-
- node = json_get(root, "message");
- setDword("MessageID", json_as_int(node));
-
- // load contact list
- ptrA token(getStringA("TokenSecret"));
- ptrA steamId(getStringA("SteamID"));
-
- PushRequest(
- new GetFriendListRequest(token, steamId),
- &CSteamProto::OnGotFriendList);
-
- // start polling thread
- m_hPollingThread = ForkThreadEx(&CSteamProto::PollingThread, 0, NULL);
-
- // go to online now
- ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus = m_iDesiredStatus);
-} \ No newline at end of file
diff --git a/protocols/Steam/src/steam_dialogs.cpp b/protocols/Steam/src/steam_dialogs.cpp
index 118583f218..a201a80a44 100644
--- a/protocols/Steam/src/steam_dialogs.cpp
+++ b/protocols/Steam/src/steam_dialogs.cpp
@@ -37,7 +37,7 @@ void CSteamPasswordEditor::OnClose()
/////////////////////////////////////////////////////////////////////////////////
-CSteamGuardDialog::CSteamGuardDialog(CSteamProto *proto, char *domain) :
+CSteamGuardDialog::CSteamGuardDialog(CSteamProto *proto, const char *domain) :
CSuper(proto, IDD_GUARD, false), m_ok(this, IDOK),
m_text(this, IDC_TEXT), m_link(this, IDC_GETDOMAIN, domain)
{
diff --git a/protocols/Steam/src/steam_dialogs.h b/protocols/Steam/src/steam_dialogs.h
index d98eac7222..233887d0fc 100644
--- a/protocols/Steam/src/steam_dialogs.h
+++ b/protocols/Steam/src/steam_dialogs.h
@@ -44,7 +44,7 @@ protected:
void OnClose();
public:
- CSteamGuardDialog(CSteamProto *proto, char *domain);
+ CSteamGuardDialog(CSteamProto *proto, const char *domain);
const char *GetGuardCode();
};
diff --git a/protocols/Steam/src/steam_login.cpp b/protocols/Steam/src/steam_login.cpp
new file mode 100644
index 0000000000..2002586053
--- /dev/null
+++ b/protocols/Steam/src/steam_login.cpp
@@ -0,0 +1,300 @@
+#include "stdafx.h"
+
+bool CSteamProto::IsOnline()
+{
+ return m_iStatus > ID_STATUS_OFFLINE && m_hPollingThread;
+}
+
+bool CSteamProto::IsMe(const char *steamId)
+{
+ ptrA mySteamId(getStringA("SteamID"));
+ if (!lstrcmpA(steamId, mySteamId))
+ return true;
+
+ return false;
+}
+
+void CSteamProto::OnGotRsaKey(const NETLIBHTTPREQUEST *response)
+{
+ if (response == NULL)
+ return;
+
+ // load rsa key parts
+ JSONNode root = JSONNode::parse(response->pData);
+ if (!root)
+ return;
+
+ if (!root["success"].as_bool())
+ return;
+
+ std::string modulus = root["publickey_mod"].as_string();
+ // exponent "010001" is used as constant in CSteamProto::RsaEncrypt
+ //std::string exponent = root["publickey_exp"].as_string();
+
+ std::string timestamp = root["timestamp"].as_string();
+
+ // encrcrypt password
+ ptrA base64RsaEncryptedPassword;
+ ptrA password(getStringA("Password"));
+
+ DWORD error = 0;
+ DWORD encryptedSize = 0;
+ if ((error = RsaEncrypt(modulus.c_str(), password, NULL, encryptedSize)) != 0)
+ {
+ debugLogA("CSteamProto::OnGotRsaKey: encryption error (%lu)", error);
+ return;
+ }
+
+ BYTE *encryptedPassword = (BYTE*)mir_calloc(encryptedSize);
+ if ((error = RsaEncrypt(modulus.c_str(), password, encryptedPassword, encryptedSize)) != 0)
+ {
+ debugLogA("CSteamProto::OnGotRsaKey: encryption error (%lu)", error);
+ return;
+ }
+
+ base64RsaEncryptedPassword = mir_base64_encode(encryptedPassword, encryptedSize);
+ mir_free(encryptedPassword);
+
+ // run authorization request
+ T2Utf username(getTStringA("Username"));
+
+ ptrA guardId(getStringA("GuardId"));
+ if (!guardId) guardId = mir_strdup("");
+ ptrA guardCode(getStringA("GuardCode"));
+ if (!guardCode) guardCode = mir_strdup("");
+
+ ptrA captchaId(getStringA("CaptchaId"));
+ if (!captchaId) captchaId = mir_strdup("-1");
+ ptrA captchaText(getStringA("CaptchaText"));
+ if (!captchaText) captchaText = mir_strdup("");
+
+ PushRequest(
+ new AuthorizationRequest(username, base64RsaEncryptedPassword, timestamp.c_str(), "", guardCode, guardId, captchaId, captchaText),
+ &CSteamProto::OnAuthorization);
+}
+
+void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response)
+{
+ if (response == NULL)
+ {
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+
+ JSONNode root = JSONNode::parse(response->pData);
+ if (!root)
+ {
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+
+ if (!root["success"].as_bool())
+ {
+ OnAuthorizationError(root);
+ return;
+ }
+
+ OnAuthorizationSuccess(root);
+}
+
+void CSteamProto::OnAuthorizationError(const JSONNode &node)
+{
+ std::string message = node["message"].as_string();
+ ptrT messageT(mir_utf8decodeT(message.c_str()));
+ if (!mir_tstrcmpi(messageT, _T("Incorrect login.")))
+ {
+ // We can't continue with incorrect login/password
+ delSetting("GuardId");
+ delSetting("GuardCode");
+ delSetting("CaptchaId");
+ delSetting("CaptchaText");
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+
+ T2Utf username(getTStringA("Username"));
+
+ if (node["requires_twofactor"].as_bool())
+ {
+ return;
+ }
+
+ if (node["emailauth_needed"].as_bool())
+ {
+ std::string guardId = node["emailsteamid"].as_string();
+ ptrA oldGuardId(getStringA("GuardId"));
+ if (mir_strcmp(guardId.c_str(), oldGuardId) == 0)
+ {
+ delSetting("GuardId");
+ delSetting("GuardCode");
+ PushRequest(
+ new GetRsaKeyRequest(username),
+ &CSteamProto::OnGotRsaKey);
+ return;
+ }
+
+ std::string domain = node["emaildomain"].as_string();
+
+ CSteamGuardDialog guardDialog(this, domain.c_str());
+ if (!guardDialog.DoModal())
+ {
+ delSetting("GuardId");
+ delSetting("GuardCode");
+ delSetting("CaptchaId");
+ delSetting("CaptchaText");
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+
+ setString("GuardId", guardId.c_str());
+ setString("GuardCode", guardDialog.GetGuardCode());
+
+ PushRequest(
+ new GetRsaKeyRequest(username),
+ &CSteamProto::OnGotRsaKey);
+ return;
+ }
+
+ if (node["captcha_needed"].as_bool())
+ {
+ std::string captchaId = node["captcha_gid"].as_string();
+
+ GetCaptchaRequest *request = new GetCaptchaRequest(captchaId.c_str());
+ NETLIBHTTPREQUEST *response = request->Send(m_hNetlibUser);
+ delete request;
+
+ CSteamCaptchaDialog captchaDialog(this, (BYTE*)response->pData, response->dataLength);
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response);
+ if (!captchaDialog.DoModal())
+ {
+ delSetting("CaptchaId");
+ delSetting("CaptchaText");
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+
+ setString("CaptchaId", captchaId.c_str());
+ setString("CaptchaText", captchaDialog.GetCaptchaText());
+
+ PushRequest(
+ new GetRsaKeyRequest(username),
+ &CSteamProto::OnGotRsaKey);
+ return;
+ }
+
+ delSetting("GuardId");
+ delSetting("GuardCode");
+ delSetting("CaptchaId");
+ delSetting("CaptchaText");
+ SetStatus(ID_STATUS_OFFLINE);
+}
+
+void CSteamProto::OnAuthorizationSuccess(const JSONNode &node)
+{
+ delSetting("GuardId");
+ delSetting("GuardCode");
+ delSetting("CaptchaId");
+ delSetting("CaptchaText");
+
+ if (!node["login_complete"].as_bool())
+ {
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+
+ std::string oauth = node["oauth"].as_string();
+ JSONNode root = JSONNode::parse(oauth.c_str());
+ if (!root)
+ {
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+
+ std::string steamId = root["steamid"].as_string();
+ setString("SteamID", steamId.c_str());
+
+ std::string token = root["oauth_token"].as_string();
+ setString("TokenSecret", token.c_str());
+
+ std::string cookie = root["webcookie"].as_string();
+
+ PushRequest(
+ new GetSessionRequest(token.c_str(), steamId.c_str(), cookie.c_str()),
+ &CSteamProto::OnGotSession);
+
+ PushRequest(
+ new LogonRequest(token.c_str()),
+ &CSteamProto::OnLoggedOn);
+}
+
+void CSteamProto::OnGotSession(const NETLIBHTTPREQUEST *response)
+{
+ if(response == NULL)
+ return;
+
+ for (int i = 0; i < response->headersCount; i++)
+ {
+ if (lstrcmpiA(response->headers[i].szName, "Set-Cookie"))
+ continue;
+
+ std::string cookies = response->headers[i].szValue;
+ size_t start = cookies.find("sessionid=") + 10;
+ size_t end = cookies.substr(start).find(';');
+ std::string sessionId = cookies.substr(start, end - start + 10);
+ setString("SessionID", sessionId.c_str());
+ break;
+ }
+}
+
+void CSteamProto::HandleTokenExpired()
+{
+ // Notify error to user
+ ShowNotification(_T("Steam"), TranslateT("Connection token expired. Please login again."));
+
+ // Delete expired token
+ delSetting("TokenSecret");
+
+ // Set status to offline
+ SetStatus(ID_STATUS_OFFLINE);
+}
+
+void CSteamProto::OnLoggedOn(const NETLIBHTTPREQUEST *response)
+{
+ if (response == NULL)
+ {
+ // Probably timeout or no connection, we can do nothing here
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+
+ JSONROOT root(response->pData);
+
+ JSONNODE *node = json_get(root, "error");
+ ptrT error(json_as_string(node));
+ if (mir_tstrcmpi(error, _T("OK")) || response->resultCode == HTTP_STATUS_UNAUTHORIZED)
+ {
+ // Probably expired TokenSecret
+ HandleTokenExpired();
+ return;
+ }
+
+ node = json_get(root, "umqid");
+ setString("UMQID", ptrA(mir_u2a(ptrT(json_as_string(node)))));
+
+ node = json_get(root, "message");
+ setDword("MessageID", json_as_int(node));
+
+ // load contact list
+ ptrA token(getStringA("TokenSecret"));
+ ptrA steamId(getStringA("SteamID"));
+
+ PushRequest(
+ new GetFriendListRequest(token, steamId),
+ &CSteamProto::OnGotFriendList);
+
+ // start polling thread
+ m_hPollingThread = ForkThreadEx(&CSteamProto::PollingThread, 0, NULL);
+
+ // go to online now
+ ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus = m_iDesiredStatus);
+} \ No newline at end of file
diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp
index af5a3e677f..f4fbfb8d65 100644
--- a/protocols/Steam/src/steam_proto.cpp
+++ b/protocols/Steam/src/steam_proto.cpp
@@ -330,7 +330,7 @@ int CSteamProto::SetStatus(int new_status)
}
PushRequest(
- new RsaKeyRequest(username),
+ new GetRsaKeyRequest(username),
&CSteamProto::OnGotRsaKey);
}
}
diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h
index 1f607ffd77..f37a36b20b 100644
--- a/protocols/Steam/src/steam_proto.h
+++ b/protocols/Steam/src/steam_proto.h
@@ -139,6 +139,8 @@ protected:
void OnGotRsaKey(const NETLIBHTTPREQUEST *response);
void OnAuthorization(const NETLIBHTTPREQUEST *response);
+ void OnAuthorizationError(const JSONNode &node);
+ void OnAuthorizationSuccess(const JSONNode &node);
void OnGotSession(const NETLIBHTTPREQUEST *response);
void OnLoggedOn(const NETLIBHTTPREQUEST *response);
@@ -233,8 +235,8 @@ protected:
MEVENT AddDBEvent(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, DWORD cbBlob, PBYTE pBlob);
- static void CSteamProto::ShowNotification(const wchar_t *message, int flags = 0, MCONTACT hContact = NULL);
- static void CSteamProto::ShowNotification(const wchar_t *caption, const wchar_t *message, int flags = 0, MCONTACT hContact = NULL);
+ static void CSteamProto::ShowNotification(const TCHAR *message, int flags = 0, MCONTACT hContact = NULL);
+ static void CSteamProto::ShowNotification(const TCHAR *caption, const wchar_t *message, int flags = 0, MCONTACT hContact = NULL);
// helpers
inline int IdleSeconds() {
diff --git a/protocols/Steam/src/steam_utils.cpp b/protocols/Steam/src/steam_utils.cpp
index 9484252d3a..df3dd31727 100644
--- a/protocols/Steam/src/steam_utils.cpp
+++ b/protocols/Steam/src/steam_utils.cpp
@@ -172,27 +172,27 @@ MEVENT CSteamProto::AddDBEvent(MCONTACT hContact, WORD type, DWORD timestamp, DW
return db_event_add(hContact, &dbei);
}
-void CSteamProto::ShowNotification(const wchar_t *caption, const wchar_t *message, int flags, MCONTACT hContact)
+void CSteamProto::ShowNotification(const TCHAR *caption, const wchar_t *message, int flags, MCONTACT hContact)
{
if (Miranda_Terminated())
return;
if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1))
{
- POPUPDATAW ppd = { 0 };
+ POPUPDATAT ppd = { 0 };
ppd.lchContact = hContact;
wcsncpy(ppd.lpwzContactName, caption, MAX_CONTACTNAME);
wcsncpy(ppd.lpwzText, message, MAX_SECONDLINE);
- ppd.lchIcon = ::Skin_GetIcon(MODULE"_main");
+ ppd.lchIcon = Skin_GetIcon(MODULE"_main");
- if (!PUAddPopupW(&ppd))
+ if (!PUAddPopupT(&ppd))
return;
}
- MessageBoxW(NULL, message, caption, MB_OK | flags);
+ MessageBox(NULL, message, caption, MB_OK | flags);
}
-void CSteamProto::ShowNotification(const wchar_t *message, int flags, MCONTACT hContact)
+void CSteamProto::ShowNotification(const TCHAR *message, int flags, MCONTACT hContact)
{
ShowNotification(TranslateT(MODULE), message, flags, hContact);
} \ No newline at end of file
diff --git a/protocols/Steam/src/version.h b/protocols/Steam/src/version.h
index 5d504039c5..f89c59fa87 100644
--- a/protocols/Steam/src/version.h
+++ b/protocols/Steam/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 11
#define __RELEASE_NUM 4
-#define __BUILD_NUM 0
+#define __BUILD_NUM 1
#include <stdver.h>
@@ -11,4 +11,4 @@
#define __AUTHOR "unsane, Robert P\xf6" "sel"
#define __AUTHOREMAIL ""
#define __AUTHORWEB "http://miranda-ng.org/p/Steam/"
-#define __COPYRIGHT "© 2014-15 Miranda NG team"
+#define __COPYRIGHT "� 2014-15 Miranda NG team"