summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-06-14 17:04:02 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-06-14 17:04:02 +0300
commit4a07d904cb59d4d9d494df34096d0ecac6d0cf76 (patch)
treecd62714fb9921a2fa1d44723c5e9ecbc73f1ea44 /protocols
parent0189e27fd98ad9a8ba9aacd1c5f715e56129167e (diff)
Steam: first working SendRequest()
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Steam/Steam.vcxproj1
-rw-r--r--protocols/Steam/Steam.vcxproj.filters3
-rw-r--r--protocols/Steam/src/api/app_info.h2
-rw-r--r--protocols/Steam/src/api/friend.h2
-rw-r--r--protocols/Steam/src/api/friend_list.h2
-rw-r--r--protocols/Steam/src/api/history.h4
-rw-r--r--protocols/Steam/src/api/login.h4
-rw-r--r--protocols/Steam/src/api/message.h4
-rw-r--r--protocols/Steam/src/api/poll.h79
-rw-r--r--protocols/Steam/src/api/search.h2
-rw-r--r--protocols/Steam/src/api/session.h13
-rw-r--r--protocols/Steam/src/stdafx.h1
-rw-r--r--protocols/Steam/src/steam_login.cpp21
-rw-r--r--protocols/Steam/src/steam_proto.h5
-rw-r--r--protocols/Steam/src/steam_request.cpp17
-rw-r--r--protocols/Steam/src/steam_server.cpp5
16 files changed, 63 insertions, 102 deletions
diff --git a/protocols/Steam/Steam.vcxproj b/protocols/Steam/Steam.vcxproj
index 434fbe7c43..e739a3d50d 100644
--- a/protocols/Steam/Steam.vcxproj
+++ b/protocols/Steam/Steam.vcxproj
@@ -56,7 +56,6 @@
<ClInclude Include="src\api\login.h" />
<ClInclude Include="src\api\message.h" />
<ClInclude Include="src\api\pending.h" />
- <ClInclude Include="src\api\poll.h" />
<ClInclude Include="src\api\rsa_key.h" />
<ClInclude Include="src\api\search.h" />
<ClInclude Include="src\api\session.h" />
diff --git a/protocols/Steam/Steam.vcxproj.filters b/protocols/Steam/Steam.vcxproj.filters
index 4e6664795d..92661ea40e 100644
--- a/protocols/Steam/Steam.vcxproj.filters
+++ b/protocols/Steam/Steam.vcxproj.filters
@@ -113,9 +113,6 @@
<ClInclude Include="src\api\pending.h">
<Filter>Header Files\api</Filter>
</ClInclude>
- <ClInclude Include="src\api\poll.h">
- <Filter>Header Files\api</Filter>
- </ClInclude>
<ClInclude Include="src\api\rsa_key.h">
<Filter>Header Files\api</Filter>
</ClInclude>
diff --git a/protocols/Steam/src/api/app_info.h b/protocols/Steam/src/api/app_info.h
index b4c2618249..d2ef0df532 100644
--- a/protocols/Steam/src/api/app_info.h
+++ b/protocols/Steam/src/api/app_info.h
@@ -5,7 +5,7 @@ class GetAppInfoRequest : public HttpRequest
{
public:
GetAppInfoRequest(const char *token, const char *appIds) :
- HttpRequest(REQUEST_GET, STEAM_API_URL "/ISteamGameOAuth/GetAppInfo/v0001")
+ HttpRequest(REQUEST_GET, "/ISteamGameOAuth/GetAppInfo/v0001")
{
this << CHAR_PARAM("access_token", token) << CHAR_PARAM("appIds", appIds);
}
diff --git a/protocols/Steam/src/api/friend.h b/protocols/Steam/src/api/friend.h
index e6740e7151..a86c2c98e4 100644
--- a/protocols/Steam/src/api/friend.h
+++ b/protocols/Steam/src/api/friend.h
@@ -5,7 +5,7 @@ class GetUserSummariesRequest : public HttpRequest
{
public:
GetUserSummariesRequest(CSteamProto *ppro, const char *steamIds) :
- HttpRequest(REQUEST_GET, STEAM_API_URL "/ISteamUserOAuth/GetUserSummaries/v0002")
+ HttpRequest(REQUEST_GET, "/ISteamUserOAuth/GetUserSummaries/v0002")
{
this << CHAR_PARAM("access_token", ppro->getMStringA("TokenSecret")) << CHAR_PARAM("steamids", steamIds);
}
diff --git a/protocols/Steam/src/api/friend_list.h b/protocols/Steam/src/api/friend_list.h
index 359423d359..84d8536bcb 100644
--- a/protocols/Steam/src/api/friend_list.h
+++ b/protocols/Steam/src/api/friend_list.h
@@ -5,7 +5,7 @@ class GetFriendListRequest : public HttpRequest
{
public:
GetFriendListRequest(const char *token, const char *steamId, const char *relationship) :
- HttpRequest(REQUEST_GET, STEAM_API_URL "/ISteamUserOAuth/GetFriendList/v0001")
+ HttpRequest(REQUEST_GET, "/ISteamUserOAuth/GetFriendList/v0001")
{
this << CHAR_PARAM("access_token", token) << CHAR_PARAM("steamid", steamId) << CHAR_PARAM("relationship", relationship);
}
diff --git a/protocols/Steam/src/api/history.h b/protocols/Steam/src/api/history.h
index 290f2310df..fbc09abed6 100644
--- a/protocols/Steam/src/api/history.h
+++ b/protocols/Steam/src/api/history.h
@@ -5,7 +5,7 @@ class GetConversationsRequest : public HttpRequest
{
public:
GetConversationsRequest(CSteamProto *ppro) :
- HttpRequest(REQUEST_GET, STEAM_API_URL "/IFriendMessagesService/GetActiveMessageSessions/v0001")
+ HttpRequest(REQUEST_GET, "/IFriendMessagesService/GetActiveMessageSessions/v0001")
{
this << CHAR_PARAM("access_token", ppro->getMStringA("TokenSecret"));
}
@@ -30,7 +30,7 @@ class GetHistoryMessagesRequest : public HttpRequest
{
public:
GetHistoryMessagesRequest(const char *token, const char *steamId, const char *who, time_t since) :
- HttpRequest(REQUEST_GET, STEAM_API_URL "/IFriendMessagesService/GetRecentMessages/v0001")
+ HttpRequest(REQUEST_GET, "/IFriendMessagesService/GetRecentMessages/v0001")
{
this
<< CHAR_PARAM("access_token", token)
diff --git a/protocols/Steam/src/api/login.h b/protocols/Steam/src/api/login.h
index d9511c4752..ece955840d 100644
--- a/protocols/Steam/src/api/login.h
+++ b/protocols/Steam/src/api/login.h
@@ -5,7 +5,7 @@ class LogonRequest : public HttpRequest
{
public:
LogonRequest(const char *token) :
- HttpRequest(REQUEST_POST, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Logon/v0001")
+ HttpRequest(REQUEST_POST, "/ISteamWebUserPresenceOAuth/Logon/v0001")
{
char data[256];
mir_snprintf(data, "access_token=%s&ui_mode=web", token);
@@ -31,7 +31,7 @@ class LogoffRequest : public HttpRequest
{
public:
LogoffRequest(const char *token, const char *umqId) :
- HttpRequest(REQUEST_POST, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Logoff/v0001")
+ HttpRequest(REQUEST_POST, "/ISteamWebUserPresenceOAuth/Logoff/v0001")
{
this
<< CHAR_PARAM("access_token", token)
diff --git a/protocols/Steam/src/api/message.h b/protocols/Steam/src/api/message.h
index e07e70d959..934bdc875e 100644
--- a/protocols/Steam/src/api/message.h
+++ b/protocols/Steam/src/api/message.h
@@ -5,7 +5,7 @@ class SendMessageRequest : public HttpRequest
{
public:
SendMessageRequest(const char *token, const char *umqId, const char *steamId, const char *text) :
- HttpRequest(REQUEST_POST, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Message/v0001")
+ HttpRequest(REQUEST_POST, "/ISteamWebUserPresenceOAuth/Message/v0001")
{
this
<< CHAR_PARAM("access_token", token)
@@ -20,7 +20,7 @@ class SendTypingRequest : public HttpRequest
{
public:
SendTypingRequest(const char *token, const char *umqId, const char *steamId) :
- HttpRequest(REQUEST_POST, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Message/v0001")
+ HttpRequest(REQUEST_POST, "/ISteamWebUserPresenceOAuth/Message/v0001")
{
this
<< CHAR_PARAM("access_token", token)
diff --git a/protocols/Steam/src/api/poll.h b/protocols/Steam/src/api/poll.h
deleted file mode 100644
index 9de2ed32d3..0000000000
--- a/protocols/Steam/src/api/poll.h
+++ /dev/null
@@ -1,79 +0,0 @@
-#ifndef _STEAM_REQUEST_POLL_H_
-#define _STEAM_REQUEST_POLL_H_
-
-class PollRequest : public HttpRequest
-{
-public:
- PollRequest(CSteamProto *ppro) :
- HttpRequest(REQUEST_POST, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Poll/v0001")
- {
- timeout = (STEAM_API_TIMEOUT + 5) * 1000;
- // flags |= NLHRF_PERSISTENT;
-
- AddHeader("Connection", "keep-alive");
-
- this
- << CHAR_PARAM("access_token", ppro->getMStringA("TokenSecret"))
- << CHAR_PARAM("umqid", ppro->getMStringA("UMQID"))
- << INT64_PARAM("message", ppro->getDword("MessageID"))
- << INT_PARAM("secidletime", ppro->IdleSeconds());
- }
-
- //{
- // "pollid": 0,
- // "sectimeout" : 30,
- // "error" : "Timeout"
- //}
-
- //{
- // "pollid": 0,
- // "messages": [
- // {
- // "type": "typing",
- // "timestamp": 17276041,
- // "utc_timestamp": 1514974857,
- // "steamid_from": "XXXXXXXXXXXXXXXXX",
- // "text": ""
- // },
- // {
- // "type": "saytext",
- // "timestamp" : 17380133,
- // "utc_timestamp" : 1514974961,
- // "steamid_from" : "XXXXXXXXXXXXXXXXX",
- // "text" : "message"
- // },
- // {
- // "type": "personarelationship",
- // "timestamp" : 7732750,
- // "utc_timestamp" : 1515187192,
- // "steamid_from" : "XXXXXXXXXXXXXXXXX",
- // "status_flags" : 1,
- // "persona_state" : 2
- // },
- // {
- // "type": "personastate",
- // "timestamp" : 366860,
- // "utc_timestamp" : 1515007523,
- // "steamid_from" : "XXXXXXXXXXXXXXXXX",
- // "status_flags" : 9055,
- // "persona_state" : 1,
- // "persona_name" : "nickname"
- // },
- // {
- // "type": "notificationcountupdate",
- // "timestamp" : 11605105,
- // "utc_timestamp" : 1515191064
- // }
- // ]
- // ,
- // "messagelast": 4,
- // "timestamp": 17276041,
- // "utc_timestamp": 1514974857,
- // "messagebase": 3,
- // "sectimeout": 14,
- // "error": "OK"
- //}
-
-};
-
-#endif //_STEAM_REQUEST_POLL_H_
diff --git a/protocols/Steam/src/api/search.h b/protocols/Steam/src/api/search.h
index fd3c8a66f0..d72d140dc5 100644
--- a/protocols/Steam/src/api/search.h
+++ b/protocols/Steam/src/api/search.h
@@ -5,7 +5,7 @@ class SearchRequest : public HttpRequest
{
public:
SearchRequest(const char *token, const char *text, int offset = 0, int count = 30) :
- HttpRequest(REQUEST_GET, STEAM_API_URL "/ISteamUserOAuth/Search/v0001")
+ HttpRequest(REQUEST_GET, "/ISteamUserOAuth/Search/v0001")
{
this
<< CHAR_PARAM("access_token", token)
diff --git a/protocols/Steam/src/api/session.h b/protocols/Steam/src/api/session.h
index 00705c1b67..8c7351db6f 100644
--- a/protocols/Steam/src/api/session.h
+++ b/protocols/Steam/src/api/session.h
@@ -1,9 +1,15 @@
#ifndef _STEAM_REQUEST_SESSION_H_
#define _STEAM_REQUEST_SESSION_H_
-class GetSessionRequest : public HttpRequest
+struct GetHostsRequest : public HttpRequest
+{
+ GetHostsRequest() :
+ HttpRequest(REQUEST_GET, "/ISteamDirectory/GetCMList/v0001?cellid=0")
+ {}
+};
+
+struct GetSessionRequest : public HttpRequest
{
-public:
GetSessionRequest(const char *token, const char *steamId, const char *cookie) :
HttpRequest(REQUEST_POST, STEAM_WEB_URL "/mobileloginsucceeded")
{
@@ -23,9 +29,8 @@ public:
}
};
-class GetSessionRequest2 : public HttpRequest
+struct GetSessionRequest2 : public HttpRequest
{
-public:
GetSessionRequest2(const char *token, const char *steamId) :
HttpRequest(REQUEST_GET, STEAM_WEB_URL "/mobilesettings/GetManifest/v0001")
{
diff --git a/protocols/Steam/src/stdafx.h b/protocols/Steam/src/stdafx.h
index a7fa9f4406..c05a845a8d 100644
--- a/protocols/Steam/src/stdafx.h
+++ b/protocols/Steam/src/stdafx.h
@@ -79,7 +79,6 @@ extern HANDLE hExtraXStatus;
#include "api/login.h"
#include "api/message.h"
#include "api/pending.h"
-#include "api/poll.h"
#include "api/rsa_key.h"
#include "api/search.h"
#include "api/session.h"
diff --git a/protocols/Steam/src/steam_login.cpp b/protocols/Steam/src/steam_login.cpp
index 32a418d848..3c077f4dde 100644
--- a/protocols/Steam/src/steam_login.cpp
+++ b/protocols/Steam/src/steam_login.cpp
@@ -27,6 +27,12 @@ void CSteamProto::Login()
SendRequest(new GetRsaKeyRequest(username), &CSteamProto::OnGotRsaKey);
}
+void CSteamProto::LoginFailed()
+{
+ m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
+ ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_FAILED, (HANDLE)m_iStatus, m_iStatus);
+}
+
void CSteamProto::Logout()
{
ptrA token(getStringA("TokenSecret"));
@@ -38,6 +44,21 @@ void CSteamProto::Logout()
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, m_iStatus);
}
+void CSteamProto::OnGotHosts(const JSONNode &root, void*)
+{
+ db_delete_module(0, STEAM_MODULE);
+
+ int i = 0;
+ CMStringA szSetting;
+ for (auto &it : root["response"]["serverlist_websockets"]) {
+ szSetting.Format("Host%d", i++);
+ db_set_ws(0, STEAM_MODULE, szSetting, it.as_mstring());
+ }
+
+ db_set_dw(0, STEAM_MODULE, DBKEY_HOSTS_COUNT, i);
+ db_set_dw(0, STEAM_MODULE, DBKEY_HOSTS_DATE, time(0));
+}
+
void CSteamProto::OnGotRsaKey(const JSONNode &root, void *)
{
if (root.isnull()) {
diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h
index 74d3631fd8..3df33f9988 100644
--- a/protocols/Steam/src/steam_proto.h
+++ b/protocols/Steam/src/steam_proto.h
@@ -36,6 +36,8 @@ typedef void(CSteamProto::*JsonCallback)(const JSONNode&, void*);
struct HttpRequest : public MTHttpRequest<CSteamProto>
{
HttpRequest(int iRequestType, const char *pszUrl);
+
+ NETLIBHTTPREQUEST* Get();
};
class CSteamProto : public PROTO<CSteamProto>
@@ -73,6 +75,7 @@ class CSteamProto : public PROTO<CSteamProto>
bool IsMe(const char *steamId);
void Login();
+ void LoginFailed();
void Logout();
void OnGotRsaKey(const JSONNode &root, void *);
@@ -84,6 +87,8 @@ class CSteamProto : public PROTO<CSteamProto>
void OnAuthorizationSuccess(const JSONNode &root);
void OnGotSession(const HttpResponse &response, void *);
+ void OnGotHosts(const JSONNode &root, void *);
+
void OnLoggedOn(const HttpResponse &response, void *);
void OnReLogin(const JSONNode &root, void *);
diff --git a/protocols/Steam/src/steam_request.cpp b/protocols/Steam/src/steam_request.cpp
index 5b23361c32..9215c873ac 100644
--- a/protocols/Steam/src/steam_request.cpp
+++ b/protocols/Steam/src/steam_request.cpp
@@ -2,7 +2,7 @@
bool CSteamProto::SendRequest(HttpRequest *request)
{
- NETLIBHTTPREQUEST *pResp = Netlib_HttpTransaction(m_hNetlibUser, request);
+ NETLIBHTTPREQUEST *pResp = Netlib_HttpTransaction(m_hNetlibUser, request->Get());
HttpResponse response(pResp);
delete request;
return response.IsSuccess();
@@ -10,7 +10,7 @@ bool CSteamProto::SendRequest(HttpRequest *request)
bool CSteamProto::SendRequest(HttpRequest *request, HttpCallback callback, void *param)
{
- NETLIBHTTPREQUEST *pResp = Netlib_HttpTransaction(m_hNetlibUser, (NETLIBHTTPREQUEST*)request);
+ NETLIBHTTPREQUEST *pResp = Netlib_HttpTransaction(m_hNetlibUser, request->Get());
HttpResponse response(pResp);
if (callback)
(this->*callback)(response, param);
@@ -20,7 +20,7 @@ bool CSteamProto::SendRequest(HttpRequest *request, HttpCallback callback, void
bool CSteamProto::SendRequest(HttpRequest *request, JsonCallback callback, void *param)
{
- NETLIBHTTPREQUEST *pResp = Netlib_HttpTransaction(m_hNetlibUser, (NETLIBHTTPREQUEST*)request);
+ NETLIBHTTPREQUEST *pResp = Netlib_HttpTransaction(m_hNetlibUser, request->Get());
HttpResponse response(pResp);
if (callback) {
JSONNode root = JSONNode::parse(response.data());
@@ -35,12 +35,23 @@ bool CSteamProto::SendRequest(HttpRequest *request, JsonCallback callback, void
HttpRequest::HttpRequest(int iRequestType, const char *szUrl)
{
+ flags = NLHRF_SSL | NLHRF_HTTP11 | NLHRF_REDIRECT | NLHRF_DUMPASTEXT;
requestType = iRequestType;
timeout = 30000;
if (szUrl)
m_szUrl = szUrl;
}
+NETLIBHTTPREQUEST* HttpRequest::Get()
+{
+ if (m_szUrl[0]== '/') {
+ m_szUrl.Insert(0, STEAM_API_URL);
+ AddHeader("User-Agent", "Valve/Steam HTTP Client 1.0");
+ }
+ szUrl = m_szUrl.GetBuffer();
+ return this;
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
// HttpResponse
diff --git a/protocols/Steam/src/steam_server.cpp b/protocols/Steam/src/steam_server.cpp
index a93c7ae696..f8c206c0e0 100644
--- a/protocols/Steam/src/steam_server.cpp
+++ b/protocols/Steam/src/steam_server.cpp
@@ -22,6 +22,9 @@ void __cdecl CSteamProto::ServerThread(void *)
// load web socket servers first if needed
int iTimeDiff = db_get_dw(0, STEAM_MODULE, DBKEY_HOSTS_DATE);
if (!db_get_dw(0, STEAM_MODULE, DBKEY_HOSTS_COUNT) || time(0) - iTimeDiff > 3600 * 24 * 7) { // once a week
- // if (!SendRequest())
+ if (!SendRequest(new GetHostsRequest(), &CSteamProto::OnGotHosts)) {
+ LoginFailed();
+ return;
+ }
}
}