diff options
-rw-r--r-- | protocols/Steam/src/Steam/authorization.h | 175 | ||||
-rw-r--r-- | protocols/Steam/src/Steam/avatar.h | 44 | ||||
-rw-r--r-- | protocols/Steam/src/Steam/friend.h | 147 | ||||
-rw-r--r-- | protocols/Steam/src/Steam/friend_list.h | 163 | ||||
-rw-r--r-- | protocols/Steam/src/Steam/login.h | 69 | ||||
-rw-r--r-- | protocols/Steam/src/Steam/message.h | 150 | ||||
-rw-r--r-- | protocols/Steam/src/Steam/pending.h | 94 | ||||
-rw-r--r-- | protocols/Steam/src/Steam/poll.h | 225 | ||||
-rw-r--r-- | protocols/Steam/src/Steam/rsa_key.h | 54 | ||||
-rw-r--r-- | protocols/Steam/src/Steam/search.h | 89 | ||||
-rw-r--r-- | protocols/Steam/src/Steam/session.h | 72 | ||||
-rw-r--r-- | protocols/Steam/src/Steam/steam.h | 23 | ||||
-rw-r--r-- | protocols/Steam/src/common.h | 2 | ||||
-rw-r--r-- | protocols/Steam/src/steam_account.cpp | 201 | ||||
-rw-r--r-- | protocols/Steam/src/steam_contacts.cpp | 555 | ||||
-rw-r--r-- | protocols/Steam/src/steam_messages.cpp | 46 | ||||
-rw-r--r-- | protocols/Steam/src/steam_pooling.cpp | 128 | ||||
-rw-r--r-- | protocols/Steam/src/steam_proto.cpp | 5 | ||||
-rw-r--r-- | protocols/Steam/src/steam_proto.h | 42 |
19 files changed, 250 insertions, 2034 deletions
diff --git a/protocols/Steam/src/Steam/authorization.h b/protocols/Steam/src/Steam/authorization.h index 0fcc5c9923..c325be31f8 100644 --- a/protocols/Steam/src/Steam/authorization.h +++ b/protocols/Steam/src/Steam/authorization.h @@ -3,177 +3,6 @@ namespace SteamWebApi
{
- class AuthorizationApi : public BaseApi
- {
- public:
-
- class AuthResult : public Result
- {
- friend AuthorizationApi;
-
- private:
- std::string steamid;
- std::string token;
- std::string cookie;
-
- std::string sessionid;
-
- std::string emailauth;
- std::string emaildomain;
- std::string emailsteamid;
-
- std::string captchagid;
- std::string captcha_text;
-
- std::wstring message;
-
- bool captcha_needed;
- bool emailauth_needed;
-
- public:
- AuthResult()
- {
- captcha_needed = false;
- emailauth_needed = false;
- captchagid = "-1";
- }
-
- bool IsCaptchaNeeded() const { return captcha_needed; }
- bool IsEmailAuthNeeded() const { return emailauth_needed; }
- const char *GetSteamid() const { return steamid.c_str(); }
- const char *GetToken() const { return token.c_str(); }
- const char *GetCookie() const { return cookie.c_str(); }
- const char *GetSessionId() const { return sessionid.c_str(); }
- const char *GetAuthId() const { return emailauth.c_str(); }
- const char *GetAuthCode() const { return emailsteamid.c_str(); }
- const char *GetEmailDomain() const { return emaildomain.c_str(); }
- const char *GetCaptchaId() const { return captchagid.c_str(); }
- const wchar_t *GetMessage() const { return message.c_str(); }
-
- void SetAuthCode(char *code)
- {
- emailauth = code;
- }
-
- void SetCaptchaText(char *text)
- {
- captcha_text = text;
- }
- };
-
- static void Authorize(HANDLE hConnection, const wchar_t *username, const char *password, const char *timestamp, AuthResult *authResult)
- {
- authResult->success = false;
- authResult->captcha_needed = false;
- authResult->emailauth_needed = false;
-
- ptrA base64Username(mir_urlEncode(ptrA(mir_utf8encodeW(username))));
-
- char data[1024];
- mir_snprintf(data, SIZEOF(data),
- "username=%s&password=%s&emailauth=%s&emailsteamid=%s&captchagid=%s&captcha_text=%s&rsatimestamp=%s&donotcache=%ld&remember_login=true&oauth_client_id=DE45CD61&oauth_scope=read_profile write_profile read_client write_client",
- base64Username,
- ptrA(mir_urlEncode(password)),
- ptrA(mir_urlEncode(authResult->emailauth.c_str())),
- authResult->emailsteamid.c_str(),
- authResult->captchagid.c_str(),
- ptrA(mir_urlEncode(authResult->captcha_text.c_str())),
- timestamp,
- time(NULL));
-
- SecureHttpPostRequest request(hConnection, STEAM_COM_URL "/mobilelogin/dologin");
- request.ResetFlags(NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP);
- request.SetData(data, strlen(data));
-
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response)
- return;
-
- if ((authResult->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
- return;
-
- JSONNODE *root = json_parse(response->pData), *node;
-
- node = json_get(root, "success");
- authResult->success = json_as_bool(node) > 0;
- if (!authResult->success)
- {
- node = json_get(root, "emailauth_needed");
- authResult->emailauth_needed = json_as_bool(node) > 0;
- if (authResult->emailauth_needed)
- {
- node = json_get(root, "emailsteamid");
- authResult->emailsteamid = ptrA(mir_u2a(json_as_string(node)));
-
- node = json_get(root, "emaildomain");
- authResult->emaildomain = ptrA(mir_utf8encodeW(json_as_string(node)));
- }
-
- node = json_get(root, "captcha_needed");
- authResult->captcha_needed = json_as_bool(node) > 0;
- if (authResult->captcha_needed)
- {
- node = json_get(root, "captcha_gid");
- authResult->captchagid = ptrA(mir_u2a(json_as_string(node)));
- }
-
- if (!authResult->emailauth_needed && !authResult->captcha_needed)
- {
- node = json_get(root, "message");
- authResult->message = json_as_string(node);
- }
- }
- else
- {
- node = json_get(root, "login_complete");
- if (!json_as_bool(node))
- return;
-
- node = json_get(root, "oauth");
- root = json_parse(ptrA(mir_u2a(json_as_string(node))));
-
- node = json_get(root, "steamid");
- authResult->steamid = ptrA(mir_u2a(json_as_string(node)));
-
- node = json_get(root, "oauth_token");
- authResult->token = ptrA(mir_u2a(json_as_string(node)));
-
- node = json_get(root, "webcookie");
- authResult->cookie = ptrA(mir_u2a(json_as_string(node)));
-
- mir_snprintf(data, SIZEOF(data),
- "oauth_token=%s&steamid=%s&webcookie=%s",
- authResult->token.c_str(),
- authResult->steamid.c_str(),
- authResult->cookie.c_str());
-
- SecureHttpPostRequest second_request(hConnection, STEAM_COM_URL "/mobileloginsucceeded");
- second_request.ResetFlags(NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP);
- second_request.SetData(data, strlen(data));
-
- response = second_request.Send();
- if (!response)
- 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(';');
- authResult->sessionid = cookies.substr(start, end - start + 10);
- break;
- }
-
- authResult->success = true;
- authResult->captcha_needed = false;
- authResult->emailauth_needed = false;
- }
- }
- };
-
class AuthorizationRequest : public HttpsPostRequest
{
void InitData(const char *username, const char *password, const char *timestamp, const char *guardId = "-1", const char *guardCode = "")
@@ -209,10 +38,6 @@ namespace SteamWebApi InitData(username, password, timestamp, guardId, guardCode);
}
-
- /*const wchar_t *GetUsername() { return username; }
- const char *GetPassword() { return password; }
- const char *GetTimestamp() { return timestamp; }*/
};
}
diff --git a/protocols/Steam/src/Steam/avatar.h b/protocols/Steam/src/Steam/avatar.h index 1ad2637def..e306b7dfb8 100644 --- a/protocols/Steam/src/Steam/avatar.h +++ b/protocols/Steam/src/Steam/avatar.h @@ -3,49 +3,13 @@ namespace SteamWebApi
{
- class AvatarApi : public BaseApi
+ class GetAvatarRequest : public HttpGetRequest
{
public:
-
- class Avatar : public Result
- {
- friend AvatarApi;
-
- private:
- size_t size;
- BYTE *data;
-
- public:
- Avatar() : size(0), data(NULL) { }
- ~Avatar()
- {
- if (data != NULL)
- mir_free(data);
- }
-
- size_t GetDataSize() const { return size; }
- const BYTE * GetData() const { return data; }
- };
-
- static void GetAvatar(HANDLE hConnection, const char *avatarUrl, Avatar *avatar)
+ GetAvatarRequest(const char *url) :
+ HttpGetRequest(url)
{
- avatar->success = false;
-
- /*HttpGetRequest request(hConnection, avatarUrl);
- request.ResetFlags(NLHRF_HTTP11 | NLHRF_NODUMP);
-
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response)
- return;
-
- if ((avatar->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
- return;
-
- avatar->size = response->dataLength;
- avatar->data = (BYTE*)mir_alloc(avatar->size);
- memcpy(avatar->data, response->pData, avatar->size);*/
-
- avatar->success = true;
+ flags = NLHRF_HTTP11 | NLHRF_NODUMP;
}
};
}
diff --git a/protocols/Steam/src/Steam/friend.h b/protocols/Steam/src/Steam/friend.h index d3ed0cc8ee..14c5250c97 100644 --- a/protocols/Steam/src/Steam/friend.h +++ b/protocols/Steam/src/Steam/friend.h @@ -3,153 +3,6 @@ namespace SteamWebApi
{
- class FriendApi : public BaseApi
- {
- public:
- struct Summary : public Result
- {
- friend FriendApi;
-
- private:
- std::string steamId;
-
- std::wstring nickname;
- std::wstring firstname;
- std::wstring lastname;
- std::wstring secondname;
- std::string countryCode;
- std::string homepage;
- std::string avatarUrl;
- std::wstring gameInfo;
- UINT32 gameId;
-
- int state;
-
- DWORD created;
- DWORD lastEvent;
-
- public:
- Summary() : gameId(0), created(0), lastEvent(0) { }
-
- const char *GetSteamId() const { return steamId.c_str(); }
- const wchar_t *GetNickName() const { return nickname.c_str(); }
- const char *GetCountryCode() const { return countryCode.c_str(); }
- const char *GetHomepage() const { return homepage.c_str(); }
- const char *GetAvatarUrl() const { return avatarUrl.c_str(); }
- const wchar_t *GetGameInfo() const { return gameInfo.c_str(); }
- const DWORD GetGameId() const { return gameId; }
- int GetState() const { return state; }
- const DWORD GetCreated() const { return created; }
- const DWORD GetLastEvent() const { return lastEvent; }
-
- const wchar_t *GetFirstName() const
- {
- return firstname.c_str();
- }
-
- const wchar_t *GetLastName() const
- {
- return lastname.c_str();
- }
- };
-
- struct Summaries : public Result
- {
- friend FriendApi;
-
- private:
- std::vector<Summary*> items;
-
- public:
- size_t GetItemCount() const { return items.size(); }
- const Summary *GetAt(size_t idx) const { return items.at(idx); }
- };
-
- static void LoadSummaries(HANDLE hConnection, const char *token, const char *steamIds, Summaries *summaries)
- {
- summaries->success = false;
-
- SecureHttpGetRequest request(hConnection, STEAM_API_URL "/ISteamUserOAuth/GetUserSummaries/v0001");
- request.AddParameter("access_token", token);
- request.AddParameter("steamids", steamIds);
-
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response)
- return;
-
- if ((summaries->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
- return;
-
- JSONNODE *root = json_parse(response->pData), *node, *child;
-
- node = json_get(root, "players");
- root = json_as_array(node);
- if (root != NULL)
- {
- for (size_t i = 0; i < json_size(root); i++)
- {
- child = json_at(root, i);
- if (child == NULL)
- break;
-
- Summary *item = new Summary();
-
- node = json_get(child, "steamid");
- item->steamId = ptrA(mir_u2a(json_as_string(node)));
-
- node = json_get(child, "personaname");
- item->nickname = json_as_string(node);
-
- node = json_get(child, "realname");
- if (node != NULL)
- {
- std::wstring realname = json_as_string(node);
- if (!realname.empty())
- {
- size_t pos = realname.find(' ', 1);
- if (pos > 0)
- {
- item->firstname = realname.substr(0, pos);
- item->lastname = realname.substr(pos + 1).c_str();
- }
- }
- }
-
- node = json_get(child, "loccountrycode");
- if (node != NULL)
- item->countryCode = ptrA(mir_u2a(json_as_string(node)));
-
- node = json_get(child, "personastate");
- item->state = json_as_int(node);
-
- node = json_get(child, "profileurl");
- item->homepage = ptrA(mir_u2a(json_as_string(node)));
-
- node = json_get(child, "timecreated");
- item->created = json_as_int(node);
-
- node = json_get(child, "lastlogoff");
- item->lastEvent = json_as_int(node);
-
- node = json_get(child, "avatarfull");
- item->avatarUrl = ptrA(mir_u2a(json_as_string(node)));
-
- node = json_get(child, "gameextrainfo");
- item->gameInfo = json_as_string(node);
-
- node = json_get(child, "gameid");
- item->gameId = atol(ptrA(mir_u2a(json_as_string(node))));
-
- summaries->items.push_back(item);
- }
- }
- else
- return;
-
- summaries->success = true;
- }
- };
-
class GetUserSummariesRequest : public HttpsGetRequest
{
public:
diff --git a/protocols/Steam/src/Steam/friend_list.h b/protocols/Steam/src/Steam/friend_list.h index 94f25d4427..a727bcf1d6 100644 --- a/protocols/Steam/src/Steam/friend_list.h +++ b/protocols/Steam/src/Steam/friend_list.h @@ -3,169 +3,6 @@ namespace SteamWebApi
{
- class FriendListApi : public BaseApi
- {
- public:
-
- enum FRIEND_TYPE
- {
- FRIEND_TYPE_NONE,
- FRIEND_TYPE_FRIEND,
- FRIEND_TYPE_IGNORED,
- };
- class FriendListItem
- {
- friend FriendListApi;
-
- private:
- std::string steamId;
- FRIEND_TYPE type;
-
- public:
- FriendListItem() : type(FRIEND_TYPE_NONE) { }
-
- const char *GetSteamId() const { return steamId.c_str(); }
- FRIEND_TYPE GetType() const { return type; }
- };
-
- class FriendList : public Result
- {
- friend FriendListApi;
-
- private:
- std::vector<FriendListItem*> items;
-
- public:
- size_t GetItemCount() const { return items.size(); }
- const FriendListItem * GetAt(size_t idx) const { return items.at(idx); }
- };
-
- static void Load(HANDLE hConnection, const char *token, const char *steamId, FriendList *friendList)
- {
- friendList->success = false;
-
- SecureHttpGetRequest request(hConnection, STEAM_API_URL "/ISteamUserOAuth/GetFriendList/v0001");
- request.AddParameter("access_token", token);
- request.AddParameter("steamid", steamId);
- request.AddParameter("relationship=friend,ignoredfriend,requestrecipient");
- //relationship = friend, requestrecipient
-
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response)
- return;
-
- if ((friendList->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
- return;
-
- JSONNODE *root = json_parse(response->pData), *node, *child;
-
- node = json_get(root, "friends");
- root = json_as_array(node);
- if (root != NULL)
- {
- for (size_t i = 0; i < json_size(root); i++)
- {
- child = json_at(root, i);
- if (child == NULL)
- break;
-
- FriendListItem *item = new FriendListItem();
-
- node = json_get(child, "steamid");
- item->steamId = ptrA(mir_u2a(json_as_string(node)));
-
- node = json_get(child, "relationship");
- ptrA relationship(mir_u2a(json_as_string(node)));
- if (!lstrcmpiA(relationship, "friend"))
- item->type = FRIEND_TYPE_FRIEND;
- else if (!lstrcmpiA(relationship, "ignoredfriend"))
- item->type = FRIEND_TYPE_IGNORED;
- else if (!lstrcmpiA(relationship, "requestrecipient"))
- item->type = FRIEND_TYPE_NONE;
- else
- {
- continue;
- }
-
- friendList->items
- .push_back(item);
- }
- }
-
- friendList->success = true;
- }
-
- static void AddFriend(HANDLE hConnection, const char *token, const char *sessionId, const char *steamId, const char *who, Result *result)
- {
- result->success = false;
-
- char login[MAX_PATH];
- mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
-
- char cookie[MAX_PATH];
- mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s;sessionid=%s;forceMobile=1", login, sessionId);
-
- char data[128];
- mir_snprintf(data, SIZEOF(data),
- "sessionID=%s&steamid=%s",
- sessionId,
- who);
-
- SecureHttpPostRequest request(hConnection, STEAM_COM_URL "/actions/AddFriendAjax");
- request.AddHeader("Cookie", cookie);
- request.SetData(data, strlen(data));
-
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response)
- return;
-
- JSONNODE *root = json_parse(response->pData), *node;
-
- //{"failed_invites":["xxxxxxxxxxxxxxxxx"], "failed_invites_result" : [41], "success" : 1}
- /*bool fail = false;
- node = json_get(root, "failed_invites_result");
- if (node)
- fail = true;*/
-
- node = json_get(root, "success");
-
- if ((result->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK || json_as_int(node) == 0/* || fail*/)
- return;
-
- result->success = true;
- }
-
- static void RemoveFriend(HANDLE hConnection, const char *token, const char *sessionId, const char *steamId, const char *who, Result *result)
- {
- result->success = false;
-
- char login[MAX_PATH];
- mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
-
- char cookie[MAX_PATH];
- mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s;sessionid=%s;forceMobile=1", login, sessionId);
-
- char data[128];
- mir_snprintf(data, SIZEOF(data),
- "sessionID=%s&steamid=%s",
- sessionId,
- who);
-
- SecureHttpPostRequest request(hConnection, STEAM_COM_URL "/actions/RemoveFriendAjax");
- request.AddHeader("Cookie", cookie);
- request.SetData(data, strlen(data));
-
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response)
- return;
-
- if ((result->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK || lstrcmpiA(response->pData, "true"))
- return;
-
- result->success = true;
- }
- };
-
class GetFriendListRequest : public HttpsGetRequest
{
public:
diff --git a/protocols/Steam/src/Steam/login.h b/protocols/Steam/src/Steam/login.h index c3ee1c5b17..7256251ec8 100644 --- a/protocols/Steam/src/Steam/login.h +++ b/protocols/Steam/src/Steam/login.h @@ -3,75 +3,6 @@ namespace SteamWebApi
{
- class LoginApi : public BaseApi
- {
- public:
- class LoginResult : public Result
- {
- friend LoginApi;
-
- private:
- std::string steamid;
- std::string umqid;
- UINT32 messageId;
-
- public:
-
- const char *GetSteamId() { return steamid.c_str(); }
- const char *GetUmqId() { return umqid.c_str(); }
- UINT32 GetMessageId() { return messageId; }
- };
-
- static void Logon(HANDLE hConnection, const char *token, LoginResult *loginResult)
- {
- loginResult->success = false;
-
- char data[256];
- mir_snprintf(data, SIZEOF(data), "access_token=%s", token);
-
- SecureHttpPostRequest request(hConnection, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Logon/v0001");
- request.SetData(data, strlen(data));
-
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response)
- return;
-
- if ((loginResult->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
- return;
-
- JSONNODE *root = json_parse(response->pData), *node;
-
- node = json_get(root, "error");
- ptrW error(json_as_string(node));
- if (lstrcmpi(error, L"OK"))
- return;
-
- node = json_get(root, "steamid");
- loginResult->steamid = ptrA(mir_u2a(json_as_string(node)));
-
- node = json_get(root, "umqid");
- loginResult->umqid = ptrA(mir_u2a(json_as_string(node)));
-
- node = json_get(root, "message");
- loginResult->messageId = json_as_int(node);
-
- loginResult->success = true;
- }
-
- static void Logoff(HANDLE hConnection, const char *token, const char *umqId)
- {
- CMStringA data;
- data.AppendFormat("access_token=%s", token);
- data.AppendFormat("&umqid=%s", umqId);
-
- SecureHttpPostRequest request(hConnection, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Logoff/v0001");
- request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
- request.SetData(data.GetBuffer(), data.GetLength());
-
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- }
- };
-
class LogonRequest : public HttpsPostRequest
{
public:
diff --git a/protocols/Steam/src/Steam/message.h b/protocols/Steam/src/Steam/message.h index 12284315bc..b75d2f7965 100644 --- a/protocols/Steam/src/Steam/message.h +++ b/protocols/Steam/src/Steam/message.h @@ -3,106 +3,106 @@ namespace SteamWebApi
{
- class MessageApi : public BaseApi
- {
- public:
- class SendResult : public Result
- {
- friend MessageApi;
+ //class MessageApi : public BaseApi
+ //{
+ //public:
+ // class SendResult : public Result
+ // {
+ // friend MessageApi;
- private:
- DWORD timestamp;
+ // private:
+ // DWORD timestamp;
- public:
- SendResult() : timestamp(0) { }
+ // public:
+ // SendResult() : timestamp(0) { }
- const DWORD GetTimestamp() const { return timestamp; }
- };
+ // const DWORD GetTimestamp() const { return timestamp; }
+ // };
- static void SendStatus(HANDLE hConnection, const char *token, const char *umqId, int state, SendResult *sendResult)
- {
- sendResult->success = false;
+ // static void SendStatus(HANDLE hConnection, const char *token, const char *umqId, int state, SendResult *sendResult)
+ // {
+ // sendResult->success = false;
- char data[256];
- mir_snprintf(data, SIZEOF(data),
- "access_token=%s&umqid=%s&type=personastate&persona_state=%i",
- token,
- umqId,
- state);
+ // char data[256];
+ // mir_snprintf(data, SIZEOF(data),
+ // "access_token=%s&umqid=%s&type=personastate&persona_state=%i",
+ // token,
+ // umqId,
+ // state);
- SecureHttpPostRequest request(hConnection, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Message/v0001");
- request.SetData(data, strlen(data));
+ // SecureHttpPostRequest request(hConnection, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Message/v0001");
+ // request.SetData(data, strlen(data));
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response)
- return;
+ // mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
+ // if (!response)
+ // return;
- if ((sendResult->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
- return;
+ // if ((sendResult->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
+ // return;
- sendResult->success = true;
- }
+ // sendResult->success = true;
+ // }
- static void SendMessage(HANDLE hConnection, const char *token, const char *umqId, const char *steamId, const char *text, SendResult *sendResult)
- {
- sendResult->success = false;
+ // static void SendMessage(HANDLE hConnection, const char *token, const char *umqId, const char *steamId, const char *text, SendResult *sendResult)
+ // {
+ // sendResult->success = false;
- char data[1024];
- mir_snprintf(data, SIZEOF(data),
- "access_token=%s&umqid=%s&steamid_dst=%s&type=saytext&text=%s",
- token,
- umqId,
- steamId,
- ptrA(mir_urlEncode(text)));
+ // char data[1024];
+ // mir_snprintf(data, SIZEOF(data),
+ // "access_token=%s&umqid=%s&steamid_dst=%s&type=saytext&text=%s",
+ // token,
+ // umqId,
+ // steamId,
+ // ptrA(mir_urlEncode(text)));
- SecureHttpPostRequest request(hConnection, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Message/v0001");
- request.SetData(data, strlen(data));
+ // SecureHttpPostRequest request(hConnection, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Message/v0001");
+ // request.SetData(data, strlen(data));
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response)
- return;
+ // mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
+ // if (!response)
+ // return;
- if ((sendResult->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
- return;
+ // if ((sendResult->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
+ // return;
- JSONNODE *root = json_parse(response->pData), *node;
+ // JSONNODE *root = json_parse(response->pData), *node;
- node = json_get(root, "error");
- ptrW error(json_as_string(node));
+ // node = json_get(root, "error");
+ // ptrW error(json_as_string(node));
- if (lstrcmp(error, L"OK"))
- return;
+ // if (lstrcmp(error, L"OK"))
+ // return;
- node = json_get(root, "utc_timestamp");
- sendResult->timestamp = atol(ptrA(mir_u2a(json_as_string(node))));
+ // node = json_get(root, "utc_timestamp");
+ // sendResult->timestamp = atol(ptrA(mir_u2a(json_as_string(node))));
- sendResult->success = true;
- }
+ // sendResult->success = true;
+ // }
- static void SendTyping(HANDLE hConnection, const char *token, const char *umqId, const char *steamId, SendResult *sendResult)
- {
- sendResult->success = false;
+ // static void SendTyping(HANDLE hConnection, const char *token, const char *umqId, const char *steamId, SendResult *sendResult)
+ // {
+ // sendResult->success = false;
- char data[256];
- mir_snprintf(data, SIZEOF(data),
- "access_token=%s&umqid=%s&steamid_dst=%s&type=typing",
- token,
- umqId,
- steamId);
+ // char data[256];
+ // mir_snprintf(data, SIZEOF(data),
+ // "access_token=%s&umqid=%s&steamid_dst=%s&type=typing",
+ // token,
+ // umqId,
+ // steamId);
- SecureHttpPostRequest request(hConnection, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Message/v0001");
- request.SetData(data, strlen(data));
+ // SecureHttpPostRequest request(hConnection, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Message/v0001");
+ // request.SetData(data, strlen(data));
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response)
- return;
+ // mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
+ // if (!response)
+ // return;
- if ((sendResult->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
- return;
+ // if ((sendResult->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
+ // return;
- sendResult->success = true;
- }
- };
+ // sendResult->success = true;
+ // }
+ //};
class SendMessageRequest : public HttpsPostRequest
{
diff --git a/protocols/Steam/src/Steam/pending.h b/protocols/Steam/src/Steam/pending.h index 639804fb44..5cdd85b885 100644 --- a/protocols/Steam/src/Steam/pending.h +++ b/protocols/Steam/src/Steam/pending.h @@ -3,13 +3,12 @@ namespace SteamWebApi
{
- class PendingApi : public BaseApi
+ class ApprovePendingRequest : public HttpsPostRequest
{
public:
- static void Accept(HANDLE hConnection, const char *token, const char *sessionId, const char *steamId, const char *who, Result *result)
+ ApprovePendingRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
+ HttpsPostRequest(STEAM_COM_URL "/profiles/%s/home_process")
{
- result->success = false;
-
char login[MAX_PATH];
mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
@@ -18,89 +17,20 @@ namespace SteamWebApi char url[MAX_PATH];
mir_snprintf(url, SIZEOF(url), STEAM_COM_URL "/profiles/%s/home_process", steamId);
+ this->url = url;
char data[MAX_PATH];
mir_snprintf(data, SIZEOF(data), "sessionID=%s&id=%s&perform=accept&action=approvePending&itype=friend&json=1&xml=0", sessionId, who);
- SecureHttpPostRequest request(hConnection, url);
- request.AddHeader("Cookie", cookie);
- request.SetData(data, strlen(data));
-
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response)
- return;
-
- //if ((result->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_FOUND)
- // return;
-
- result->success = true;
- }
-
- static void Ignore(HANDLE hConnection, const char *token, const char *sessionId, const char *steamId, const char *who, Result *result)
- {
- result->success = false;
-
- char login[MAX_PATH];
- mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
-
- char cookie[MAX_PATH];
- mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s;sessionid=%s;forceMobile=1", login, sessionId);
-
- char url[MAX_PATH];
- mir_snprintf(url, SIZEOF(url), STEAM_COM_URL "/profiles/%s/home_process", steamId);
-
- char data[MAX_PATH];
- mir_snprintf(data, SIZEOF(data), "sessionID=%s&id=%s&perform=ignore&action=approvePending&itype=friend&json=1&xml=0", sessionId, who);
-
- SecureHttpPostRequest request(hConnection, url);
- request.AddHeader("Cookie", cookie);
- request.SetData(data, strlen(data));
-
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response)
- return;
-
- if ((result->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
- return;
-
- result->success = true;
- }
-
- static void Block(HANDLE hConnection, const char *token, const char *sessionId, const char *steamId, const char *who, Result *result)
- {
- result->success = false;
-
- char login[MAX_PATH];
- mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
-
- char cookie[MAX_PATH];
- mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s;sessionid=%s;forceMobile=1", login, sessionId);
-
- char url[MAX_PATH];
- mir_snprintf(url, SIZEOF(url), STEAM_COM_URL "/profiles/%s/home_process", steamId);
-
- char data[MAX_PATH];
- mir_snprintf(data, SIZEOF(data), "sessionID=%s&id=%s&perform=block&action=approvePending&itype=friend&json=1&xml=0", sessionId, who);
-
- SecureHttpPostRequest request(hConnection, url);
- request.AddHeader("Cookie", cookie);
- request.SetData(data, strlen(data));
-
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response)
- return;
-
- if ((result->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
- return;
-
- result->success = true;
+ SetData(data, strlen(data));
+ AddHeader("Cookie", cookie);
}
};
- class ApprovePendingRequest : public HttpsPostRequest
+ class IgnorePendingRequest : public HttpsPostRequest
{
public:
- ApprovePendingRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
+ IgnorePendingRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
HttpsPostRequest(STEAM_COM_URL "/profiles/%s/home_process")
{
char login[MAX_PATH];
@@ -114,17 +44,17 @@ namespace SteamWebApi this->url = url;
char data[MAX_PATH];
- mir_snprintf(data, SIZEOF(data), "sessionID=%s&id=%s&perform=accept&action=approvePending&itype=friend&json=1&xml=0", sessionId, who);
+ mir_snprintf(data, SIZEOF(data), "sessionID=%s&id=%s&perform=ignore&action=approvePending&itype=friend&json=1&xml=0", sessionId, who);
SetData(data, strlen(data));
AddHeader("Cookie", cookie);
}
};
- class IgnorePendingRequest : public HttpsPostRequest
+ class BlockPendingRequest : public HttpsPostRequest
{
public:
- IgnorePendingRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
+ BlockPendingRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
HttpsPostRequest(STEAM_COM_URL "/profiles/%s/home_process")
{
char login[MAX_PATH];
@@ -138,7 +68,7 @@ namespace SteamWebApi this->url = url;
char data[MAX_PATH];
- mir_snprintf(data, SIZEOF(data), "sessionID=%s&id=%s&perform=ignore&action=approvePending&itype=friend&json=1&xml=0", sessionId, who);
+ mir_snprintf(data, SIZEOF(data), "sessionID=%s&id=%s&perform=block&action=approvePending&itype=friend&json=1&xml=0", sessionId, who);
SetData(data, strlen(data));
AddHeader("Cookie", cookie);
diff --git a/protocols/Steam/src/Steam/poll.h b/protocols/Steam/src/Steam/poll.h index 73597e81c4..7411ad85e6 100644 --- a/protocols/Steam/src/Steam/poll.h +++ b/protocols/Steam/src/Steam/poll.h @@ -3,230 +3,6 @@ namespace SteamWebApi
{
- class PollApi : public BaseApi
- {
- public:
- enum POOL_TYPE
- {
- POOL_TYPE_UNKNOWN,
- POOL_TYPE_MESSAGE,
- POOL_TYPE_MYMESSAGE,
- POOL_TYPE_TYPING,
- POOL_TYPE_STATE,
- POOL_TYPE_CONTACT_REQUEST,
- //POOL_TYPE_CONTACT_REQUESTED,
- POOL_TYPE_CONTACT_ADD,
- POOL_TYPE_CONTACT_IGNORE,
- POOL_TYPE_CONTACT_REMOVE,
- };
-
- class PoolItem// : public Result
- {
- friend PollApi;
-
- private:
- std::string steamId;
- DWORD timestamp;
- POOL_TYPE type;
-
- public:
- PoolItem() : timestamp(0), type(POOL_TYPE_UNKNOWN) { }
-
- const char *GetSteamId() const { return steamId.c_str(); }
- const DWORD GetTimestamp() const { return timestamp; }
- POOL_TYPE GetType() const { return type; }
- };
-
- class Typing : public PoolItem { friend PollApi; };
-
- class Message : public PoolItem
- {
- friend PollApi;
-
- private:
- std::wstring text;
-
- public:
- const wchar_t *GetText() const { return text.c_str(); }
- };
-
- class State : public PoolItem
- {
- friend PollApi;
-
- private:
- int status;
- std::wstring nickname;
-
- public:
- int GetStatus() const { return status; }
- const wchar_t *GetNickname() const { return nickname.c_str(); }
- };
-
- class Relationship : public PoolItem { friend PollApi; };
-
- class PollResult : public Result
- {
- friend PollApi;
-
- private:
- bool need_relogin;
- UINT32 messageId;
- std::vector<PoolItem*> items;
-
- public:
- PollResult() : messageId(0), need_relogin(false) { }
-
- UINT32 GetMessageId() const { return messageId; }
- bool IsNeedRelogin() const { return need_relogin; }
- size_t GetItemCount() const { return items.size(); }
- const PoolItem *GetAt(size_t idx) const { return items.at(idx); }
- };
-
- static void Poll(HANDLE hConnection, const char *token, const char *umqId, UINT32 messageId, PollResult *pollResult)
- {
- pollResult->success = false;
- pollResult->need_relogin = false;
- pollResult->items.clear();
-
- char data[256];
- mir_snprintf(data, SIZEOF(data), "access_token=%s&umqid=%s&message=%u", token, umqId, messageId);
-
- SecureHttpPostRequest request(hConnection, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Poll/v0001");
- request.SetData(data, strlen(data));
- request.SetTimeout(30000); // may need to encrease timeout
-
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response)
- return;
-
- if ((pollResult->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
- return;
-
- JSONNODE *root = json_parse(response->pData), *node, *child;
- node = json_get(root, "error");
- ptrW error(json_as_string(node));
-
- if (!lstrcmpi(error, L"Not Logged On"))
- {
- pollResult->need_relogin = true;
- //pollResult->success = true;
- return;
- }
- else if (!lstrcmpi(error, L"Timeout"))
- {
- pollResult->messageId = messageId;
- pollResult->success = true;
- return;
- }
- else if (lstrcmpi(error, L"OK"))
- return;
-
- node = json_get(root, "messagelast");
- pollResult->messageId = json_as_int(node);
-
- node = json_get(root, "messages");
- root = json_as_array(node);
- if (root != NULL)
- {
- for (size_t i = 0; i < json_size(root); i++)
- {
- child = json_at(root, i);
- if (child == NULL)
- break;
-
- PoolItem *item = NULL;
-
- node = json_get(child, "type");
- ptrW type(json_as_string(node));
- if (!lstrcmpi(type, L"saytext") || !lstrcmpi(type, L"emote") ||
- !lstrcmpi(type, L"my_saytext") || !lstrcmpi(type, L"my_emote"))
- {
- Message *message = new Message();
-
- if (_tcsstr(type, L"my_") == NULL)
- message->type = POOL_TYPE_MESSAGE;
- else
- message->type = POOL_TYPE_MYMESSAGE;
-
- node = json_get(child, "text");
- if (node != NULL) message->text = json_as_string(node);
-
- node = json_get(child, "utc_timestamp");
- message->timestamp = atol(ptrA(mir_u2a(json_as_string(node))));
-
- item = message;
- }
- else if(!lstrcmpi(type, L"typing"))
- {
- item = new Typing();
- item->type = POOL_TYPE_TYPING;
- }
- else if (!lstrcmpi(type, L"personastate"))
- {
- State *state = new State();
- state->type = POOL_TYPE_STATE;
-
- node = json_get(child, "persona_state");
- if (node != NULL) state->status = json_as_int(node);
-
- node = json_get(child, "persona_name");
- if (node != NULL) state->nickname = json_as_string(node);
-
- item = state;
- }
- else if (!lstrcmpi(type, L"personarelationship"))
- {
- Relationship *crs = new Relationship();
-
- node = json_get(child, "persona_state");
- int state = json_as_int(node);
- if (state == 0)
- {
- // removed
- crs->type = POOL_TYPE_CONTACT_REMOVE;
- }
-
- else if (state == 1)
- {
- // ignored
- crs->type = POOL_TYPE_CONTACT_IGNORE;
- }
- else if (state == 2)
- {
- // auth request
- crs->type = POOL_TYPE_CONTACT_REQUEST;
- }
- else if (state == 3)
- {
- // add to list
- crs->type = POOL_TYPE_CONTACT_ADD;
- }
- else continue;
- }
- /*else if (!lstrcmpi(type, L"leftconversation"))
- {
- }*/
- else
- {
- continue;
- }
-
- node = json_get(child, "steamid_from");
- item->steamId = ptrA(mir_u2a(json_as_string(node)));
-
- node = json_get(child, "utc_timestamp");
- item->timestamp = atol(ptrA(mir_u2a(json_as_string(node))));
-
- if (item != NULL)
- pollResult->items.push_back(item);
- }
- }
-
- pollResult->success = true;
- }
- };
-
class PollRequest : public HttpsPostRequest
{
public:
@@ -245,5 +21,4 @@ namespace SteamWebApi };
}
-
#endif //_STEAM_POLL_H_
\ No newline at end of file diff --git a/protocols/Steam/src/Steam/rsa_key.h b/protocols/Steam/src/Steam/rsa_key.h index 2ea9a20558..c4f9efc72d 100644 --- a/protocols/Steam/src/Steam/rsa_key.h +++ b/protocols/Steam/src/Steam/rsa_key.h @@ -3,60 +3,6 @@ namespace SteamWebApi
{
- class RsaKeyApi : public BaseApi
- {
- public:
-
- class RsaKey : public Result
- {
- friend RsaKeyApi;
-
- private:
- std::string modulus;
- std::string exponent;
- std::string timestamp;
-
- public:
- const char * GetModulus() const { return modulus.c_str(); }
- const char * GetExponent() const { return exponent.c_str(); }
- const char * GetTimestamp() const { return timestamp.c_str(); }
- };
-
- static void GetRsaKey(HANDLE hConnection, const wchar_t *username, RsaKey *rsaKey)
- {
- rsaKey->success = false;
-
- ptrA base64Username(mir_urlEncode(ptrA(mir_utf8encodeW(username))));
-
- SecureHttpGetRequest request(hConnection, STEAM_COM_URL "/mobilelogin/getrsakey");
- request.AddParameter("username", (char*)base64Username);
-
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response)
- return;
-
- if ((rsaKey->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
- return;
-
- JSONNODE *root = json_parse(response->pData), *node;
- if (!root) return;
-
- node = json_get(root, "success");
- if (!json_as_bool(node)) return;
-
- node = json_get(root, "publickey_mod");
- rsaKey->modulus = ptrA(mir_u2a(json_as_string(node)));
-
- node = json_get(root, "publickey_exp");
- rsaKey->exponent = ptrA(mir_u2a(json_as_string(node)));
-
- node = json_get(root, "timestamp");
- rsaKey->timestamp = ptrA(mir_u2a(json_as_string(node)));
-
- rsaKey->success = true;
- }
- };
-
class RsaKeyRequest : public HttpsGetRequest
{
public:
diff --git a/protocols/Steam/src/Steam/search.h b/protocols/Steam/src/Steam/search.h index ff85f5960f..4cdd4179e0 100644 --- a/protocols/Steam/src/Steam/search.h +++ b/protocols/Steam/src/Steam/search.h @@ -3,95 +3,6 @@ namespace SteamWebApi
{
- class SearchApi : public BaseApi
- {
- public:
-
- class SearchItem// : public Result
- {
- friend SearchApi;
-
- private:
- std::string steamId;
-
- public:
- const char *GetSteamId() const { return steamId.c_str(); }
- };
-
- class SearchResult : public Result
- {
- friend SearchApi;
-
- private:
- int count;
- std::vector<SearchItem*> items;
-
- public:
- SearchResult() : count(0) { }
-
- int GetItemCount() { return count; }
- const SearchItem *GetAt(int idx) const { return items.at(idx); }
- };
-
- static void Search(HANDLE hConnection, const char *token, const char *text, SearchResult *searchResult)
- {
- searchResult->success = false;
- searchResult->count = 0;
- searchResult->items.clear();
-
- // todo: may need to load all results
- // 15 first at now
- SecureHttpGetRequest request(hConnection, STEAM_API_URL "/ISteamUserOAuth/Search/v0001");
- request.AddParameter("access_token", token);
- request.AddParameter("keywords", ptrA(mir_urlEncode(text)));
- request.AddParameter("offset=0&count=15&targets=users&fields=all");
-
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response)
- return;
-
- if ((searchResult->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK)
- return;
-
- JSONNODE *root = json_parse(response->pData), *node, *child;
-
- node = json_get(root, "success");
- searchResult->success = json_as_bool(node) > 0;
- if (!searchResult->success)
- return;
-
- node = json_get(root, "count");
- searchResult->count = json_as_int(node);
-
- //node = json_get(root, "total");
- //searchResult->total = json_as_int(node);
-
- if (searchResult->count == 0)
- return;
-
- node = json_get(root, "results");
- root = json_as_array(node);
- if (root != NULL)
- {
- for (size_t i = 0; i < json_size(root); i++)
- {
- child = json_at(root, i);
- if (child == NULL)
- break;
-
- SearchItem *item = new SearchItem();
-
- node = json_get(child, "steamid");
- item->steamId = ptrA(mir_u2a(json_as_string(node)));
-
- searchResult->items.push_back(item);
- }
- }
-
- searchResult->success = true;
- }
- };
-
class SearchRequest : public HttpsGetRequest
{
public:
diff --git a/protocols/Steam/src/Steam/session.h b/protocols/Steam/src/Steam/session.h index 3ddcc219cd..a5fd950e1d 100644 --- a/protocols/Steam/src/Steam/session.h +++ b/protocols/Steam/src/Steam/session.h @@ -3,53 +3,53 @@ namespace SteamWebApi
{
- class SessionApi : public BaseApi
- {
- public:
- class SessionId : public Result
- {
- friend SessionApi;
+ //class SessionApi : public BaseApi
+ //{
+ //public:
+ // class SessionId : public Result
+ // {
+ // friend SessionApi;
- private:
- std::string sessionid;
+ // private:
+ // std::string sessionid;
- public:
+ // public:
- const char *GetSessionId() { return sessionid.c_str(); }
- };
+ // const char *GetSessionId() { return sessionid.c_str(); }
+ // };
- static void GetSessionId(HANDLE hConnection, const char *token, const char *steamId, SessionId *sessionId)
- {
- sessionId->success = false;
+ // static void GetSessionId(HANDLE hConnection, const char *token, const char *steamId, SessionId *sessionId)
+ // {
+ // sessionId->success = false;
- char login[MAX_PATH];
- mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
+ // char login[MAX_PATH];
+ // mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
- char cookie[MAX_PATH];
- mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s", ptrA(mir_urlEncode(login)));
+ // char cookie[MAX_PATH];
+ // mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s", ptrA(mir_urlEncode(login)));
- SecureHttpGetRequest request(hConnection, STEAM_COM_URL "/mobilesettings/GetManifest/v0001");
- request.AddHeader("Cookie", cookie);
+ // SecureHttpGetRequest request(hConnection, STEAM_COM_URL "/mobilesettings/GetManifest/v0001");
+ // request.AddHeader("Cookie", cookie);
- mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
- if (!response)
- return;
+ // mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
+ // if (!response)
+ // return;
- for (int i = 0; i < response->headersCount; i++)
- {
- if (lstrcmpiA(response->headers[i].szName, "Set-Cookie"))
- continue;
+ // 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(';');
- sessionId->sessionid = cookies.substr(start, end - start + 10);
- break;
- }
+ // std::string cookies = response->headers[i].szValue;
+ // size_t start = cookies.find("sessionid=") + 10;
+ // size_t end = cookies.substr(start).find(';');
+ // sessionId->sessionid = cookies.substr(start, end - start + 10);
+ // break;
+ // }
- sessionId->success = true;
- }
- };
+ // sessionId->success = true;
+ // }
+ //};
class GetSessionRequest : public HttpsPostRequest
{
diff --git a/protocols/Steam/src/Steam/steam.h b/protocols/Steam/src/Steam/steam.h index df039288a5..a30ea6b4e6 100644 --- a/protocols/Steam/src/Steam/steam.h +++ b/protocols/Steam/src/Steam/steam.h @@ -6,29 +6,6 @@ namespace SteamWebApi #define STEAM_API_URL "https://api.steampowered.com"
#define STEAM_COM_URL "https://steamcommunity.com"
- class FriendListApi;
- class PendingApi;
-
- class BaseApi
- {
- public:
- class Result
- {
- friend FriendListApi;
- friend PendingApi;
-
- protected:
- bool success;
- HTTP_STATUS status;
-
- public:
- Result() : success(false), status(HTTP_STATUS_NONE) { }
-
- bool IsSuccess() const { return success; }
- HTTP_STATUS GetStatus() const { return status; }
- };
- };
-
class HttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject
{
public:
diff --git a/protocols/Steam/src/common.h b/protocols/Steam/src/common.h index 4069d9e897..afef19c6f0 100644 --- a/protocols/Steam/src/common.h +++ b/protocols/Steam/src/common.h @@ -36,8 +36,6 @@ class CSteamProto;
extern HINSTANCE g_hInstance;
-#include "http_request.h"
-
#include "Steam\steam.h"
#include "steam_proto.h"
diff --git a/protocols/Steam/src/steam_account.cpp b/protocols/Steam/src/steam_account.cpp index 59915ddeac..3db721db27 100644 --- a/protocols/Steam/src/steam_account.cpp +++ b/protocols/Steam/src/steam_account.cpp @@ -202,205 +202,4 @@ void CSteamProto::OnLoggedOn(const NETLIBHTTPREQUEST *response, void *arg) // go to online now
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus = m_iDesiredStatus);
-}
-
-void CSteamProto::SetServerStatusThread(void *arg)
-{
- WORD status = *((WORD*)&arg);
-
- ptrA token(getStringA("TokenSecret"));
- ptrA umqId(getStringA("UMQID"));
-
- int state = CSteamProto::MirandaToSteamState(status);
-
- // change status
- WORD oldStatus = m_iStatus;
- m_iDesiredStatus = status;
-
- SteamWebApi::MessageApi::SendResult sendResult;
- debugLogA("CSteamProto::SetServerStatusThread: call SteamWebApi::MessageApi::SendStatus");
- SteamWebApi::MessageApi::SendStatus(m_hNetlibUser, token, umqId, state, &sendResult);
-
- if (sendResult.IsSuccess())
- {
- m_iStatus = status;
- ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
- }
- else
- m_iDesiredStatus = m_iStatus;
-}
-
-void CSteamProto::SetServerStatus(WORD status)
-{
- if (m_iStatus == status)
- return;
-
- ForkThread(&CSteamProto::SetServerStatusThread, (void*)status);
-}
-
-void CSteamProto::Authorize(SteamWebApi::AuthorizationApi::AuthResult *authResult)
-{
- ptrW username(getWStringA("Username"));
- ptrA base64RsaEncryptedPassword;
-
- const wchar_t *nickname = getWStringA("Nick");
- if (lstrlen(nickname) == 0 && username)
- setWString("Nick", username);
-
- // get rsa public key
- SteamWebApi::RsaKeyApi::RsaKey rsaKey;
- debugLogA("CSteamProto::Authorize: call SteamWebApi::RsaKeyApi::GetRsaKey");
- SteamWebApi::RsaKeyApi::GetRsaKey(m_hNetlibUser, username, &rsaKey);
- if (!rsaKey.IsSuccess())
- return;
-
- ptrA password(getStringA("Password"));
-
- /*DWORD error = 0;
- DWORD encryptedSize = 0;
- DWORD passwordSize = (DWORD)strlen(password);
- if ((error = RsaEncrypt(rsaKey, password, passwordSize, NULL, encryptedSize)) != 0)
- {
- debugLogA("CSteamProto::Authorize: encryption error (%lu)", error);
- return;
- }
-
- BYTE *encryptedPassword = (BYTE*)mir_calloc(encryptedSize);
- if ((error = RsaEncrypt(rsaKey, password, passwordSize, encryptedPassword, encryptedSize)) != 0)
- {
- debugLogA("CSteamProto::Authorize: encryption error (%lu)", error);
- return;
- }
-
- base64RsaEncryptedPassword = mir_base64_encode(encryptedPassword, encryptedSize);
- mir_free(encryptedPassword);*/
-
- // try to authorize
- debugLogA("CSteamProto::Authorize: call SteamWebApi::AuthorizationApi::Authorize");
- SteamWebApi::AuthorizationApi::Authorize(m_hNetlibUser, username, base64RsaEncryptedPassword, rsaKey.GetTimestamp(), authResult);
- if (authResult->IsEmailAuthNeeded() || authResult->IsCaptchaNeeded())
- {
- do
- {
- if (authResult->IsEmailAuthNeeded())
- {
- GuardParam guard;
-
- lstrcpyA(guard.domain, authResult->GetEmailDomain());
-
- if (DialogBoxParam(
- g_hInstance,
- MAKEINTRESOURCE(IDD_GUARD),
- NULL,
- CSteamProto::GuardProc,
- (LPARAM)&guard) != 1)
- break;
-
- authResult->SetAuthCode(guard.code);
- }
-
- if (authResult->IsCaptchaNeeded())
- {
- // todo: show captcha dialog
- }
-
- // try to authorize with emailauthcode or captcha taxt
- debugLogA("CSteamProto::Authorize: call SteamWebApi::AuthorizationApi::Authorize");
- SteamWebApi::AuthorizationApi::Authorize(m_hNetlibUser, username, base64RsaEncryptedPassword, rsaKey.GetTimestamp(), authResult);
- } while (authResult->IsEmailAuthNeeded() || authResult->IsCaptchaNeeded());
- }
-}
-
-void CSteamProto::LogInThread(void* param)
-{
- while (isTerminated || m_hPollingThread != NULL)
- Sleep(500);
-
- ptrA token(getStringA("TokenSecret"));
- if (!token || lstrlenA(token) == 0)
- {
- SteamWebApi::AuthorizationApi::AuthResult authResult;
- Authorize(&authResult);
- // if some error
- if (!authResult.IsSuccess())
- {
- // todo: display error message from authResult.GetMessage()
- //ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_BADUSERID);
- debugLogA("CSteamProto::LogInThread: Authorization error (%s)", authResult.GetMessage());
-
- m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
- ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, ID_STATUS_OFFLINE);
- return;
- }
-
- token = mir_strdup(authResult.GetToken());
-
- setString("TokenSecret", token);
- //setString("Cookie", authResult.GetCookie());
- setString("SteamID", authResult.GetSteamid());
- setString("SessionID", authResult.GetSessionId());
- }
-
- SteamWebApi::LoginApi::LoginResult loginResult;
- debugLogA("CSteamProto::LogInThread: call SteamWebApi::LoginApi::Logon");
- SteamWebApi::LoginApi::Logon(m_hNetlibUser, token, &loginResult);
-
- // if some error
- if (!loginResult.IsSuccess())
- {
- debugLogA("CSteamProto::LogInThread: Login error (%d)", loginResult.GetStatus());
-
- // token has expired
- if (loginResult.GetStatus() == HTTP_STATUS_UNAUTHORIZED)
- {
- delSetting("TokenSecret");
- //delSetting("Cookie");
- }
-
- // 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;
- }
-
- setString("UMQID", loginResult.GetUmqId());
- setDword("MessageID", loginResult.GetMessageId());
-
- // set selected status
- ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus = m_iDesiredStatus);
-
- /*ptrA sessionId(getStringA("SessionID"));
- if (!sessionId || lstrlenA(sessionId) == 0)
- {
- SteamWebApi::SessionApi::SessionId result;
- debugLogA("CSteamProto::LogInThread: call SteamWebApi::SessionApi::GetSessionId");
- SteamWebApi::SessionApi::GetSessionId(m_hNetlibUser, token, loginResult.GetSteamId(), &result);
- if (result.IsSuccess())
- setString("SessionID", result.GetSessionId());
- }*/
-
- // load contact list
- LoadContactListThread(NULL);
-
- // start pooling thread
- if (m_hPollingThread == NULL)
- {
- isTerminated = false;
- m_hPollingThread = ForkThreadEx(&CSteamProto::PollingThread, NULL, NULL);
- }
-}
-
-void CSteamProto::LogOutThread(void*)
-{
- ptrA token(getStringA("TokenSecret"));
- ptrA umqId(getStringA("UMQID"));
-
- while (!Miranda_Terminated() && isTerminated && m_hPollingThread != NULL)
- Sleep(200);
-
- debugLogA("CSteamProto::LogOutThread: call SteamWebApi::LoginApi::Logoff");
- SteamWebApi::LoginApi::Logoff(m_hNetlibUser, token, umqId);
-
- delSetting("UMQID");
- isTerminated = false;
}
\ No newline at end of file diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index b3449088f5..9713f3d1cf 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -55,132 +55,6 @@ MCONTACT CSteamProto::FindContact(const char *steamId) return hContact;
}
-void CSteamProto::UpdateContact(MCONTACT hContact, const SteamWebApi::FriendApi::Summary *summary)
-{
- // only if contact is in contact list
- if (hContact && !FindContact(summary->GetSteamId()))
- return;
-
- // set common data
- setWString(hContact, "Nick", summary->GetNickName());
- setString(hContact, "Homepage", summary->GetHomepage());
- // only for contacts
- if (hContact)
- {
- setDword(hContact, "LastEventDateTS", summary->GetLastEvent());
-
- DWORD gameId = summary->GetGameId();
- if (gameId >0)
- {
- setWord(hContact, "Status", ID_STATUS_OUTTOLUNCH);
- db_set_ws(hContact, "CList", "StatusMsg", summary->GetGameInfo());
-
- setWString(hContact, "GameInfo", summary->GetGameInfo());
- setDword(hContact, "GameID", summary->GetGameId());
- }
- else
- {
- WORD status = SteamToMirandaStatus(summary->GetState());
- setWord(hContact, "Status", status);
-
- db_unset(hContact, "CList", "StatusMsg");
- delSetting(hContact, "GameID");
- }
- }
-
- // set name
- const wchar_t *firstName = summary->GetFirstName();
- const wchar_t *lastName = summary->GetLastName();
- if (lstrlen(firstName) == 0)
- {
- delSetting(hContact, "FirstName");
- delSetting(hContact, "LastName");
- }
- else if (lstrlen(lastName) == 0)
- {
- setWString(hContact, "FirstName", firstName);
- delSetting(hContact, "LastName");
- }
- else
- {
- setWString(hContact, "FirstName", firstName);
- setWString(hContact, "LastName", lastName);
- }
-
- // avatar
- ptrA oldAvatar(getStringA("AvatarUrl"));
- if (lstrcmpiA(oldAvatar, summary->GetAvatarUrl()))
- {
- // todo: need to place in thread
- SteamWebApi::AvatarApi::Avatar avatar;
- debugLogA("CSteamProto::UpdateContact: SteamWebApi::AvatarApi::GetAvatar");
- SteamWebApi::AvatarApi::GetAvatar(m_hNetlibUser, summary->GetAvatarUrl(), &avatar);
-
- if (avatar.IsSuccess() && avatar.GetDataSize() > 0)
- {
- ptrW avatarPath(GetAvatarFilePath(hContact));
- FILE *fp = _wfopen(avatarPath, L"wb");
- if (fp)
- {
- fwrite(avatar.GetData(), sizeof(char), avatar.GetDataSize(), fp);
- fclose(fp);
-
- PROTO_AVATAR_INFORMATIONW pai = { sizeof(pai) };
- pai.format = PA_FORMAT_JPEG;
- pai.hContact = hContact;
- wcscpy(pai.filename, avatarPath);
-
- ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, 0);
-
- setString("AvatarUrl", summary->GetAvatarUrl());
- }
- }
- }
-
- // set country
- const char *isoCode = summary->GetCountryCode();
- if (!lstrlenA(isoCode))
- this->delSetting(hContact, "Country");
- else
- {
- // todo: is should be free()?
- char *country = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isoCode, 0);
- setString(hContact, "Country", country);
- }
-}
-
-void CSteamProto::UpdateContactsThread(void *arg)
-{
- ptrA steamIds((char*)arg);
-
- ptrA token(getStringA("TokenSecret"));
-
- SteamWebApi::FriendApi::Summaries summarues;
- debugLogA("CSteamProto::UpdateContactsThread: call SteamWebApi::FriendApi::LoadSummaries");
- SteamWebApi::FriendApi::LoadSummaries(m_hNetlibUser, token, steamIds, &summarues);
-
- if (!summarues.IsSuccess())
- return;
-
- for (size_t i = 0; i < summarues.GetItemCount(); i++)
- {
- const SteamWebApi::FriendApi::Summary *contact = summarues.GetAt(i);
-
- MCONTACT hContact = NULL;
- if (!IsMe(contact->GetSteamId()))
- {
- const char *steamId = contact->GetSteamId();
- hContact = this->FindContact(steamId);
- if (hContact == NULL)
- hContact = AddContact(steamId);
- if (hContact == NULL)
- return;
- }
-
- UpdateContact(hContact, contact);
- }
-}
-
void CSteamProto::UpdateContact(MCONTACT hContact, JSONNODE *data)
{
JSONNODE *node = NULL;
@@ -221,42 +95,15 @@ void CSteamProto::UpdateContact(MCONTACT hContact, JSONNODE *data) delSetting(hContact, "LastName");
}
- //// avatar
-
- //node = json_get(data, "avatarfull");
- //item->avatarUrl = ptrA(mir_u2a(json_as_string(node)));
-
- //ptrA oldAvatar(getStringA("AvatarUrl"));
- //if (lstrcmpiA(oldAvatar, summary->GetAvatarUrl()))
- //{
- // // todo: need to place in thread
- // SteamWebApi::AvatarApi::Avatar avatar;
- // debugLogA("CSteamProto::UpdateContact: SteamWebApi::AvatarApi::GetAvatar");
- // SteamWebApi::AvatarApi::GetAvatar(m_hNetlibUser, summary->GetAvatarUrl(), &avatar);
-
- // if (avatar.IsSuccess() && avatar.GetDataSize() > 0)
- // {
- // ptrW avatarPath(GetAvatarFilePath(hContact));
- // FILE *fp = _wfopen(avatarPath, L"wb");
- // if (fp)
- // {
- // fwrite(avatar.GetData(), sizeof(char), avatar.GetDataSize(), fp);
- // fclose(fp);
-
- // PROTO_AVATAR_INFORMATIONW pai = { sizeof(pai) };
- // pai.format = PA_FORMAT_JPEG;
- // pai.hContact = hContact;
- // wcscpy(pai.filename, avatarPath);
-
- // ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, 0);
-
- // setString("AvatarUrl", summary->GetAvatarUrl());
- // }
- // }
- //}
-
- /*node = json_get(data, "timecreated");
- time_t created = json_as_int(node);*/
+ // avatar
+ node = json_get(data, "avatarfull");
+ ptrA avatarUrl(mir_u2a(json_as_string(node)));
+ setString("AvatarUrl", avatarUrl);
+
+ PushRequest(
+ new SteamWebApi::GetAvatarRequest(avatarUrl),
+ &CSteamProto::OnGotAvatar,
+ (void*)hContact);
// set country
node = json_get(data, "loccountrycode");
@@ -375,7 +222,7 @@ void CSteamProto::OnGotFriendList(const NETLIBHTTPREQUEST *response, void *arg) if (!hContact)
hContact = AddContact(steamId, true);
- RaiseAuthRequestThread((void*)hContact);
+ //RaiseAuthRequestThread((void*)hContact);
}
else continue;
}
@@ -418,6 +265,32 @@ void CSteamProto::OnGotUserSummaries(const NETLIBHTTPREQUEST *response, void *ar }
}
+void CSteamProto::OnGotAvatar(const NETLIBHTTPREQUEST *response, void *arg)
+{
+ MCONTACT hContact = (MCONTACT)arg;
+
+ if (response == NULL || response->resultCode != HTTP_STATUS_OK)
+ {
+ ptrA steamId(getStringA(hContact, "SteamID"));
+ debugLogA("CSteamProto::OnGotAvatar: failed to get avatar %s", steamId);
+ }
+
+ ptrW avatarPath(GetAvatarFilePath(hContact));
+ FILE *fp = _wfopen(avatarPath, L"wb");
+ if (fp)
+ {
+ fwrite(response->pData, sizeof(char), response->dataLength, fp);
+ fclose(fp);
+
+ PROTO_AVATAR_INFORMATIONW pai = { sizeof(pai) };
+ pai.format = PA_FORMAT_JPEG;
+ pai.hContact = hContact;
+ wcscpy(pai.filename, avatarPath);
+
+ ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, 0);
+ }
+}
+
void CSteamProto::OnFriendAdded(const NETLIBHTTPREQUEST *response, void *arg)
{
SendAuthParam *param = (SendAuthParam*)arg;
@@ -592,302 +465,60 @@ void CSteamProto::OnSearchByNameStarted(const NETLIBHTTPREQUEST *response, void {
}
-void CSteamProto::RaiseAuthRequestThread(void *arg)
-{
- MCONTACT hContact = (MCONTACT)arg;
- if (!hContact)
- debugLogA("CSteamProto::RaiseAuthRequestThread: error (contact is NULL)");
-
- ptrA token(getStringA("TokenSecret"));
- ptrA steamId(getStringA(hContact, "SteamID"));
-
- //setByte(hContact, "Auth", 1);
- setByte(hContact, "Grant", 1);
-
- SteamWebApi::FriendApi::Summaries summaries;
- debugLogA("CSteamProto::RaiseAuthRequestThread: call SteamWebApi::FriendApi::LoadSummaries");
- SteamWebApi::FriendApi::LoadSummaries(m_hNetlibUser, token, steamId, &summaries);
-
- if (summaries.IsSuccess())
- {
- const SteamWebApi::FriendApi::Summary *summary = summaries.GetAt(0);
-
- UpdateContact(hContact, summary);
-
- char *nickName = mir_utf8encodeW(summary->GetNickName());
- char *firstName = mir_utf8encodeW(summary->GetFirstName());
- char *lastName = mir_utf8encodeW(summary->GetLastName());
- char reason[MAX_PATH];
- mir_snprintf(reason, SIZEOF(reason), Translate("%s has added you to his or her Friend List"), nickName);
-
- // blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), firstName(ASCIIZ), lastName(ASCIIZ), sid(ASCIIZ), reason(ASCIIZ)
- DWORD cbBlob = (DWORD)(sizeof(DWORD)* 2 + strlen(nickName) + strlen(firstName) + strlen(lastName) + strlen(steamId) + strlen(reason) + 5);
-
- PBYTE pBlob, pCurBlob;
- pCurBlob = pBlob = (PBYTE)mir_alloc(cbBlob);
-
- *((PDWORD)pCurBlob) = 0;
- pCurBlob += sizeof(DWORD);
- *((PDWORD)pCurBlob) = (DWORD)hContact;
- pCurBlob += sizeof(DWORD);
- strcpy((char*)pCurBlob, nickName);
- pCurBlob += strlen(nickName) + 1;
- strcpy((char*)pCurBlob, firstName);
- pCurBlob += strlen(firstName) + 1;
- strcpy((char*)pCurBlob, lastName);
- pCurBlob += strlen(lastName) + 1;
- strcpy((char*)pCurBlob, steamId);
- pCurBlob += strlen(steamId) + 1;
- strcpy((char*)pCurBlob, mir_strdup(reason));
-
- AddDBEvent(hContact, EVENTTYPE_AUTHREQUEST, time(NULL), DBEF_UTF, cbBlob, pBlob);
- }
-}
-
-void CSteamProto::AuthAllowThread(void *arg)
-{
- MCONTACT hContact = (MCONTACT)arg;
- if (!hContact)
- return;
-
- ptrA token(getStringA("TokenSecret"));
- ptrA sessionId(getStringA("SessionID"));
- ptrA steamId(getStringA("SteamID"));
- ptrA who(getStringA(hContact, "SteamID"));
-
- SteamWebApi::PendingApi::Result result;
- debugLogA("CSteamProto::AuthAllowThread: call SteamWebApi::PendingApi::Accept");
- SteamWebApi::PendingApi::Accept(m_hNetlibUser, token, sessionId, steamId, who, &result);
-
- if (result.IsSuccess())
- {
- delSetting(hContact, "Auth");
- delSetting(hContact, "Grant");
- db_unset(hContact, "CList", "NotOnList");
-
- /*SteamWebApi::FriendApi::Summaries summaries;
- debugLogA("CSteamProto::AuthAllowThread: call SteamWebApi::FriendApi::LoadSummaries");
- SteamWebApi::FriendApi::LoadSummaries(m_hNetlibUser, token, who, &summaries);
-
- if (summaries.IsSuccess())
- {
- UpdateContact(hContact, summaries.GetAt(0));
- }*/
- }
-}
-
-void CSteamProto::AuthDenyThread(void *arg)
-{
- MCONTACT hContact = (MCONTACT)arg;
- if (!hContact)
- return;
-
- ptrA token(getStringA("TokenSecret"));
- ptrA sessionId(getStringA("SessionID"));
- ptrA steamId(getStringA("SteamID"));
- ptrA who(getStringA(hContact, "SteamID"));
-
- SteamWebApi::PendingApi::Result result;
- debugLogA("CSteamProto::AuthDenyThread: call SteamWebApi::PendingApi::Ignore");
- SteamWebApi::PendingApi::Ignore(m_hNetlibUser, token, sessionId, steamId, who, &result);
-}
-
-void CSteamProto::AddContactThread(void *arg)
-{
- SendAuthParam *param = (SendAuthParam*)arg;
-
- MCONTACT hContact = param->hContact;
- if (!hContact)
- return;
-
- ptrA token(getStringA("TokenSecret"));
- ptrA sessionId(getStringA("SessionID"));
- ptrA steamId(getStringA("SteamID"));
- ptrA who(getStringA(hContact, "SteamID"));
-
- //db_unset(hContact, "CList", "NotOnList");
-
- SteamWebApi::FriendListApi::Result result;
- debugLogA("CSteamProto::AddContactThread: call SteamWebApi::FriendListApi::AddFriend");
- SteamWebApi::FriendListApi::AddFriend(m_hNetlibUser, token, sessionId, steamId, who, &result);
-
- if (result.IsSuccess())
- {
- delSetting(hContact, "Auth");
- delSetting(hContact, "Grant");
- db_unset(hContact, "CList", "NotOnList");
- }
-
- ProtoBroadcastAck(hContact, ACKTYPE_AUTHREQ, result.IsSuccess() ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, param->hAuth, 0);
-
- mir_free(param);
-}
-
-void CSteamProto::RemoveContactThread(void *arg)
-{
- if (!arg)
- return;
-
- ptrA token(getStringA("TokenSecret"));
- ptrA sessionId(getStringA("SessionID"));
- ptrA steamId(getStringA("SteamID"));
- ptrA who((char*)arg);
-
- SteamWebApi::FriendListApi::Result result;
- debugLogA("CSteamProto::RemoveContactThread: call SteamWebApi::FriendListApi::RemoveFriend");
- SteamWebApi::FriendListApi::RemoveFriend(m_hNetlibUser, token, sessionId, steamId, who, &result);
-}
-
-void CSteamProto::LoadContactListThread(void*)
-{
- ptrA token(getStringA("TokenSecret"));
- ptrA steamId(getStringA("SteamID"));
-
- SteamWebApi::FriendListApi::FriendList friendList;
- debugLogA("CSteamProto::LoadContactListThread: call SteamWebApi::FriendListApi::Load");
- SteamWebApi::FriendListApi::Load(m_hNetlibUser, token, steamId, &friendList);
-
- if (friendList.IsSuccess())
- {
- CMStringA newContacts;
- for (size_t i = 0; i < friendList.GetItemCount(); i++)
- {
- const SteamWebApi::FriendListApi::FriendListItem *item = friendList.GetAt(i);
-
- const char *steamId = item->GetSteamId();
- SteamWebApi::FriendListApi::FRIEND_TYPE type = item->GetType();
-
- if (type == SteamWebApi::FriendListApi::FRIEND_TYPE_FRIEND)
- {
- if (!FindContact(steamId))
- {
- if (newContacts.IsEmpty())
- newContacts.Append(steamId);
- else
- newContacts.AppendFormat(",%s", steamId);
- }
- }
- else if (type == SteamWebApi::FriendListApi::FRIEND_TYPE_NONE)
- {
- MCONTACT hContact = FindContact(steamId);
- if (!hContact)
- hContact = AddContact(steamId, true);
-
- RaiseAuthRequestThread((void*)hContact);
- }
- }
-
- if (!newContacts.IsEmpty())
- {
- SteamWebApi::FriendApi::Summaries summaries;
- debugLogA("CSteamProto::LoadContactListThread: call SteamWebApi::FriendApi::LoadSummaries");
- SteamWebApi::FriendApi::LoadSummaries(m_hNetlibUser, token, newContacts, &summaries);
-
- if (summaries.IsSuccess())
- {
- for (size_t i = 0; i < summaries.GetItemCount(); i++)
- {
- const SteamWebApi::FriendApi::Summary *summary = summaries.GetAt(i);
- MCONTACT hContact = AddContact(summary->GetSteamId());
- if (hContact)
- UpdateContact(hContact, summary);
- }
- }
- }
- }
-}
-
-void CSteamProto::SearchByIdThread(void* arg)
-{
- ptrW steamIdW((wchar_t*)arg);
- ptrA steamId(mir_u2a(steamIdW));
-
- ptrA token(getStringA("TokenSecret"));
-
- SteamWebApi::FriendApi::Summaries summarues;
- debugLogA("CSteamProto::SearchByIdThread: call SteamWebApi::FriendApi::LoadSummaries");
- SteamWebApi::FriendApi::LoadSummaries(m_hNetlibUser, token, steamId, &summarues);
-
- if (!summarues.IsSuccess())
- {
- ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)STEAM_SEARCH_BYID, 0);
- return;
- }
-
- if (summarues.GetItemCount() == 0)
- return;
-
- const SteamWebApi::FriendApi::Summary *contact = summarues.GetAt(0);
-
- STEAM_SEARCH_RESULT ssr = { 0 };
- ssr.hdr.cbSize = sizeof(STEAM_SEARCH_RESULT);
- ssr.hdr.flags = PSR_TCHAR;
-
- ssr.hdr.id = mir_wstrdup(steamIdW);
- ssr.hdr.nick = mir_wstrdup(contact->GetNickName());
- ssr.hdr.firstName = mir_wstrdup(contact->GetFirstName());
- ssr.hdr.lastName = mir_wstrdup(contact->GetLastName());
-
- ssr.contact = contact;
-
- ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)STEAM_SEARCH_BYID, (LPARAM)&ssr);
- ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)STEAM_SEARCH_BYID, 0);
-}
-
-void CSteamProto::SearchByNameThread(void* arg)
-{
- ptrW keywordsW((wchar_t*)arg);
- ptrA keywords(mir_utf8encodeW(keywordsW));
-
- ptrA token(getStringA("TokenSecret"));
-
- SteamWebApi::SearchApi::SearchResult searchResult;
- debugLogA("CSteamProto::SearchByNameThread: call SteamWebApi::SearchApi::Search");
- SteamWebApi::SearchApi::Search(m_hNetlibUser, token, keywords, &searchResult);
-
- if (!searchResult.IsSuccess())
- {
- ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)STEAM_SEARCH_BYNAME, 0);
- return;
- }
-
- CMStringA steamIds;
- for (int i = 0; i < searchResult.GetItemCount(); i++)
- {
- const SteamWebApi::SearchApi::SearchItem *item = searchResult.GetAt(i);
- if (steamIds.IsEmpty())
- steamIds.Append(item->GetSteamId());
- else
- steamIds.AppendFormat(",%s", item->GetSteamId());
- }
-
- SteamWebApi::FriendApi::Summaries summarues;
- debugLogA("CSteamProto::SearchByNameThread: call SteamWebApi::FriendApi::LoadSummaries");
- SteamWebApi::FriendApi::LoadSummaries(m_hNetlibUser, token, steamIds, &summarues);
-
- if (!summarues.IsSuccess())
- {
- ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)STEAM_SEARCH_BYNAME, 0);
- return;
- }
-
- for (size_t i = 0; i < summarues.GetItemCount(); i++)
- {
- const SteamWebApi::FriendApi::Summary *contact = summarues.GetAt(i);
-
- STEAM_SEARCH_RESULT ssr = { 0 };
- ssr.hdr.cbSize = sizeof(STEAM_SEARCH_RESULT);
- ssr.hdr.flags = PSR_TCHAR;
-
- ssr.hdr.id = mir_a2u(contact->GetSteamId());
- ssr.hdr.nick = mir_wstrdup(contact->GetNickName());
- ssr.hdr.firstName = mir_wstrdup(contact->GetFirstName());
- ssr.hdr.lastName = mir_wstrdup(contact->GetLastName());
-
- ssr.contact = contact;
-
- ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)STEAM_SEARCH_BYNAME, (LPARAM)&ssr);
- }
-
- ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)STEAM_SEARCH_BYNAME, 0);
-}
\ No newline at end of file +//void CSteamProto::SearchByNameThread(void* arg)
+//{
+// ptrW keywordsW((wchar_t*)arg);
+// ptrA keywords(mir_utf8encodeW(keywordsW));
+//
+// ptrA token(getStringA("TokenSecret"));
+//
+// SteamWebApi::SearchApi::SearchResult searchResult;
+// debugLogA("CSteamProto::SearchByNameThread: call SteamWebApi::SearchApi::Search");
+// SteamWebApi::SearchApi::Search(m_hNetlibUser, token, keywords, &searchResult);
+//
+// if (!searchResult.IsSuccess())
+// {
+// ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)STEAM_SEARCH_BYNAME, 0);
+// return;
+// }
+//
+// CMStringA steamIds;
+// for (int i = 0; i < searchResult.GetItemCount(); i++)
+// {
+// const SteamWebApi::SearchApi::SearchItem *item = searchResult.GetAt(i);
+// if (steamIds.IsEmpty())
+// steamIds.Append(item->GetSteamId());
+// else
+// steamIds.AppendFormat(",%s", item->GetSteamId());
+// }
+//
+// SteamWebApi::FriendApi::Summaries summarues;
+// debugLogA("CSteamProto::SearchByNameThread: call SteamWebApi::FriendApi::LoadSummaries");
+// SteamWebApi::FriendApi::LoadSummaries(m_hNetlibUser, token, steamIds, &summarues);
+//
+// if (!summarues.IsSuccess())
+// {
+// ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)STEAM_SEARCH_BYNAME, 0);
+// return;
+// }
+//
+// for (size_t i = 0; i < summarues.GetItemCount(); i++)
+// {
+// const SteamWebApi::FriendApi::Summary *contact = summarues.GetAt(i);
+//
+// STEAM_SEARCH_RESULT ssr = { 0 };
+// ssr.hdr.cbSize = sizeof(STEAM_SEARCH_RESULT);
+// ssr.hdr.flags = PSR_TCHAR;
+//
+// ssr.hdr.id = mir_a2u(contact->GetSteamId());
+// ssr.hdr.nick = mir_wstrdup(contact->GetNickName());
+// ssr.hdr.firstName = mir_wstrdup(contact->GetFirstName());
+// ssr.hdr.lastName = mir_wstrdup(contact->GetLastName());
+//
+// ssr.contact = contact;
+//
+// ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)STEAM_SEARCH_BYNAME, (LPARAM)&ssr);
+// }
+//
+// ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)STEAM_SEARCH_BYNAME, 0);
+//}
\ No newline at end of file diff --git a/protocols/Steam/src/steam_messages.cpp b/protocols/Steam/src/steam_messages.cpp index c6a06672f3..44feb387ad 100644 --- a/protocols/Steam/src/steam_messages.cpp +++ b/protocols/Steam/src/steam_messages.cpp @@ -1,39 +1,17 @@ #include "common.h"
-void CSteamProto::SendMessageThread(void *arg)
-{
- SendMessageParam *param = (SendMessageParam*)arg;
-
- ptrA token(getStringA("TokenSecret"));
- ptrA umqId(getStringA("UMQID"));
- ptrA steamId(getStringA(param->hContact, "SteamID"));
-
- SteamWebApi::MessageApi::SendResult sendResult;
- debugLogA("CSteamProto::SendMessageThread: call SteamWebApi::PollApi::SteamWebApi::MessageApi::SendMessage");
- SteamWebApi::MessageApi::SendMessage(m_hNetlibUser, token, umqId, steamId, param->text, &sendResult);
-
- ProtoBroadcastAck(
- param->hContact,
- ACKTYPE_MESSAGE,
- sendResult.IsSuccess() ? ACKRESULT_SUCCESS : ACKRESULT_FAILED,
- param->hMessage, 0);
-
- mir_free((void*)param->text);
- mir_free(param);
-}
-
-void CSteamProto::SendTypingThread(void *arg)
-{
- MCONTACT hContact = (MCONTACT)arg;
-
- ptrA token(getStringA("TokenSecret"));
- ptrA umqId(getStringA("UMQID"));
- ptrA steamId(getStringA(hContact, "SteamID"));
-
- SteamWebApi::MessageApi::SendResult sendResult;
- debugLogA("CSteamProto::SendTypingThread: call SteamWebApi::PollApi::SteamWebApi::MessageApi::SendMessage");
- SteamWebApi::MessageApi::SendTyping(m_hNetlibUser, token, umqId, steamId, &sendResult);
-}
+//void CSteamProto::SendTypingThread(void *arg)
+//{
+// MCONTACT hContact = (MCONTACT)arg;
+//
+// ptrA token(getStringA("TokenSecret"));
+// ptrA umqId(getStringA("UMQID"));
+// ptrA steamId(getStringA(hContact, "SteamID"));
+//
+// SteamWebApi::MessageApi::SendResult sendResult;
+// debugLogA("CSteamProto::SendTypingThread: call SteamWebApi::PollApi::SteamWebApi::MessageApi::SendMessage");
+// SteamWebApi::MessageApi::SendTyping(m_hNetlibUser, token, umqId, steamId, &sendResult);
+//}
void CSteamProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg)
{
diff --git a/protocols/Steam/src/steam_pooling.cpp b/protocols/Steam/src/steam_pooling.cpp index 957a3dff68..f2b8ef94a1 100644 --- a/protocols/Steam/src/steam_pooling.cpp +++ b/protocols/Steam/src/steam_pooling.cpp @@ -1,133 +1,5 @@ #include "common.h"
-void CSteamProto::PollServer(const char *token, const char *umqId, UINT32 messageId, SteamWebApi::PollApi::PollResult *pollResult)
-{
- debugLogA("CSteamProto::PollServer: call SteamWebApi::PollApi::Poll");
- SteamWebApi::PollApi::Poll(m_hNetlibUser, token, umqId, messageId, pollResult);
-
- if (!pollResult->IsSuccess())
- return;
-
- CMStringA updatedIds;
- for (size_t i = 0; i < pollResult->GetItemCount(); i++)
- {
- const SteamWebApi::PollApi::PoolItem *item = pollResult->GetAt(i);
- switch (item->GetType())
- {
- case SteamWebApi::PollApi::POOL_TYPE_TYPING:
- break;
-
- case SteamWebApi::PollApi::POOL_TYPE_MESSAGE:
- {
- SteamWebApi::PollApi::Message *message = (SteamWebApi::PollApi::Message*)item;
-
- MCONTACT hContact = FindContact(message->GetSteamId());
- if (hContact)
- {
- const wchar_t *text = message->GetText();
-
- PROTORECVEVENT recv = { 0 };
- recv.flags = PREF_UTF;
- recv.timestamp = message->GetTimestamp();
- recv.szMessage = mir_utf8encodeW(text);
-
- ProtoChainRecvMsg(hContact, &recv);
- }
- }
- break;
-
- case SteamWebApi::PollApi::POOL_TYPE_MYMESSAGE:
- {
- SteamWebApi::PollApi::Message *message = (SteamWebApi::PollApi::Message*)item;
-
- MCONTACT hContact = FindContact(message->GetSteamId());
- if (hContact)
- {
- const wchar_t *text = message->GetText();
-
- AddDBEvent(hContact, EVENTTYPE_MESSAGE, time(NULL), DBEF_UTF | DBEF_SENT, lstrlen(text), (BYTE*)mir_utf8encodeW(text));
- }
- }
- break;
-
- case SteamWebApi::PollApi::POOL_TYPE_STATE:
- {
- SteamWebApi::PollApi::State *state = (SteamWebApi::PollApi::State*)item;
-
- WORD status = CSteamProto::SteamToMirandaStatus(state->GetStatus());
- const char *steamId = state->GetSteamId();
- const wchar_t *nickname = state->GetNickname();
-
- if (IsMe(steamId))
- {
- if (status == ID_STATUS_OFFLINE)
- continue;
-
- if (status != m_iStatus)
- {
- debugLogA("Change own status to %i", status);
- WORD oldStatus = m_iStatus;
- m_iStatus = m_iDesiredStatus = status;
- ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
- }
- }
- /*else
- {
- MCONTACT hContact = FindContact(steamId);
- if (hContact)
- SetContactStatus(hContact, status);
- }*/
-
- if (updatedIds.IsEmpty())
- updatedIds.Append(steamId);
- else
- updatedIds.AppendFormat(",%s", steamId);
- }
- break;
-
- case SteamWebApi::PollApi::POOL_TYPE_CONTACT_ADD:
- {
- SteamWebApi::PollApi::Relationship *crs = (SteamWebApi::PollApi::Relationship*)item;
-
- const char *steamId = crs->GetSteamId();
- if (updatedIds.IsEmpty())
- updatedIds.Append(steamId);
- else
- updatedIds.AppendFormat(",%s", steamId);
- }
- break;
-
- case SteamWebApi::PollApi::POOL_TYPE_CONTACT_REMOVE:
- {
- SteamWebApi::PollApi::Relationship *crs = (SteamWebApi::PollApi::Relationship*)item;
-
- const char *steamId = crs->GetSteamId();
- MCONTACT hContact = FindContact(steamId);
- if (hContact)
- CallService(MS_DB_CONTACT_DELETE, hContact, 0);
- }
- break;
-
- case SteamWebApi::PollApi::POOL_TYPE_CONTACT_REQUEST:
- {
- SteamWebApi::PollApi::Relationship *crs = (SteamWebApi::PollApi::Relationship*)item;
-
- const char *steamId = crs->GetSteamId();
-
- MCONTACT hContact = FindContact(steamId);
- if (!hContact)
- hContact = AddContact(steamId, true);
-
- RaiseAuthRequestThread((void*)hContact);
- }
- break;
- }
- }
-
- if (!updatedIds.IsEmpty())
- UpdateContactsThread(mir_strdup(updatedIds));
-}
-
void CSteamProto::ParsePollData(JSONNODE *data)
{
JSONNODE *node, *item = NULL;
diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp index fec169b376..2e175c8317 100644 --- a/protocols/Steam/src/steam_proto.cpp +++ b/protocols/Steam/src/steam_proto.cpp @@ -52,10 +52,9 @@ CSteamProto::~CSteamProto() MCONTACT __cdecl CSteamProto::AddToList(int flags, PROTOSEARCHRESULT* psr)
{
MCONTACT hContact = NULL;
-
+ ptrA steamId(mir_u2a(psr->id));
if (psr->cbSize == sizeof(PROTOSEARCHRESULT))
{
- ptrA steamId(mir_u2a(psr->id));
if (!FindContact(steamId))
{
//hContact = AddContact(steamId, true);
@@ -71,7 +70,7 @@ MCONTACT __cdecl CSteamProto::AddToList(int flags, PROTOSEARCHRESULT* psr) else if (psr->cbSize == sizeof(STEAM_SEARCH_RESULT))
{
STEAM_SEARCH_RESULT *ssr = (STEAM_SEARCH_RESULT*)psr;
- hContact = AddContact(ssr->contact->GetSteamId(), true);
+ hContact = AddContact(steamId, true);
UpdateContact(hContact, ssr->data);
}
diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index 0ce865978f..7ddaf48786 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -27,13 +27,11 @@ struct SendMessageParam {
MCONTACT hContact;
HANDLE hMessage;
- const char *text;
};
struct STEAM_SEARCH_RESULT
{
PROTOSEARCHRESULT hdr;
- const SteamWebApi::FriendApi::Summary *contact;
JSONNODE *data;
};
@@ -47,6 +45,21 @@ enum CMI_MAX // this item shall be the last one
};
+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
+};
+
typedef void (CSteamProto::*RESPONSE)(const NETLIBHTTPREQUEST *response, void *arg);
struct QueueItem
@@ -160,18 +173,12 @@ protected: void __cdecl QueueThread(void*);
// pooling thread
- void PollServer(const char *sessionId, const char *steamId, UINT32 messageId, SteamWebApi::PollApi::PollResult *pollResult);
void ParsePollData(JSONNODE *data);
void __cdecl PollingThread(void*);
// account
bool IsOnline();
bool IsMe(const char *steamId);
- void SetServerStatus(WORD status);
- void Authorize(SteamWebApi::AuthorizationApi::AuthResult *authResult);
- void __cdecl LogInThread(void*);
- void __cdecl LogOutThread(void*);
- void __cdecl SetServerStatusThread(void*);
void OnGotRsaKey(const NETLIBHTTPREQUEST *response, void *arg);
@@ -186,9 +193,6 @@ protected: MCONTACT GetContactFromAuthEvent(HANDLE hEvent);
- void UpdateContact(MCONTACT hContact, const SteamWebApi::FriendApi::Summary *summary);
- void __cdecl UpdateContactsThread(void*);
-
void UpdateContact(MCONTACT hContact, JSONNODE *data);
MCONTACT FindContact(const char *steamId);
@@ -196,6 +200,7 @@ protected: void OnGotFriendList(const NETLIBHTTPREQUEST *response, void *arg);
void OnGotUserSummaries(const NETLIBHTTPREQUEST *response, void *arg);
+ void OnGotAvatar(const NETLIBHTTPREQUEST *response, void *arg);
void OnFriendAdded(const NETLIBHTTPREQUEST *response, void *arg);
void OnFriendRemoved(const NETLIBHTTPREQUEST *response, void *arg);
@@ -210,22 +215,7 @@ protected: void OnSearchByNameStarted(const NETLIBHTTPREQUEST *response, void *arg);
void OnSearchByNameFinished(const NETLIBHTTPREQUEST *response, void *arg);
- void __cdecl RaiseAuthRequestThread(void*);
- void __cdecl AuthAllowThread(void*);
- void __cdecl AuthDenyThread(void*);
-
- void __cdecl AddContactThread(void*);
- void __cdecl RemoveContactThread(void*);
-
- void __cdecl LoadContactListThread(void*);
-
- void __cdecl SearchByIdThread(void*);
- void __cdecl SearchByNameThread(void*);
-
// messages
- void __cdecl SendMessageThread(void*);
- void __cdecl SendTypingThread(void*);
-
void OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg);
// menus
|