diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2014-06-17 18:23:25 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2014-06-17 18:23:25 +0000 |
commit | 4e17e675414fd1af646827d4ceeb2a96c1335995 (patch) | |
tree | b5d7748e959237d714ab6942b1b92707266613a5 /protocols/Steam | |
parent | 64c2db2196761922e242aece07166ee4b9926a86 (diff) |
Steam:
- first approach of captcha support
- added some docs
git-svn-id: http://svn.miranda-ng.org/main/trunk@9533 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Steam')
-rw-r--r-- | protocols/Steam/Steam_10.vcxproj | 2 | ||||
-rw-r--r-- | protocols/Steam/Steam_10.vcxproj.filters | 6 | ||||
-rw-r--r-- | protocols/Steam/Steam_12.vcxproj | 2 | ||||
-rw-r--r-- | protocols/Steam/Steam_12.vcxproj.filters | 6 | ||||
-rw-r--r-- | protocols/Steam/doc/sources.txt | 11 | ||||
-rw-r--r-- | protocols/Steam/src/Steam/authorization.h | 14 | ||||
-rw-r--r-- | protocols/Steam/src/Steam/captcha.h | 18 | ||||
-rw-r--r-- | protocols/Steam/src/Steam/steam.h | 1 | ||||
-rw-r--r-- | protocols/Steam/src/common.h | 1 | ||||
-rw-r--r-- | protocols/Steam/src/http_request.h | 165 | ||||
-rw-r--r-- | protocols/Steam/src/steam_account.cpp | 46 | ||||
-rw-r--r-- | protocols/Steam/src/steam_dialogs.cpp | 78 | ||||
-rw-r--r-- | protocols/Steam/src/steam_pooling.cpp | 3 |
13 files changed, 127 insertions, 226 deletions
diff --git a/protocols/Steam/Steam_10.vcxproj b/protocols/Steam/Steam_10.vcxproj index 7b77dbd3f1..7adb920113 100644 --- a/protocols/Steam/Steam_10.vcxproj +++ b/protocols/Steam/Steam_10.vcxproj @@ -188,10 +188,10 @@ </ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
- <ClInclude Include="src\http_request.h" />
<ClInclude Include="src\common.h" />
<ClInclude Include="src\Steam\authorization.h" />
<ClInclude Include="src\Steam\avatar.h" />
+ <ClInclude Include="src\Steam\captcha.h" />
<ClInclude Include="src\Steam\pending.h" />
<ClInclude Include="src\Steam\rsa_key.h" />
<ClInclude Include="src\Steam\friend.h" />
diff --git a/protocols/Steam/Steam_10.vcxproj.filters b/protocols/Steam/Steam_10.vcxproj.filters index 64a828d75d..f652465c1e 100644 --- a/protocols/Steam/Steam_10.vcxproj.filters +++ b/protocols/Steam/Steam_10.vcxproj.filters @@ -68,9 +68,6 @@ <ClInclude Include="src\steam_proto.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="src\http_request.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="src\Steam\steam.h">
<Filter>Header Files\Steam</Filter>
</ClInclude>
@@ -101,6 +98,9 @@ <ClInclude Include="src\Steam\rsa_key.h">
<Filter>Header Files\Steam</Filter>
</ClInclude>
+ <ClInclude Include="src\Steam\captcha.h">
+ <Filter>Header Files\Steam</Filter>
+ </ClInclude>
<ClInclude Include="src\Steam\avatar.h">
<Filter>Header Files\Steam</Filter>
</ClInclude>
diff --git a/protocols/Steam/Steam_12.vcxproj b/protocols/Steam/Steam_12.vcxproj index 4f3259f87c..192936124f 100644 --- a/protocols/Steam/Steam_12.vcxproj +++ b/protocols/Steam/Steam_12.vcxproj @@ -193,9 +193,9 @@ </ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="src\common.h" />
- <ClInclude Include="src\http_request.h" />
<ClInclude Include="src\Steam\authorization.h" />
<ClInclude Include="src\Steam\avatar.h" />
+ <ClInclude Include="src\Steam\captcha.h" />
<ClInclude Include="src\Steam\friend.h" />
<ClInclude Include="src\Steam\friend_list.h" />
<ClInclude Include="src\Steam\pending.h" />
diff --git a/protocols/Steam/Steam_12.vcxproj.filters b/protocols/Steam/Steam_12.vcxproj.filters index de27b86ab0..0a9df2ae03 100644 --- a/protocols/Steam/Steam_12.vcxproj.filters +++ b/protocols/Steam/Steam_12.vcxproj.filters @@ -68,9 +68,6 @@ <ClInclude Include="src\steam_proto.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="src\http_request.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="src\Steam\authorization.h">
<Filter>Header Files\Steam</Filter>
</ClInclude>
@@ -107,6 +104,9 @@ <ClInclude Include="src\Steam\rsa_key.h">
<Filter>Header Files\Steam</Filter>
</ClInclude>
+ <ClInclude Include="src\Steam\captcha.h">
+ <Filter>Header Files\Steam</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\resource.rc">
diff --git a/protocols/Steam/doc/sources.txt b/protocols/Steam/doc/sources.txt new file mode 100644 index 0000000000..ccac7b00a3 --- /dev/null +++ b/protocols/Steam/doc/sources.txt @@ -0,0 +1,11 @@ +Steam web API
+http://steamcommunity.com/dev
+Official supported API
+http://api.steampowered.com/ISteamWebAPIUtil/GetSupportedAPIList/v0001/
+Not supported, bud worked API
+http://pastebin.com/qsX36TMT
+Steam browser protocol
+https://developer.valvesoftware.com/wiki/Steam_browser_protocol
+Other realization on c++
+https://code.google.com/p/pidgin-opensteamworks/
+https://github.com/jgeboski/bitlbee-steam
\ No newline at end of file diff --git a/protocols/Steam/src/Steam/authorization.h b/protocols/Steam/src/Steam/authorization.h index c325be31f8..74a2188aca 100644 --- a/protocols/Steam/src/Steam/authorization.h +++ b/protocols/Steam/src/Steam/authorization.h @@ -5,7 +5,7 @@ namespace SteamWebApi {
class AuthorizationRequest : public HttpsPostRequest
{
- void InitData(const char *username, const char *password, const char *timestamp, const char *guardId = "-1", const char *guardCode = "")
+ void InitData(const char *username, const char *password, const char *timestamp, const char *guardId = "-1", const char *guardCode = "", const char *captchaId = "-1", const char *captchaText = "")
{
char data[1024];
mir_snprintf(data, SIZEOF(data),
@@ -14,8 +14,8 @@ namespace SteamWebApi ptrA(mir_urlEncode(password)),
guardId,
guardCode,
- "-1",
- "",
+ captchaId,
+ captchaText,
timestamp,
time(NULL));
@@ -38,6 +38,14 @@ namespace SteamWebApi InitData(username, password, timestamp, guardId, guardCode);
}
+
+ AuthorizationRequest(const char *username, const char *password, const char *timestamp, const char *guardId, const char *guardCode, const char *captchaId, const char *captchaText) :
+ HttpsPostRequest(STEAM_COM_URL "/mobilelogin/dologin")
+ {
+ flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP;
+
+ InitData(username, password, timestamp, guardId, guardCode, captchaId, captchaText);
+ }
};
}
diff --git a/protocols/Steam/src/Steam/captcha.h b/protocols/Steam/src/Steam/captcha.h new file mode 100644 index 0000000000..cb02fdda49 --- /dev/null +++ b/protocols/Steam/src/Steam/captcha.h @@ -0,0 +1,18 @@ +#ifndef _STEAM_CAPTCHA_H_
+#define _STEAM_CAPTCHA_H_
+
+namespace SteamWebApi
+{
+ class GetCaptchaRequest : public HttpGetRequest
+ {
+ public:
+ GetCaptchaRequest(const char *url) :
+ HttpGetRequest(url)
+ {
+ flags = NLHRF_HTTP11 | NLHRF_NODUMP;
+ }
+ };
+}
+
+
+#endif //_STEAM_CAPTCHA_H_
\ No newline at end of file diff --git a/protocols/Steam/src/Steam/steam.h b/protocols/Steam/src/Steam/steam.h index a30ea6b4e6..c32da7e92a 100644 --- a/protocols/Steam/src/Steam/steam.h +++ b/protocols/Steam/src/Steam/steam.h @@ -120,5 +120,6 @@ namespace SteamWebApi #include "Steam\message.h"
#include "Steam\search.h"
#include "Steam\avatar.h"
+#include "Steam\captcha.h"
#endif //_STEAM_H_
\ No newline at end of file diff --git a/protocols/Steam/src/common.h b/protocols/Steam/src/common.h index afef19c6f0..1597bd002d 100644 --- a/protocols/Steam/src/common.h +++ b/protocols/Steam/src/common.h @@ -19,6 +19,7 @@ #include <m_genmenu.h>
#include <m_string.h>
#include <m_freeimage.h>
+#include <m_imgsrvc.h>
#include <m_protocols.h>
#include <m_protomod.h>
#include <m_protosvc.h>
diff --git a/protocols/Steam/src/http_request.h b/protocols/Steam/src/http_request.h deleted file mode 100644 index c9f9013eab..0000000000 --- a/protocols/Steam/src/http_request.h +++ /dev/null @@ -1,165 +0,0 @@ -#ifndef _HTTP_REQUEST_H_
-#define _HTTP_REQUEST_H_
-
-#include "common.h"
-
-enum HTTP_STATUS
-{
- HTTP_STATUS_NONE = 0,
- HTTP_STATUS_OK = 200,
- HTTP_STATUS_FOUND = 302,
- HTTP_STATUS_BAD_REQUEST = 400,
- HTTP_STATUS_UNAUTHORIZED = 401,
- HTTP_STATUS_FORBIDDEN = 403,
- HTTP_STATUS_NOT_FOUND = 404,
- HTTP_STATUS_METHOD_NOT_ALLOWED = 405,
- HTTP_STATUS_TOO_MANY_REQUESTS = 429,
- HTTP_STATUS_SERVICE_UNAVAILABLE = 503,
- HTTP_STATUS_INSUFICIENTE_STORAGE = 507
-};
-
-class HttpRequest : protected NETLIBHTTPREQUEST//, public MZeroedObject
-{
-public:
- HttpRequest(HANDLE hNetlibUser, int request, LPCSTR url)
- {
- cbSize = sizeof(NETLIBHTTPREQUEST);
- pData = NULL;
- szUrl = NULL;
- headers = NULL;
- dataLength = 0;
- headersCount = 0;
- szResultDescr = NULL;
- flags = NLHRF_HTTP11 | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT;
- requestType = request;
- timeout = 0;
-
- m_hNetlibUser = hNetlibUser;
- szUrl = NULL;
- m_szUrl = url;
-
- AddHeader("User-Agent", "Steam App / Miranda / 0.0.1");
- }
-
- ~HttpRequest()
- {
- if (headers != NULL)
- {
- for (int i = 0; i < headersCount; i++)
- {
- mir_free(headers[i].szName);
- mir_free(headers[i].szValue);
- }
- mir_free(headers);
- }
- if (szUrl != NULL)
- mir_free(szUrl);
- if (pData != NULL)
- mir_free(pData);
- }
-
- void ResetFlags(int newFlags)
- {
- flags = newFlags;
- }
-
- void AddHeader(LPCSTR szName, LPCSTR szValue)
- {
- if (headers == NULL)
- headers = (NETLIBHTTPHEADER*)mir_alloc(sizeof(NETLIBHTTPHEADER));
- else
- headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER) * (headersCount + 1));
- headers[headersCount].szName = mir_strdup(szName);
- headers[headersCount].szValue = mir_strdup(szValue);
- headersCount++;
- }
-
- void SetData(const char *data, size_t size)
- {
- if (pData != NULL)
- mir_free(pData);
-
- dataLength = (int)size;
- pData = (char*)mir_alloc(size);
- memcpy(pData, data, size);
- }
-
- void AddUrlPart(LPCSTR szPart)
- {
- m_szUrl += szPart;
- }
-
- void AddParameter(LPCSTR szName, LPCSTR szValue)
- {
- if (m_szUrl.find('?') == -1)
- m_szUrl.append("?").append(szName).append("=").append(szValue);
- else
- m_szUrl.append("&").append(szName).append("=").append(szValue);
- }
-
- void AddParameter(LPCSTR szValue)
- {
- if (m_szUrl.find('?') == -1)
- m_szUrl.append("?").append(szValue);
- else
- m_szUrl.append("&").append(szValue);
- }
-
- void SetTimeout(int msecs)
- {
- timeout = msecs;
- }
-
- NETLIBHTTPREQUEST *Send()
- {
- szUrl = mir_strdup(m_szUrl.c_str());
- NETLIBHTTPREQUEST *response = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)this);
- mir_free(szUrl);szUrl = NULL;
- return response;
- }
-
-private:
- std::string m_szUrl;
- HANDLE m_hNetlibUser;
-};
-
-class HttpGetRequest : public HttpRequest
-{
-public:
- HttpGetRequest(HANDLE hNetlibUser, LPCSTR url) : HttpRequest(hNetlibUser, REQUEST_GET, url) { }
-};
-
-class HttpPostRequest : public HttpRequest
-{
-public:
- HttpPostRequest(HANDLE hNetlibUser, LPCSTR url) : HttpRequest(hNetlibUser, REQUEST_POST, url) { }
-};
-
-class SecureHttpRequest : public HttpRequest
-{
-public:
- SecureHttpRequest(HANDLE hNetlibUser, int request, LPCSTR url)
- : HttpRequest(hNetlibUser, request, url)
- {
- flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT;
- }
-};
-
-class SecureHttpGetRequest : public SecureHttpRequest
-{
-public:
- SecureHttpGetRequest(HANDLE hNetlibUser, LPCSTR url)
- : SecureHttpRequest(hNetlibUser, REQUEST_GET, url) { }
-};
-
-class SecureHttpPostRequest : public SecureHttpRequest
-{
-public:
- SecureHttpPostRequest(HANDLE hNetlibUser, LPCSTR url)
- : SecureHttpRequest(hNetlibUser, REQUEST_POST, url)
- {
- AddHeader("Content-Type", "application/x-www-form-urlencoded");
- }
-};
-
-#endif //_HTTP_REQUEST_H_
\ No newline at end of file diff --git a/protocols/Steam/src/steam_account.cpp b/protocols/Steam/src/steam_account.cpp index 3db721db27..f05741f0bd 100644 --- a/protocols/Steam/src/steam_account.cpp +++ b/protocols/Steam/src/steam_account.cpp @@ -102,20 +102,46 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *arg) new SteamWebApi::AuthorizationRequest(username, base64RsaEncryptedPassword, timestamp, guardId, guard.code),
&CSteamProto::OnAuthorization);
}
-
- // todo: show captcha dialog
- /*node = json_get(root, "captcha_needed");
+
+ node = json_get(root, "captcha_needed");
if (json_as_bool(node) > 0)
{
node = json_get(root, "captcha_gid");
- authResult->captchagid = ptrA(mir_u2a(json_as_string(node)));
- }
+ ptrA captchaId(mir_u2a(json_as_string(node)));
- if (!authResult->emailauth_needed && !authResult->captcha_needed)
- {
- node = json_get(root, "message");
- authResult->message = json_as_string(node);
- }*/
+ char url[MAX_PATH];
+ mir_snprintf(url, SIZEOF(url), STEAM_COM_URL "/public/captcha.php?gid=%s", captchaId);
+
+ SteamWebApi::GetCaptchaRequest *request = new SteamWebApi::GetCaptchaRequest(url);
+ request->szUrl = (char*)request->url.c_str();
+ NETLIBHTTPREQUEST *response = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)request);
+ delete request;
+
+ CallService(MS_UTILS_OPENURL, 0, (LPARAM)url);
+
+ CaptchaParam captcha = { 0 };
+ captcha.size = response->dataLength;
+ captcha.data = (BYTE*)mir_alloc(captcha.size);
+ memcpy(captcha.data, response->pData, captcha.size);
+
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response);
+
+ if (DialogBoxParam(
+ g_hInstance,
+ MAKEINTRESOURCE(IDD_CAPTCHA),
+ NULL,
+ CSteamProto::CaptchaProc,
+ (LPARAM)&captcha) != 1)
+ return;
+
+ ptrA username(mir_urlEncode(ptrA(mir_utf8encodeW(getWStringA("Username")))));
+ ptrA base64RsaEncryptedPassword(getStringA("EncryptedPassword"));
+ ptrA timestamp(getStringA("Timestamp"));
+
+ PushRequest(
+ new SteamWebApi::AuthorizationRequest(username, base64RsaEncryptedPassword, timestamp, "-1", "", captchaId, captcha.text),
+ &CSteamProto::OnAuthorization);
+ }
return;
}
diff --git a/protocols/Steam/src/steam_dialogs.cpp b/protocols/Steam/src/steam_dialogs.cpp index 2e672fff92..4df9192d81 100644 --- a/protocols/Steam/src/steam_dialogs.cpp +++ b/protocols/Steam/src/steam_dialogs.cpp @@ -70,46 +70,44 @@ INT_PTR CALLBACK CSteamProto::CaptchaProc(HWND hwnd, UINT message, WPARAM wParam EndDialog(hwnd, 0);
break;
- //case WM_PAINT:
- // {
- // /*FI_INTERFACE *fei = 0;
-
- // INT_PTR result = CALLSERVICE_NOTFOUND;
- // if (ServiceExists(MS_IMG_GETINTERFACE))
- // result = CallService(MS_IMG_GETINTERFACE, FI_IF_VERSION, (LPARAM)&fei);
-
- // if (fei == NULL || result != S_OK) {
- // MessageBox(0, TranslateT("Fatal error, image services not found. Avatar services will be disabled."), TranslateT("Avatar Service"), MB_OK);
- // return 0;
- // }*/
-
- // PAINTSTRUCT ps;
- // HDC hDC = BeginPaint(hwnd, &ps);
-
- // //FreeImage_Initialise();
- //
- // /*FIMEMORY *stream = FreeImage_OpenMemory(captcha->data, captcha->size);
- // FIBITMAP *dib = FreeImage_LoadFromMemory(FIF_PNG, stream, PNG_DEFAULT);
- // FreeImage_CloseMemory(stream);
-
- // SetStretchBltMode(hDC, COLORONCOLOR);
- // StretchDIBits(
- // hDC,
- // 0, 0,
- // 206, 40,
- // 0, 0,
- // FreeImage_GetWidth(dib), FreeImage_GetHeight(dib),
- // FreeImage_GetBits(dib),
- // FreeImage_GetInfo(dib),
- // DIB_RGB_COLORS, SRCCOPY);
-
- // FreeImage_Unload(dib);*/
-
- // //FreeImage_DeInitialise();
-
- // EndPaint(hwnd, &ps);
- // }
- // return 0;
+ case WM_PAINT:
+ {
+ FI_INTERFACE *fei = 0;
+
+ INT_PTR result = CALLSERVICE_NOTFOUND;
+ if (ServiceExists(MS_IMG_GETINTERFACE))
+ result = CallService(MS_IMG_GETINTERFACE, FI_IF_VERSION, (LPARAM)&fei);
+
+ if (fei == NULL || result != S_OK) {
+ MessageBox(0, TranslateT("Fatal error, image services not found. Avatar services will be disabled."), TranslateT("Avatar Service"), MB_OK);
+ return 0;
+ }
+
+ FIMEMORY *memory = fei->FI_OpenMemory(captcha->data, captcha->size);
+ FIBITMAP *bitmap = fei->FI_LoadFromMemory(FIF_PNG, memory, PNG_DEFAULT);
+ fei->FI_CloseMemory(memory);
+
+ PAINTSTRUCT ps;
+ HDC hDC = BeginPaint(hwnd, &ps);
+
+ SetStretchBltMode(hDC, COLORONCOLOR);
+ StretchDIBits(
+ hDC,
+ 0, 0,
+ 206, 40,
+ 0, 0,
+ fei->FI_GetWidth(bitmap),
+ fei->FI_GetHeight(bitmap),
+ fei->FI_GetBits(bitmap),
+ fei->FI_GetInfo(bitmap),
+ DIB_RGB_COLORS, SRCCOPY);
+
+ fei->FI_Unload(bitmap);
+ //fei->FI_DeInitialise();
+
+ EndPaint(hwnd, &ps);
+ }
+ return 0;
case WM_COMMAND:
{
diff --git a/protocols/Steam/src/steam_pooling.cpp b/protocols/Steam/src/steam_pooling.cpp index f2b8ef94a1..48755bbbc2 100644 --- a/protocols/Steam/src/steam_pooling.cpp +++ b/protocols/Steam/src/steam_pooling.cpp @@ -55,6 +55,9 @@ void CSteamProto::ParsePollData(JSONNODE *data) if (IsMe(steamId))
{
+ node = json_get(item, "persona_name");
+ setWString("Nick", json_as_string(node));
+
if (status == ID_STATUS_OFFLINE)
continue;
|