diff options
-rw-r--r-- | protocols/Steam/src/api/friend_list.h | 2 | ||||
-rw-r--r-- | protocols/Steam/src/http_request.h | 23 | ||||
-rw-r--r-- | protocols/Steam/src/steam_avatars.cpp | 52 | ||||
-rw-r--r-- | protocols/Steam/src/steam_contacts.cpp | 217 | ||||
-rw-r--r-- | protocols/Steam/src/steam_crypt.cpp | 174 | ||||
-rw-r--r-- | protocols/Steam/src/steam_dialogs.cpp | 2 | ||||
-rw-r--r-- | protocols/Steam/src/steam_history.cpp | 30 | ||||
-rw-r--r-- | protocols/Steam/src/steam_login.cpp | 66 | ||||
-rw-r--r-- | protocols/Steam/src/steam_menus.cpp | 27 | ||||
-rw-r--r-- | protocols/Steam/src/steam_messages.cpp | 36 | ||||
-rw-r--r-- | protocols/Steam/src/steam_options.cpp | 4 | ||||
-rw-r--r-- | protocols/Steam/src/steam_polling.cpp | 96 | ||||
-rw-r--r-- | protocols/Steam/src/steam_proto.cpp | 13 | ||||
-rw-r--r-- | protocols/Steam/src/steam_proto.h | 21 | ||||
-rw-r--r-- | protocols/Steam/src/steam_utils.cpp | 10 | ||||
-rw-r--r-- | protocols/Steam/src/steam_xstatus.cpp | 29 | ||||
-rw-r--r-- | protocols/Steam/src/version.h | 2 |
17 files changed, 321 insertions, 483 deletions
diff --git a/protocols/Steam/src/api/friend_list.h b/protocols/Steam/src/api/friend_list.h index 50c9a7b5bc..c291f14b85 100644 --- a/protocols/Steam/src/api/friend_list.h +++ b/protocols/Steam/src/api/friend_list.h @@ -4,7 +4,7 @@ class GetFriendListRequest : public HttpRequest
{
public:
- GetFriendListRequest(const char *token, const char *steamId, const char *relationship = "friend,ignoredfriend,requestrecipient") :
+ GetFriendListRequest(const char *token, const char *steamId, const char *relationship) :
HttpRequest(HttpGet, STEAM_API_URL "/ISteamUserOAuth/GetFriendList/v0001")
{
Uri
diff --git a/protocols/Steam/src/http_request.h b/protocols/Steam/src/http_request.h index 7e8213b87d..b7c715ea92 100644 --- a/protocols/Steam/src/http_request.h +++ b/protocols/Steam/src/http_request.h @@ -170,8 +170,7 @@ protected: virtual ~HttpContent() { - if (m_request) - { + if (m_request) { m_request->pData = nullptr; m_request->dataLength = 0; } @@ -210,11 +209,11 @@ public: class FormUrlEncodedContent : public HttpContent { - friend FormUrlEncodedContent* operator<<(FormUrlEncodedContent*, const PARAM&); - friend FormUrlEncodedContent* operator<<(FormUrlEncodedContent*, const BOOL_PARAM&); - friend FormUrlEncodedContent* operator<<(FormUrlEncodedContent*, const INT_PARAM&); - friend FormUrlEncodedContent* operator<<(FormUrlEncodedContent*, const INT64_PARAM&); - friend FormUrlEncodedContent* operator<<(FormUrlEncodedContent*, const CHAR_PARAM&); + friend FormUrlEncodedContent *operator<<(FormUrlEncodedContent *, const PARAM &); + friend FormUrlEncodedContent *operator<<(FormUrlEncodedContent *, const BOOL_PARAM &); + friend FormUrlEncodedContent *operator<<(FormUrlEncodedContent *, const INT_PARAM &); + friend FormUrlEncodedContent *operator<<(FormUrlEncodedContent *, const INT64_PARAM &); + friend FormUrlEncodedContent *operator<<(FormUrlEncodedContent *, const CHAR_PARAM &); private: CMStringA m_content; @@ -228,8 +227,7 @@ private: m_content.AppendFormatV(fmt, args); va_end(args); - if (m_request) - { + if (m_request) { m_request->pData = m_content.GetBuffer(); m_request->dataLength = m_content.GetLength(); } @@ -291,8 +289,8 @@ public: HttpHeaders Headers; HttpContent Content; - HttpResponse(HttpRequest *request, NETLIBHTTPREQUEST *response) - : Request(request), + HttpResponse(HttpRequest *request, NETLIBHTTPREQUEST *response) : + Request(request), m_response(response), Headers(response), Content(response) @@ -372,8 +370,7 @@ public: ~HttpRequest() { - if (Content != nullptr) - { + if (Content != nullptr) { delete Content; Content = nullptr; } diff --git a/protocols/Steam/src/steam_avatars.cpp b/protocols/Steam/src/steam_avatars.cpp index 4a3a003ca7..828840de94 100644 --- a/protocols/Steam/src/steam_avatars.cpp +++ b/protocols/Steam/src/steam_avatars.cpp @@ -42,14 +42,12 @@ void CSteamProto::CheckAvatarChange(MCONTACT hContact, std::string avatarUrl) if (update_required)
setString(hContact, "AvatarUrl", avatarUrl.c_str());
- if (!hContact)
- {
+ if (!hContact) {
PROTO_AVATAR_INFORMATION ai = { 0 };
- if (GetAvatarInfo(update_required ? GAIF_FORCE : 0, (LPARAM)&ai) != GAIR_WAITFOR)
+ if (GetAvatarInfo(update_required ? GAIF_FORCE : 0, (LPARAM)& ai) != GAIR_WAITFOR)
ReportSelfAvatarChanged();
}
- else if (update_required)
- {
+ else if (update_required) {
db_set_b(hContact, "ContactPhoto", "NeedUpdate", 1);
ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, nullptr, 0);
}
@@ -60,14 +58,13 @@ INT_PTR CSteamProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) if (!lParam)
return GAIR_NOAVATAR;
- PROTO_AVATAR_INFORMATION* pai = (PROTO_AVATAR_INFORMATION*)lParam;
+ PROTO_AVATAR_INFORMATION *pai = (PROTO_AVATAR_INFORMATION *)lParam;
ptrA avatarUrl(getStringA(pai->hContact, "AvatarUrl"));
if (!avatarUrl)
return GAIR_NOAVATAR;
- if (GetDbAvatarInfo(*pai))
- {
+ if (GetDbAvatarInfo(*pai)) {
bool fileExist = _waccess(pai->filename, 0) == 0;
bool needLoad;
@@ -76,37 +73,30 @@ INT_PTR CSteamProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) else
needLoad = (wParam & GAIF_FORCE) || !fileExist;
- if (needLoad)
- {
- PushRequest(
- new GetAvatarRequest(avatarUrl),
- &CSteamProto::OnGotAvatar,
- (void*)pai->hContact);
-
+ if (needLoad) {
+ PushRequest(new GetAvatarRequest(avatarUrl), &CSteamProto::OnGotAvatar, (void *)pai->hContact);
return GAIR_WAITFOR;
}
- else if (fileExist)
+ if (fileExist)
return GAIR_SUCCESS;
-
}
+
return GAIR_NOAVATAR;
}
INT_PTR CSteamProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam)
{
- switch (wParam)
- {
+ switch (wParam) {
case AF_MAXSIZE:
- {
- POINT *size = (POINT*)lParam;
- if (size)
{
- size->x = 184;
- size->y = 184;
+ POINT *size = (POINT *)lParam;
+ if (size) {
+ size->x = 184;
+ size->y = 184;
+ }
}
- }
- break;
-
+ break;
+
case AF_PROPORTION:
return PIP_SQUARE;
@@ -115,7 +105,7 @@ INT_PTR CSteamProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam) case AF_ENABLED:
return 1;
-
+
case AF_DELAYAFTERFAIL:
// request avatar again in one hour if server gave an error
return 60 * 60 * 1000;
@@ -134,11 +124,11 @@ INT_PTR CSteamProto::GetMyAvatar(WPARAM wParam, LPARAM lParam) if (!wParam || !lParam)
return -3;
- wchar_t* buf = (wchar_t*)wParam;
+ wchar_t *buf = (wchar_t *)wParam;
int size = (int)lParam;
PROTO_AVATAR_INFORMATION ai = { 0 };
- switch (GetAvatarInfo(0, (LPARAM)&ai)) {
+ switch (GetAvatarInfo(0, (LPARAM)& ai)) {
case GAIR_SUCCESS:
wcsncpy(buf, ai.filename, size);
buf[size - 1] = 0;
@@ -150,4 +140,4 @@ INT_PTR CSteamProto::GetMyAvatar(WPARAM wParam, LPARAM lParam) default:
return -2;
}
-}
\ No newline at end of file +}
diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index aa0f13da76..4cd9ffc563 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -14,7 +14,7 @@ void CSteamProto::SetContactStatus(MCONTACT hContact, WORD status) WORD oldStatus = getWord(hContact, "Status", ID_STATUS_OFFLINE); if (oldStatus == status) return; - + setWord(hContact, "Status", status); // Special handling of some statuses @@ -23,7 +23,7 @@ void CSteamProto::SetContactStatus(MCONTACT hContact, WORD status) // if contact is offline, remove played game info delSetting(hContact, "GameID"); delSetting(hContact, "ServerIP"); - delSetting(hContact, "ServerID"); + delSetting(hContact, "ServerID"); // clear also xstatus delSetting(hContact, "XStatusId"); delSetting(hContact, "XStatusName"); @@ -31,7 +31,7 @@ void CSteamProto::SetContactStatus(MCONTACT hContact, WORD status) // and extra icon SetContactExtraIcon(hContact, NULL); // no break intentionally - [[fallthrough]]; + [[fallthrough]] ; default: db_unset(hContact, "CList", "StatusMsg"); @@ -43,8 +43,8 @@ MCONTACT CSteamProto::GetContactFromAuthEvent(MEVENT hEvent) { DWORD body[3]; DBEVENTINFO dbei = {}; - dbei.cbBlob = sizeof(DWORD)* 2; - dbei.pBlob = (PBYTE)&body; + dbei.cbBlob = sizeof(DWORD) * 2; + dbei.pBlob = (PBYTE)& body; if (db_event_get(hEvent, &dbei)) return INVALID_CONTACT_ID; @@ -81,8 +81,8 @@ void CSteamProto::UpdateContactDetails(MCONTACT hContact, const JSONNode &data) setString(hContact, "PrimaryClanID", primaryClanId.c_str()); // set name - JSONNode node = data["realname"]; - if (!node.isnull()) { + const JSONNode &node = data["realname"]; + if (node) { CMStringW realName = node.as_mstring(); if (!realName.IsEmpty()) { int pos = realName.Find(L' ', 1); @@ -107,14 +107,12 @@ void CSteamProto::UpdateContactDetails(MCONTACT hContact, const JSONNode &data) CheckAvatarChange(hContact, avatarUrl); // set country - node = data["loccountrycode"]; - if (!node.isnull()) { - json_string countryCode = node.as_string(); + json_string countryCode = data["loccountrycode"].as_string(); + if (!countryCode.empty()) { char *country = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)countryCode.c_str(), 0); setString(hContact, "Country", country); } - else - delSetting(hContact, "Country"); + else delSetting(hContact, "Country"); // state code // note: it seems that steam sends "incorrect" state code @@ -127,7 +125,7 @@ void CSteamProto::UpdateContactDetails(MCONTACT hContact, const JSONNode &data) //else //{ // delSetting(hContact, "State"); - delSetting(hContact, "StateCode"); + delSetting(hContact, "StateCode"); //} // city id @@ -136,35 +134,30 @@ void CSteamProto::UpdateContactDetails(MCONTACT hContact, const JSONNode &data) //if (!node.isnull()) // setDword(hContact, "CityID", node.as_int()); //else - delSetting(hContact, "CityID"); + delSetting(hContact, "CityID"); // account created - node = data["timecreated"]; - setDword(hContact, "MemberTS", node.as_int()); + setDword(hContact, "MemberTS", data["timecreated"].as_int()); // last logout time - node = data["lastlogoff"]; - setDword(hContact, "LogoffTS", node.as_int()); + setDword(hContact, "LogoffTS", data["lastlogoff"].as_int()); if (!IsOnline()) return; // status - node = data["personastate"]; // note: this here is often wrong info, probably depending on publicity of steam profile // but sometimes polling does not get status at all WORD oldStatus = getWord(hContact, "Status", ID_STATUS_OFFLINE); // so, set status only if contact is offline if (oldStatus == ID_STATUS_OFFLINE) { - WORD status = SteamToMirandaStatus((PersonaState)node.as_int()); + WORD status = SteamToMirandaStatus((PersonaState)data["personastate"].as_int()); SetContactStatus(hContact, status); } // client - node = data["personastateflags"]; - PersonaStateFlag stateflags = !node.isnull() - ? (PersonaStateFlag)node.as_int() - : (PersonaStateFlag)(-1); + const JSONNode &nFlags = data["personastateflags"]; + PersonaStateFlag stateflags = (nFlags) ? (PersonaStateFlag)nFlags.as_int() : (PersonaStateFlag)(-1); if (stateflags == PersonaStateFlag::None) { // nothing special, either standard client or in different status (only online, I want to play, I want to trade statuses support this flags) @@ -212,10 +205,7 @@ void CSteamProto::UpdateContactDetails(MCONTACT hContact, const JSONNode &data) CMStringW message(gameInfo); if (gameId && message.IsEmpty()) { ptrA token(getStringA("TokenSecret")); - PushRequest( - new GetAppInfoRequest(token, appId.c_str()), - &CSteamProto::OnGotAppInfo, - (void*)hContact); + PushRequest(new GetAppInfoRequest(token, appId.c_str()), &CSteamProto::OnGotAppInfo, (void*)hContact); } else { if (!gameId) @@ -223,7 +213,7 @@ void CSteamProto::UpdateContactDetails(MCONTACT hContact, const JSONNode &data) if (!serverIP.empty()) message.AppendFormat(TranslateT(" on server %s"), serverIP.c_str()); } - + setDword(hContact, "XStatusId", gameId); setWString(hContact, "XStatusName", TranslateT("Playing")); setWString(hContact, "XStatusMsg", message); @@ -294,23 +284,23 @@ void CSteamProto::ContactIsRemoved(MCONTACT hContact) void CSteamProto::ContactIsAskingAuth(MCONTACT hContact) { + // auth request was already showed, do nothing here if (getByte(hContact, "AuthAsked", 0)) - // auth request was already showed, do nothing here return; - /*if (getByte(hContact, "Auth", 0) == 0) { - // user was just added or he already has authorization, but because we've just got auth request, he was probably deleted and requested again - ContactIsRemoved(hContact); - }*/ - // create auth request event ptrA steamId(getStringA(hContact, "SteamID")); + ptrA token(getStringA("TokenSecret")); + SendRequest(new GetUserSummariesRequest(token, steamId), &CSteamProto::OnGotUserSummaries); + ptrA nickName(getStringA(hContact, "Nick")); if (nickName == nullptr) nickName = mir_strdup(steamId); + ptrA firstName(getStringA(hContact, "FirstName")); if (firstName == nullptr) firstName = mir_strdup(""); + ptrA lastName(getStringA(hContact, "LastName")); if (lastName == nullptr) lastName = mir_strdup(""); @@ -350,16 +340,12 @@ MCONTACT CSteamProto::AddContact(const char *steamId, const wchar_t *nick, bool db_set_ws(hContact, "CList", "MyHandle", nick); } - // update info - //UpdateContact(hContact, contact); - if (isTemporary) { debugLogA("Contact %d added as a temporary one"); db_set_b(hContact, "CList", "NotOnList", 1); } setByte(hContact, "Auth", 1); - //setByte(hContact, "Grant", 1); // move to default group Clist_SetGroup(hContact, m_defaultGroup); @@ -369,15 +355,11 @@ MCONTACT CSteamProto::AddContact(const char *steamId, const wchar_t *nick, bool void CSteamProto::UpdateContactRelationship(MCONTACT hContact, const JSONNode &data) { - JSONNode node = data["friend_since"]; - if (!node.isnull()) + const JSONNode &node = data["friend_since"]; + if (node) db_set_dw(hContact, "UserInfo", "ContactAddTime", node.as_int()); - node = data["relationship"]; - if (node.isnull()) - return; - - json_string relationship = node.as_string(); + json_string relationship = data["relationship"].as_string(); if (relationship == "friend") ContactIsFriend(hContact); else if (relationship == "ignoredfriend") @@ -390,8 +372,7 @@ void CSteamProto::OnGotAppInfo(const JSONNode &root, void *arg) { MCONTACT hContact = (UINT_PTR)arg; - JSONNode apps = root["apps"].as_array(); - for (const JSONNode &app : apps) { + for (auto &app : root["apps"]) { DWORD gameId = app["appid"].as_int(); CMStringW message = app["name"].as_mstring(); @@ -401,20 +382,19 @@ void CSteamProto::OnGotAppInfo(const JSONNode &root, void *arg) } } -void CSteamProto::OnGotFriendList(const JSONNode &root, void*) +void CSteamProto::OnGotFriendList(const JSONNode &root, void *) { if (root.isnull()) return; // Comma-separated list of steam ids to update summaries - std::string steamIds = (char*)ptrA(getStringA("SteamID")); + std::string steamIds = (char *)ptrA(getStringA("SteamID")); // Remember contacts on server - std::map<json_string, JSONNode*> friendsMap; - JSONNode friends = root["friends"].as_array(); - for (const JSONNode &_friend : friends) { + std::map<json_string, const JSONNode*> friendsMap; + for (auto &_friend : root["friends"]) { json_string steamId = _friend["steamid"].as_string(); - friendsMap.insert(std::make_pair(steamId, json_copy(&_friend))); + friendsMap.insert(std::make_pair(steamId, &_friend)); } // Check and update contacts in database @@ -423,14 +403,14 @@ void CSteamProto::OnGotFriendList(const JSONNode &root, void*) if (steamId == nullptr) continue; - auto it = friendsMap.find((char*)steamId); + auto it = friendsMap.find((char *)steamId); if (it == friendsMap.end()) { // Contact was removed from server-list, notify it ContactIsRemoved(hContact); continue; } - JSONNode _friend = *it->second; + const JSONNode &_friend = *it->second; // Contact is on server-list, update (and eventually notify) it UpdateContactRelationship(hContact, _friend); @@ -440,14 +420,13 @@ void CSteamProto::OnGotFriendList(const JSONNode &root, void*) if (relationship == "friend") steamIds.append(",").append(it->first); - json_delete(it->second); friendsMap.erase(it); } // Check remaining contacts in map and add them to contact list for (auto it : friendsMap) { // Contact is on server-list, but not in database, add (but not notify) it - JSONNode _friend = *it.second; + const JSONNode &_friend = *it.second; json_string relationship = _friend["relationship"].as_string(); @@ -456,71 +435,40 @@ void CSteamProto::OnGotFriendList(const JSONNode &root, void*) if (relationship == "friend") steamIds.append(",").append(it.first); - - json_delete(it.second); } friendsMap.clear(); ptrA token(getStringA("TokenSecret")); if (!steamIds.empty()) - { - steamIds.pop_back(); - - PushRequest( - new GetUserSummariesRequest(token, steamIds.c_str()), - &CSteamProto::OnGotUserSummaries); - } + PushRequest(new GetUserSummariesRequest(token, steamIds.c_str()), &CSteamProto::OnGotUserSummaries); // Load last conversations - PushRequest( - new GetConversationsRequest(token), - &CSteamProto::OnGotConversations); + PushRequest(new GetConversationsRequest(token), &CSteamProto::OnGotConversations); } -void CSteamProto::OnGotBlockList(const JSONNode &root, void*) +void CSteamProto::OnGotBlockList(const JSONNode &root, void *) { if (root.isnull()) return; - //std::string steamIds; - - JSONNode friends = root["friends"].as_array(); - if (friends.isnull()) - return; - - for (const JSONNode &_friend: friends) - { + for (auto &_friend : root["friends"]) { json_string steamId = _friend["steamid"].as_string(); - /*MCONTACT hContact = FindContact(steamId); - if (!hContact) - { - hContact = AddContact(steamId); - steamIds.append(steamId).append(","); - }*/ - json_string relationship = _friend["relationship"].as_string(); - if (!mir_strcmp(relationship.c_str(), "ignoredfriend")) - { + if (!mir_strcmp(relationship.c_str(), "ignoredfriend")) { // todo: open block list } else continue; } } -void CSteamProto::OnGotUserSummaries(const JSONNode &root, void*) +void CSteamProto::OnGotUserSummaries(const JSONNode &root, void *) { - JSONNode players = root["players"].as_array(); - if (players.isnull()) - return; - - for (const JSONNode &player : players) { + for (auto &player : root["players"]) { json_string steamId = player["steamid"].as_string(); CMStringW nick = player["personaname"].as_mstring(); - MCONTACT hContact = !IsMe(steamId.c_str()) - ? hContact = AddContact(steamId.c_str(), nick) - : NULL; + MCONTACT hContact = !IsMe(steamId.c_str()) ? AddContact(steamId.c_str(), nick) : 0; UpdateContactDetails(hContact, player); } } @@ -536,17 +484,17 @@ void CSteamProto::OnGotAvatar(const HttpResponse &response, void *arg) debugLogA(__FUNCTION__ ": failed to get avatar %s", steamId); if (ai.hContact) - ProtoBroadcastAck(ai.hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, (HANDLE)&ai, 0); + ProtoBroadcastAck(ai.hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, (HANDLE)& ai, 0); return; } FILE *file = _wfopen(ai.filename, L"wb"); if (file) { - fwrite((const char*)response.Content, sizeof(char), response.Content.size(), file); + fwrite((const char *)response.Content, sizeof(char), response.Content.size(), file); fclose(file); if (ai.hContact) - ProtoBroadcastAck(ai.hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&ai, 0); + ProtoBroadcastAck(ai.hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)& ai, 0); else ReportSelfAvatarChanged(); } @@ -554,10 +502,10 @@ void CSteamProto::OnGotAvatar(const HttpResponse &response, void *arg) void CSteamProto::OnFriendAdded(const HttpResponse &response, void *arg) { - SendAuthParam *param = (SendAuthParam*)arg; + SendAuthParam *param = (SendAuthParam *)arg; if (!response.IsSuccess() || mir_strcmp(response.Content, "true")) { - + ptrW steamId(getWStringA(param->hContact, "SteamID")); ptrW who(getWStringA(param->hContact, "Nick")); if (!who) @@ -570,14 +518,13 @@ void CSteamProto::OnFriendAdded(const HttpResponse &response, void *arg) if (root) { int success = root["success"].as_int(); if (success == 1) { - JSONNode invited = root["invited"].as_array(); - if (invited.empty()) { - JSONNode errors = root["failed_invites_result"].as_array(); + const JSONNode &invited = root["invited"]; + if (invited) { + const JSONNode &errors = root["failed_invites_result"]; if (!errors.empty()) { int first = 0; int errorCode = errors[first].as_int(); - switch (errorCode) - { + switch (errorCode) { case 11: mir_snwprintf(message, L"All communication with %s is blocked. Communication is only possible if you have lifted the blocking. To do this, visit the user's Steam Community page.", who); break; @@ -618,10 +565,10 @@ void CSteamProto::OnFriendAdded(const HttpResponse &response, void *arg) void CSteamProto::OnFriendBlocked(const HttpResponse &response, void *arg) { - ptrA steamId((char*)arg); + ptrA steamId((char *)arg); if (!response.IsSuccess() || mir_strcmp(response.Content, "true")) { - debugLogA(__FUNCTION__ ": failed to ignore friend %s", (char*)steamId); + debugLogA(__FUNCTION__ ": failed to ignore friend %s", (char *)steamId); return; } @@ -632,10 +579,10 @@ void CSteamProto::OnFriendBlocked(const HttpResponse &response, void *arg) void CSteamProto::OnFriendUnblocked(const HttpResponse &response, void *arg) { - ptrA steamId((char*)arg); + ptrA steamId((char *)arg); if (!response.IsSuccess() || mir_strcmp(response.Content, "true")) { - debugLogA(__FUNCTION__ ": failed to unignore friend %s", (char*)steamId); + debugLogA(__FUNCTION__ ": failed to unignore friend %s", (char *)steamId); return; } @@ -646,10 +593,10 @@ void CSteamProto::OnFriendUnblocked(const HttpResponse &response, void *arg) void CSteamProto::OnFriendRemoved(const HttpResponse &response, void *arg) { - ptrA steamId((char*)arg); + ptrA steamId((char *)arg); if (!response.IsSuccess() || mir_strcmp(response.Content, "true")) { - debugLogA(__FUNCTION__ ": failed to remove friend %s", (char*)steamId); + debugLogA(__FUNCTION__ ": failed to remove friend %s", (char *)steamId); return; } @@ -658,27 +605,23 @@ void CSteamProto::OnFriendRemoved(const HttpResponse &response, void *arg) ContactIsRemoved(hContact); } -void CSteamProto::OnAuthRequested(const JSONNode &root, void*) +void CSteamProto::OnAuthRequested(const JSONNode &root, void *) { if (root.isnull()) return; - int first = 0; - JSONNode players = root["players"].as_array(); - JSONNode player = players[first]; - if (player.isnull()) - return; - - json_string steamId = player["steamid"].as_string(); - CMStringW nick = player["personaname"].as_mstring(); - MCONTACT hContact = AddContact(steamId.c_str(), nick); - UpdateContactDetails(hContact, player); - ContactIsAskingAuth(hContact); + for (auto &player : root["players"]) { + json_string steamId = player["steamid"].as_string(); + CMStringW nick = player["personaname"].as_mstring(); + MCONTACT hContact = AddContact(steamId.c_str(), nick); + UpdateContactDetails(hContact, player); + ContactIsAskingAuth(hContact); + } } void CSteamProto::OnPendingApproved(const JSONNode &root, void *arg) { - ptrA steamId((char*)arg); + ptrA steamId((char *)arg); if (root.isnull()) return; @@ -692,7 +635,7 @@ void CSteamProto::OnPendingApproved(const JSONNode &root, void *arg) void CSteamProto::OnPendingIgnoreded(const JSONNode &root, void *arg) { - ptrA steamId((char*)arg); + ptrA steamId((char *)arg); if (root.isnull()) return; @@ -721,8 +664,7 @@ void CSteamProto::OnSearchResults(const HttpResponse &response, void *arg) return; } - JSONNode players = root["players"].as_array(); - for (const JSONNode &player : players) { + for (auto &player : root["players"]) { STEAM_SEARCH_RESULT ssr = { 0 }; ssr.psr.cbSize = sizeof(STEAM_SEARCH_RESULT); ssr.psr.flags = PSR_UNICODE; @@ -733,8 +675,8 @@ void CSteamProto::OnSearchResults(const HttpResponse &response, void *arg) CMStringW nick = player["personaname"].as_mstring(); ssr.psr.nick.w = nick.Detach(); - JSONNode node = player["realname"]; - if (!node.isnull()) { + const JSONNode &node = player["realname"]; + if (node) { CMStringW realName = node.as_mstring(); if (!realName.IsEmpty()) { int pos = realName.Find(' ', 1); @@ -742,15 +684,14 @@ void CSteamProto::OnSearchResults(const HttpResponse &response, void *arg) ssr.psr.firstName.w = realName.Mid(0, pos).Detach(); ssr.psr.lastName.w = realName.Mid(pos + 1).Detach(); } - else - ssr.psr.firstName.w = realName.Detach(); + else ssr.psr.firstName.w = realName.Detach(); } } // todo: is this needed and safe (no memleak) to be here? ssr.data = json_copy(&player); - ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, searchType, (LPARAM)&ssr); + ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, searchType, (LPARAM)& ssr); } ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, searchType, 0); @@ -777,8 +718,7 @@ void CSteamProto::OnSearchByNameStarted(const HttpResponse &response, void *arg) std::string steamIds; - JSONNode results = root["results"].as_array(); - for (const JSONNode &result : results) { + for (auto &result : root["results"]) { json_string steamId = result["steamid"].as_string(); steamIds.append(steamId).append(","); } @@ -792,8 +732,5 @@ void CSteamProto::OnSearchByNameStarted(const HttpResponse &response, void *arg) steamIds.pop_back(); ptrA token(getStringA("TokenSecret")); - PushRequest( - new GetUserSummariesRequest(token, steamIds.c_str()), - &CSteamProto::OnSearchResults, - (HANDLE)arg); + PushRequest(new GetUserSummariesRequest(token, steamIds.c_str()), &CSteamProto::OnSearchResults, (HANDLE)arg); } diff --git a/protocols/Steam/src/steam_crypt.cpp b/protocols/Steam/src/steam_crypt.cpp index 7c7fa07312..28cc21f6f5 100644 --- a/protocols/Steam/src/steam_crypt.cpp +++ b/protocols/Steam/src/steam_crypt.cpp @@ -5,108 +5,98 @@ int CSteamProto::RsaEncrypt(const char *pszModulus, DWORD &exponent, const char *data, BYTE *encryptedData, DWORD &encryptedSize) { DWORD cchModulus = (DWORD)mir_strlen(pszModulus); - int result = 0; - BYTE *pbBuffer = nullptr; - BYTE *pKeyBlob = nullptr; + int result; HCRYPTKEY phKey = 0; HCRYPTPROV hCSP = 0; - // convert hex string to byte array - DWORD cbLen = 0, dwSkip = 0, dwFlags = 0; - if (!CryptStringToBinaryA(pszModulus, cchModulus, CRYPT_STRING_HEX, nullptr, &cbLen, &dwSkip, &dwFlags)) - { - result = GetLastError(); - goto exit; - } - - // allocate a new buffer. - pbBuffer = (BYTE*)malloc(cbLen); - if (!CryptStringToBinaryA(pszModulus, cchModulus, CRYPT_STRING_HEX, pbBuffer, &cbLen, &dwSkip, &dwFlags)) - { - result = GetLastError(); - goto exit; - } - - // reverse byte array, because of microsoft - for (int i = 0; i < (int)(cbLen / 2); ++i) - { - BYTE temp = pbBuffer[cbLen - i - 1]; - pbBuffer[cbLen - i - 1] = pbBuffer[i]; - pbBuffer[i] = temp; - } - - if (!CryptAcquireContext(&hCSP, nullptr, nullptr, PROV_RSA_AES, CRYPT_SILENT) && - !CryptAcquireContext(&hCSP, nullptr, nullptr, PROV_RSA_AES, CRYPT_SILENT | CRYPT_NEWKEYSET)) - { - result = GetLastError(); - goto exit; - } - - // Move the key into the key container. - DWORD cbKeyBlob = sizeof(PUBLICKEYSTRUC) + sizeof(RSAPUBKEY) + cbLen; - pKeyBlob = (BYTE*)malloc(cbKeyBlob); - - // Fill in the data. - PUBLICKEYSTRUC *pPublicKey = (PUBLICKEYSTRUC*)pKeyBlob; - pPublicKey->bType = PUBLICKEYBLOB; - pPublicKey->bVersion = CUR_BLOB_VERSION; // Always use this value. - pPublicKey->reserved = 0; // Must be zero. - pPublicKey->aiKeyAlg = CALG_RSA_KEYX; // RSA public-key key exchange. - - // The next block of data is the RSAPUBKEY structure. - RSAPUBKEY *pRsaPubKey = (RSAPUBKEY*)(pKeyBlob + sizeof(PUBLICKEYSTRUC)); - pRsaPubKey->magic = 0x31415352; // RSA1 // Use public key - pRsaPubKey->bitlen = cbLen * 8; // Number of bits in the modulus. - pRsaPubKey->pubexp = exponent; // Exponent. - - // Copy the modulus into the blob. Put the modulus directly after the - // RSAPUBKEY structure in the blob. - BYTE *pKey = (BYTE*)(((BYTE *)pRsaPubKey) + sizeof(RSAPUBKEY)); - //pKeyBlob + sizeof(BLOBHEADER)+ sizeof(RSAPUBKEY); - memcpy(pKey, pbBuffer, cbLen); - - // Now import public key - if (!CryptImportKey(hCSP, pKeyBlob, cbKeyBlob, 0, 0, &phKey)) - { - result = GetLastError(); - goto exit; - } - - DWORD dataSize = (DWORD)mir_strlen(data); - - // if data is not allocated just renurn size - if (encryptedData == nullptr) - { - // get length of encrypted data - if (!CryptEncrypt(phKey, 0, TRUE, 0, nullptr, &encryptedSize, dataSize)) + __try { + // convert hex string to byte array + DWORD cbLen = 0, dwSkip = 0, dwFlags = 0; + if (!CryptStringToBinaryA(pszModulus, cchModulus, CRYPT_STRING_HEX, nullptr, &cbLen, &dwSkip, &dwFlags)) { result = GetLastError(); - goto exit; - } + __leave; + } - // encrypt password - memcpy(encryptedData, data, dataSize); - if (!CryptEncrypt(phKey, 0, TRUE, 0, encryptedData, &dataSize, encryptedSize)) - { - result = GetLastError(); - goto exit; + // allocate a new buffer. + mir_ptr<BYTE> pbBuffer((BYTE *)mir_alloc(cbLen)); + if (!CryptStringToBinaryA(pszModulus, cchModulus, CRYPT_STRING_HEX, pbBuffer, &cbLen, &dwSkip, &dwFlags)) { + result = GetLastError(); + __leave; + } + + // reverse byte array, because of microsoft + for (int i = 0; i < (int)(cbLen / 2); ++i) { + BYTE temp = pbBuffer[cbLen - i - 1]; + pbBuffer[cbLen - i - 1] = pbBuffer[i]; + pbBuffer[i] = temp; + } + + if (!CryptAcquireContext(&hCSP, nullptr, nullptr, PROV_RSA_AES, CRYPT_SILENT) && + !CryptAcquireContext(&hCSP, nullptr, nullptr, PROV_RSA_AES, CRYPT_SILENT | CRYPT_NEWKEYSET)) { + result = GetLastError(); + __leave; + } + + // Move the key into the key container. + DWORD cbKeyBlob = sizeof(PUBLICKEYSTRUC) + sizeof(RSAPUBKEY) + cbLen; + mir_ptr<BYTE> pKeyBlob((BYTE *)mir_alloc(cbKeyBlob)); + + // Fill in the data. + PUBLICKEYSTRUC *pPublicKey = (PUBLICKEYSTRUC *)pKeyBlob.get(); + pPublicKey->bType = PUBLICKEYBLOB; + pPublicKey->bVersion = CUR_BLOB_VERSION; // Always use this value. + pPublicKey->reserved = 0; // Must be zero. + pPublicKey->aiKeyAlg = CALG_RSA_KEYX; // RSA public-key key exchange. + + // The next block of data is the RSAPUBKEY structure. + RSAPUBKEY *pRsaPubKey = (RSAPUBKEY *)(pKeyBlob + sizeof(PUBLICKEYSTRUC)); + pRsaPubKey->magic = 0x31415352; // RSA1 // Use public key + pRsaPubKey->bitlen = cbLen * 8; // Number of bits in the modulus. + pRsaPubKey->pubexp = exponent; // Exponent. + + // Copy the modulus into the blob. Put the modulus directly after the + // RSAPUBKEY structure in the blob. + BYTE *pKey = (BYTE *)(((BYTE *)pRsaPubKey) + sizeof(RSAPUBKEY)); + memcpy(pKey, pbBuffer, cbLen); + + // Now import public key + if (!CryptImportKey(hCSP, pKeyBlob, cbKeyBlob, 0, 0, &phKey)) { + result = GetLastError(); + __leave; + } + + DWORD dataSize = (DWORD)mir_strlen(data); + + // if data is not allocated just renurn size + if (encryptedData == nullptr) { + // get length of encrypted data + if (!CryptEncrypt(phKey, 0, TRUE, 0, nullptr, &encryptedSize, dataSize)) + result = GetLastError(); + __leave; + } + + // encrypt password + memcpy(encryptedData, data, dataSize); + if (!CryptEncrypt(phKey, 0, TRUE, 0, encryptedData, &dataSize, encryptedSize)) { + result = GetLastError(); + __leave; + } + + // reverse byte array again + for (int i = 0; i < (int)(encryptedSize / 2); ++i) { + BYTE temp = encryptedData[encryptedSize - i - 1]; + encryptedData[encryptedSize - i - 1] = encryptedData[i]; + encryptedData[i] = temp; + } } - - // reverse byte array again - for (int i = 0; i < (int)(encryptedSize / 2); ++i) + __finally { - BYTE temp = encryptedData[encryptedSize - i - 1]; - encryptedData[encryptedSize - i - 1] = encryptedData[i]; - encryptedData[i] = temp; - } + result = 0; + }; -exit: - if (pKeyBlob) - free(pKeyBlob); if (phKey) CryptDestroyKey(phKey); - - if (pbBuffer) - free(pbBuffer); + if (hCSP) CryptReleaseContext(hCSP, 0); diff --git a/protocols/Steam/src/steam_dialogs.cpp b/protocols/Steam/src/steam_dialogs.cpp index 3277f3fa2b..68605a0eec 100644 --- a/protocols/Steam/src/steam_dialogs.cpp +++ b/protocols/Steam/src/steam_dialogs.cpp @@ -196,4 +196,4 @@ INT_PTR CSteamCaptchaDialog::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) const char* CSteamCaptchaDialog::GetCaptchaText()
{
return m_captchaText;
-}
\ No newline at end of file +}
diff --git a/protocols/Steam/src/steam_history.cpp b/protocols/Steam/src/steam_history.cpp index 987b96ecea..27c693cb30 100644 --- a/protocols/Steam/src/steam_history.cpp +++ b/protocols/Steam/src/steam_history.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" -void CSteamProto::OnGotConversations(const JSONNode &root, void*) +void CSteamProto::OnGotConversations(const JSONNode &root, void *) { // Don't load any messages when we don't have lastMessageTS, as it may cause duplicates if (m_lastMessageTS <= 0) @@ -9,13 +9,8 @@ void CSteamProto::OnGotConversations(const JSONNode &root, void*) if (root.isnull()) return; - JSONNode response = root["response"]; - JSONNode sessions = response["message_sessions"].as_array(); - if (sessions.isnull()) - return; - - for (const JSONNode &session : sessions) - { + const JSONNode &response = root["response"]; + for (auto &session : response["message_sessions"]) { long long accountId = _wtoi64(session["accountid_friend"].as_mstring()); const char *who = AccountIdToSteamId(accountId); @@ -27,22 +22,17 @@ void CSteamProto::OnGotConversations(const JSONNode &root, void*) node = json_get(session, "unread_message_count"); long unread_count = json_as_int(node);*/ - if (lastMessageTS > m_lastMessageTS) - { + if (lastMessageTS > m_lastMessageTS) { ptrA token(getStringA("TokenSecret")); ptrA steamId(getStringA("SteamID")); - - PushRequest( - new GetHistoryMessagesRequest(token, steamId, who, m_lastMessageTS), - &CSteamProto::OnGotHistoryMessages, - mir_strdup(who)); + PushRequest(new GetHistoryMessagesRequest(token, steamId, who, m_lastMessageTS), &CSteamProto::OnGotHistoryMessages, mir_strdup(who)); } } } void CSteamProto::OnGotHistoryMessages(const JSONNode &root, void *arg) { - ptrA cSteamId((char*)arg); + ptrA cSteamId((char *)arg); MCONTACT hContact = GetContact(cSteamId); if (!hContact) @@ -51,10 +41,10 @@ void CSteamProto::OnGotHistoryMessages(const JSONNode &root, void *arg) if (root.isnull()) return; - JSONNode response = root["response"]; - JSONNode messages = response["messages"].as_array(); + const JSONNode &response = root["response"]; + const JSONNode &messages = response["messages"]; for (size_t i = messages.size(); i > 0; i--) { - JSONNode message = messages[i - 1]; + const JSONNode &message = messages[i - 1]; long long accountId = _wtoi64(message["accountid"].as_mstring()); const char *steamId = AccountIdToSteamId(accountId); @@ -69,7 +59,7 @@ void CSteamProto::OnGotHistoryMessages(const JSONNode &root, void *arg) PROTORECVEVENT recv = { 0 }; recv.timestamp = timestamp; - recv.szMessage = (char*)text.c_str(); + recv.szMessage = (char *)text.c_str(); if (IsMe(steamId)) recv.flags = PREF_SENT; diff --git a/protocols/Steam/src/steam_login.cpp b/protocols/Steam/src/steam_login.cpp index 5eaa7609af..4537b52532 100644 --- a/protocols/Steam/src/steam_login.cpp +++ b/protocols/Steam/src/steam_login.cpp @@ -16,21 +16,15 @@ void CSteamProto::Login() ptrA token(getStringA("TokenSecret")); ptrA sessionId(getStringA("SessionID")); if (mir_strlen(token) > 0 && mir_strlen(sessionId) > 0) { - PushRequest( - new LogonRequest(token), - &CSteamProto::OnLoggedOn); + PushRequest(new LogonRequest(token), &CSteamProto::OnLoggedOn); return; } - + T2Utf username(getWStringA("Username")); - if (username == NULL) { + if (username == NULL) SetStatus(ID_STATUS_OFFLINE); - return; - } - - PushRequest( - new GetRsaKeyRequest(username), - &CSteamProto::OnGotRsaKey); + else + PushRequest(new GetRsaKeyRequest(username), &CSteamProto::OnGotRsaKey); } void CSteamProto::Logout() @@ -46,7 +40,7 @@ void CSteamProto::Logout() } } -void CSteamProto::OnGotRsaKey(const JSONNode &root, void*) +void CSteamProto::OnGotRsaKey(const JSONNode &root, void *) { if (root.isnull()) { SetStatus(ID_STATUS_OFFLINE); @@ -77,7 +71,7 @@ void CSteamProto::OnGotRsaKey(const JSONNode &root, void*) return; } - BYTE *encryptedPassword = (BYTE*)mir_calloc(encryptedSize); + BYTE *encryptedPassword = (BYTE *)mir_calloc(encryptedSize); if ((error = RsaEncrypt(modulus.c_str(), exponent, szPassword, encryptedPassword, encryptedSize)) != 0) { debugLogA(__FUNCTION__ ": encryption error (%lu)", error); SetStatus(ID_STATUS_OFFLINE); @@ -109,14 +103,13 @@ void CSteamProto::OnGotRsaKey(const JSONNode &root, void*) captchaText = mir_strdup(""); PushRequest( - new AuthorizationRequest(username, base64RsaEncryptedPassword, timestamp.c_str(), twoFactorCode, - guardCode, guardId, captchaId, captchaText), + new AuthorizationRequest(username, base64RsaEncryptedPassword, timestamp.c_str(), twoFactorCode, guardCode, guardId, captchaId, captchaText), &CSteamProto::OnAuthorization); } void CSteamProto::OnGotCaptcha(const HttpResponse &response, void *arg) { - ptrA captchaId((char*)arg); + ptrA captchaId((char *)arg); if (!response.IsSuccess()) { debugLogA(__FUNCTION__ ": failed to get captcha"); @@ -134,12 +127,10 @@ void CSteamProto::OnGotCaptcha(const HttpResponse &response, void *arg) setString("CaptchaText", captchaDialog.GetCaptchaText()); T2Utf username(getWStringA("Username")); - PushRequest( - new GetRsaKeyRequest(username), - &CSteamProto::OnGotRsaKey); + PushRequest(new GetRsaKeyRequest(username), &CSteamProto::OnGotRsaKey); } -void CSteamProto::OnAuthorization(const HttpResponse &response, void*) +void CSteamProto::OnAuthorization(const HttpResponse &response, void *) { if (!response) { SetStatus(ID_STATUS_OFFLINE); @@ -206,9 +197,7 @@ void CSteamProto::OnAuthorizationError(const JSONNode &root) setString("TwoFactorCode", twoFactorDialog.GetTwoFactorCode()); - PushRequest( - new GetRsaKeyRequest(username), - &CSteamProto::OnGotRsaKey); + PushRequest(new GetRsaKeyRequest(username), &CSteamProto::OnGotRsaKey); return; } @@ -238,9 +227,7 @@ void CSteamProto::OnAuthorizationError(const JSONNode &root) setString("GuardId", guardId.c_str()); setString("GuardCode", guardDialog.GetGuardCode()); - PushRequest( - new GetRsaKeyRequest(username), - &CSteamProto::OnGotRsaKey); + PushRequest(new GetRsaKeyRequest(username), &CSteamProto::OnGotRsaKey); return; } @@ -249,10 +236,7 @@ void CSteamProto::OnAuthorizationError(const JSONNode &root) delSetting("CaptchaId"); delSetting("CaptchaText"); json_string captchaId = root["captcha_gid"].as_string(); - PushRequest( - new GetCaptchaRequest(captchaId.c_str()), - &CSteamProto::OnGotCaptcha, - mir_strdup(captchaId.c_str())); + PushRequest(new GetCaptchaRequest(captchaId.c_str()), &CSteamProto::OnGotCaptcha, mir_strdup(captchaId.c_str())); return; } @@ -284,16 +268,12 @@ void CSteamProto::OnAuthorizationSuccess(const JSONNode &root) json_string token = node["oauth_token"].as_string(); setString("TokenSecret", token.c_str()); - SendRequest( - new GetSessionRequest2(token.c_str(), steamId.c_str()), - &CSteamProto::OnGotSession); + SendRequest(new GetSessionRequest2(token.c_str(), steamId.c_str()), &CSteamProto::OnGotSession); - PushRequest( - new LogonRequest(token.c_str()), - &CSteamProto::OnLoggedOn); + PushRequest(new LogonRequest(token.c_str()), &CSteamProto::OnLoggedOn); } -void CSteamProto::OnGotSession(const HttpResponse &response, void*) +void CSteamProto::OnGotSession(const HttpResponse &response, void *) { if (!response) { debugLogA(__FUNCTION__ ": failed to get session id"); @@ -335,7 +315,7 @@ void CSteamProto::HandleTokenExpired() return; } -void CSteamProto::OnLoggedOn(const HttpResponse &response, void*) +void CSteamProto::OnLoggedOn(const HttpResponse &response, void *) { if (!response.IsSuccess()) { // Probably timeout or no connection, we can do nothing here @@ -363,7 +343,7 @@ void CSteamProto::OnLoggedOn(const HttpResponse &response, void*) long messageId = root["umqid"].as_int(); setDword("MessageID", messageId); - + if (m_lastMessageTS <= 0) { time_t timestamp = _wtoi64(root["utc_timestamp"].as_mstring()); setDword("LastMessageTS", timestamp); @@ -373,14 +353,10 @@ void CSteamProto::OnLoggedOn(const HttpResponse &response, void*) ptrA token(getStringA("TokenSecret")); ptrA steamId(getStringA("SteamID")); - SendRequest( - new GetSessionRequest2(token, steamId), - &CSteamProto::OnGotSession); + SendRequest(new GetSessionRequest2(token, steamId), &CSteamProto::OnGotSession); // send this request immediately, so we can start polling thread with already loaded all contacts - SendRequest( - new GetFriendListRequest(token, steamId), - &CSteamProto::OnGotFriendList); + SendRequest(new GetFriendListRequest(token, steamId, "friend,ignoredfriend,requestrecipient"), &CSteamProto::OnGotFriendList); // go to online now ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus = m_iDesiredStatus); diff --git a/protocols/Steam/src/steam_menus.cpp b/protocols/Steam/src/steam_menus.cpp index b8f9aec6b6..aa51b0db71 100644 --- a/protocols/Steam/src/steam_menus.cpp +++ b/protocols/Steam/src/steam_menus.cpp @@ -22,11 +22,7 @@ INT_PTR CSteamProto::AuthRevokeCommand(WPARAM hContact, LPARAM) ptrA sessionId(getStringA("SessionID"));
ptrA steamId(getStringA("SteamID"));
char *who = getStringA(hContact, "SteamID");
- PushRequest(
- new RemoveFriendRequest(token, sessionId, steamId, who),
- &CSteamProto::OnFriendRemoved,
- (void*)who);
-
+ PushRequest(new RemoveFriendRequest(token, sessionId, steamId, who), &CSteamProto::OnFriendRemoved, who);
return 0;
}
@@ -36,12 +32,7 @@ int CSteamProto::BlockCommand(WPARAM hContact, LPARAM) ptrA sessionId(getStringA("SessionID"));
ptrA steamId(getStringA("SteamID"));
char *who = getStringA(hContact, "SteamID");
-
- PushRequest(
- new BlockFriendRequest(token, sessionId, steamId, who),
- &CSteamProto::OnFriendBlocked,
- who);
-
+ PushRequest(new BlockFriendRequest(token, sessionId, steamId, who), &CSteamProto::OnFriendBlocked, who);
return 0;
}
@@ -51,12 +42,7 @@ int CSteamProto::UnblockCommand(WPARAM hContact, LPARAM) ptrA sessionId(getStringA("SessionID"));
ptrA steamId(getStringA("SteamID"));
char *who = getStringA(hContact, "SteamID");
-
- PushRequest(
- new UnblockFriendRequest(token, sessionId, steamId, who),
- &CSteamProto::OnFriendUnblocked,
- who);
-
+ PushRequest(new UnblockFriendRequest(token, sessionId, steamId, who), &CSteamProto::OnFriendUnblocked, who);
return 0;
}
@@ -66,7 +52,6 @@ int CSteamProto::JoinToGameCommand(WPARAM hContact, LPARAM) DWORD gameId = getDword(hContact, "GameID", 0);
mir_snprintf(url, "steam://rungameid/%lu", gameId);
Utils_OpenUrl(url);
-
return 0;
}
@@ -74,10 +59,7 @@ INT_PTR CSteamProto::OpenBlockListCommand(WPARAM, LPARAM) {
ptrA token(getStringA("TokenSecret"));
ptrA steamId(getStringA("SteamID"));
- PushRequest(
- new GetFriendListRequest(token, steamId, "ignoredfriend"),
- &CSteamProto::OnGotBlockList);
-
+ PushRequest(new GetFriendListRequest(token, steamId, "ignoredfriend"), &CSteamProto::OnGotBlockList);
return 0;
}
@@ -101,7 +83,6 @@ int CSteamProto::OnPrebuildContactMenu(WPARAM hContact, LPARAM) DWORD gameId = getDword(hContact, "GameID", 0);
Menu_ShowItem(contactMenuItems[CMI_JOIN_GAME], gameId || ctrlPressed);
-
return 0;
}
diff --git a/protocols/Steam/src/steam_messages.cpp b/protocols/Steam/src/steam_messages.cpp index f2111e03aa..d06eb54de2 100644 --- a/protocols/Steam/src/steam_messages.cpp +++ b/protocols/Steam/src/steam_messages.cpp @@ -10,52 +10,44 @@ int CSteamProto::OnSendMessage(MCONTACT hContact, const char *message) {
UINT hMessage = InterlockedIncrement(&hMessageProcess);
- SendMessageParam *param = (SendMessageParam*)mir_calloc(sizeof(SendMessageParam));
+ SendMessageParam *param = (SendMessageParam *)mir_calloc(sizeof(SendMessageParam));
param->hContact = hContact;
param->hMessage = (HANDLE)hMessage;
ptrA token(getStringA("TokenSecret"));
ptrA umqid(getStringA("UMQID"));
ptrA steamId(getStringA(hContact, "SteamID"));
- PushRequest(
- new SendMessageRequest(token, umqid, steamId, message),
- &CSteamProto::OnMessageSent,
- param);
-
+ PushRequest(new SendMessageRequest(token, umqid, steamId, message), &CSteamProto::OnMessageSent, param);
return hMessage;
}
void CSteamProto::OnMessageSent(const HttpResponse &response, void *arg)
{
- SendMessageParam *param = (SendMessageParam*)arg;
+ SendMessageParam *param = (SendMessageParam *)arg;
std::string error = Translate("Unknown error");
ptrW steamId(getWStringA(param->hContact, "SteamID"));
time_t timestamp = NULL;
- if (response)
- {
+ if (response) {
JSONNode root = JSONNode::parse(response.Content);
- JSONNode node = root["error"];
- if (!node.isnull())
+ const JSONNode &node = root["error"];
+ if (node)
error = node.as_string();
- node = root["utc_timestamp"];
- if (!node.isnull())
- {
+ const JSONNode &time = root["utc_timestamp"];
+ if (time) {
timestamp = atol(node.as_string().c_str());
if (timestamp > getDword("LastMessageTS", 0))
setDword("LastMessageTS", timestamp);
}
}
- if (mir_strcmpi(error.c_str(), "OK") != 0)
- {
+ if (mir_strcmpi(error.c_str(), "OK") != 0) {
debugLogA(__FUNCTION__ ": failed to send message for %s (%s)", steamId, error.c_str());
ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hMessage, _A2T(error.c_str()));
}
- else
- {
+ else {
// remember server time of this message
auto it = m_mpOutMessages.find(param->hMessage);
if (it == m_mpOutMessages.end() && timestamp != NULL)
@@ -69,13 +61,12 @@ void CSteamProto::OnMessageSent(const HttpResponse &response, void *arg) int CSteamProto::OnPreCreateMessage(WPARAM, LPARAM lParam)
{
- MessageWindowEvent *evt = (MessageWindowEvent*)lParam;
+ MessageWindowEvent *evt = (MessageWindowEvent *)lParam;
if (mir_strcmp(GetContactProto(evt->hContact), m_szModuleName))
return 0;
auto it = m_mpOutMessages.find((HANDLE)evt->seq);
- if (it != m_mpOutMessages.end())
- {
+ if (it != m_mpOutMessages.end()) {
evt->dbei->timestamp = it->second;
m_mpOutMessages.erase(it);
}
@@ -88,11 +79,10 @@ int CSteamProto::UserIsTyping(MCONTACT hContact, int type) // NOTE: Steam doesn't support sending "user stopped typing" so we're sending only positive info
if (type == PROTOTYPE_SELFTYPING_OFF)
return 0;
-
+
ptrA token(getStringA("TokenSecret"));
ptrA umqid(getStringA("UMQID"));
ptrA steamId(getStringA(hContact, "SteamID"));
PushRequest(new SendTypingRequest(token, umqid, steamId));
-
return 0;
}
diff --git a/protocols/Steam/src/steam_options.cpp b/protocols/Steam/src/steam_options.cpp index 3c0197d400..62728a2cae 100644 --- a/protocols/Steam/src/steam_options.cpp +++ b/protocols/Steam/src/steam_options.cpp @@ -71,7 +71,7 @@ bool CSteamOptionsBlockList::OnInitDialog() return true;
}
-void CSteamOptionsBlockList::OnBlock(CCtrlButton*)
+void CSteamOptionsBlockList::OnBlock(CCtrlButton *)
{
}
@@ -93,4 +93,4 @@ int CSteamProto::OnOptionsInit(WPARAM wParam, LPARAM) //g_plugin.addOptions(wParam, &odp);
return 0;
-}
\ No newline at end of file +}
diff --git a/protocols/Steam/src/steam_polling.cpp b/protocols/Steam/src/steam_polling.cpp index bd0cdaf8dd..299b79c1a1 100644 --- a/protocols/Steam/src/steam_polling.cpp +++ b/protocols/Steam/src/steam_polling.cpp @@ -4,16 +4,46 @@ void CSteamProto::ParsePollData(const JSONNode &data) { std::string steamIds; - for (const JSONNode &item : data) { + for (auto &item : data) { json_string steamId = item["steamid_from"].as_string(); + json_string type = item["type"].as_string(); time_t timestamp = _wtol(item["utc_timestamp"].as_mstring()); - MCONTACT hContact = NULL; - if (!IsMe(steamId.c_str()) && !(hContact = GetContact(steamId.c_str()))) - // probably this is info about random player playing on same server, so we ignore it + bool bIsMe = IsMe(steamId.c_str()); + MCONTACT hContact = (bIsMe) ? 0 : GetContact(steamId.c_str()); + + if (type == "personarelationship") { + PersonaRelationshipAction state = (PersonaRelationshipAction)item["persona_state"].as_int(); + switch (state) { + case PersonaRelationshipAction::Remove: + if (hContact) + ContactIsRemoved(hContact); + break; + + case PersonaRelationshipAction::Ignore: + if (hContact) + ContactIsBlocked(hContact); + break; + + case PersonaRelationshipAction::AuthRequest: + hContact = AddContact(steamId.c_str()); + if (hContact) + ContactIsAskingAuth(hContact); + break; + + case PersonaRelationshipAction::AuthRequested: + if (hContact) + ContactIsFriend(hContact); + break; + } + + continue; + } + + // probably this is a packet from random player playing on the same server, so we ignore it + if (!bIsMe && !hContact) continue; - json_string type = item["type"].as_string(); if (type == "my_saytext" || type =="my_emote") { json_string text = item["text"].as_string(); @@ -55,8 +85,8 @@ void CSteamProto::ParsePollData(const JSONNode &data) if (type == "personastate") { if (!IsMe(steamId.c_str())) { // there no sense to change own status - JSONNode node = item["persona_state"]; - if (!node.isnull()) { + const JSONNode &node = item["persona_state"]; + if (node) { int status = SteamToMirandaStatus((PersonaState)node.as_int()); SetContactStatus(hContact, status); } @@ -66,44 +96,6 @@ void CSteamProto::ParsePollData(const JSONNode &data) continue; } - if (type == "personarelationship") { - PersonaRelationshipAction state = (PersonaRelationshipAction)item["persona_state"].as_int(); - switch (state) { - case PersonaRelationshipAction::Remove: - hContact = GetContact(steamId.c_str()); - if (hContact) - ContactIsRemoved(hContact); - break; - - case PersonaRelationshipAction::Ignore: - hContact = GetContact(steamId.c_str()); - if (hContact) - ContactIsBlocked(hContact); - break; - - case PersonaRelationshipAction::AuthRequest: - hContact = AddContact(steamId.c_str()); - if (hContact) - ContactIsAskingAuth(hContact); - else { - // load info about this user from server - ptrA token(getStringA("TokenSecret")); - PushRequest( - new GetUserSummariesRequest(token, steamId.c_str()), - &CSteamProto::OnAuthRequested); - } - break; - - case PersonaRelationshipAction::AuthRequested: - hContact = GetContact(steamId.c_str()); - if (hContact) - ContactIsFriend(hContact); - break; - } - - continue; - } - if (type == "leftconversation") { if (!getBool("ShowChatEvents", true)) continue; @@ -176,7 +168,7 @@ void CSteamProto::OnGotPoll(const HttpResponse &response, void *arg) } JSONNode root = JSONNode::parse(response.Content); - if (root.isnull()) { + if (!root) { debugLogA(__FUNCTION__ ": could not recognize a response"); param->errors++; return; @@ -205,8 +197,7 @@ void CSteamProto::OnGotPoll(const HttpResponse &response, void *arg) long messageId = root["messagelast"].as_int(); setDword("MessageID", messageId); - JSONNode data = root["messages"].as_array(); - ParsePollData(data); + ParsePollData(root["messages"]); // Reset error counter only when we've got OK param->errors = 0; @@ -223,9 +214,7 @@ void CSteamProto::OnGotPoll(const HttpResponse &response, void *arg) // try to reconnect only when we're actually online (during normal logout we will still got this error anyway, but in that case our status is already offline) if (IsOnline()) { ptrA token(getStringA("TokenSecret")); - SendRequest( - new LogonRequest(token), - &CSteamProto::OnReLogin); + SendRequest(new LogonRequest(token), &CSteamProto::OnReLogin); } return; } @@ -250,10 +239,7 @@ void CSteamProto::PollingThread(void*) // request->nlc = m_pollingConnection; ptrA umqId(getStringA("UMQID")); UINT32 messageId = getDword("MessageID", 0); - SendRequest( - new PollRequest(token, umqId, messageId, IdleSeconds()), - &CSteamProto::OnGotPoll, - (void*)¶m); + SendRequest(new PollRequest(token, umqId, messageId, IdleSeconds()), &CSteamProto::OnGotPoll, ¶m); } if (IsOnline()) { diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp index f45385e486..143a26e444 100644 --- a/protocols/Steam/src/steam_proto.cpp +++ b/protocols/Steam/src/steam_proto.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" -CSteamProto::CSteamProto(const char* protoName, const wchar_t* userName) +CSteamProto::CSteamProto(const char *protoName, const wchar_t *userName) : PROTO<CSteamProto>(protoName, userName), m_requestQueue(1), hAuthProcess(1), hMessageProcess(1) { @@ -95,11 +95,10 @@ CSteamProto::~CSteamProto() MCONTACT CSteamProto::AddToList(int, PROTOSEARCHRESULT *psr) { - _T2A steamId(psr->id.w); - MCONTACT hContact = AddContact(steamId, psr->nick.w, true); + MCONTACT hContact = AddContact(_T2A(psr->id.w), psr->nick.w, true); if (psr->cbSize == sizeof(STEAM_SEARCH_RESULT)) { - STEAM_SEARCH_RESULT *ssr = (STEAM_SEARCH_RESULT*)psr; + STEAM_SEARCH_RESULT *ssr = (STEAM_SEARCH_RESULT *)psr; UpdateContactDetails(hContact, *ssr->data); } @@ -218,7 +217,7 @@ HANDLE CSteamProto::SearchBasic(const wchar_t* id) return (HANDLE)STEAM_SEARCH_BYID; } -HANDLE CSteamProto::SearchByName(const wchar_t* nick, const wchar_t* firstName, const wchar_t* lastName) +HANDLE CSteamProto::SearchByName(const wchar_t *nick, const wchar_t *firstName, const wchar_t *lastName) { if (!IsOnline()) return nullptr; @@ -316,14 +315,14 @@ void CSteamProto::GetAwayMsgThread(void *arg) MCONTACT hContact = (UINT_PTR)arg; CMStringW message(db_get_wsm(hContact, "CList", "StatusMsg")); - + // if contact has no status message, get xstatus message if (message.IsEmpty()) { ptrW xStatusName(getWStringA(hContact, "XStatusName")); ptrW xStatusMsg(getWStringA(hContact, "XStatusMsg")); if (xStatusName) - message.AppendFormat(L"%s: %s", xStatusName, xStatusMsg); + message.AppendFormat(L"%s: %s", xStatusName.get(), xStatusMsg.get()); else message.Append(xStatusMsg); } diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index 9fe393f51b..2fe4b12f36 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -36,11 +36,17 @@ struct RequestQueueItem void *param;
RequestQueueItem(HttpRequest *request)
- : request(request), httpCallback(nullptr), jsonCallback(nullptr), param(nullptr) {}
+ : request(request), httpCallback(nullptr), jsonCallback(nullptr), param(nullptr)
+ {
+ }
RequestQueueItem(HttpRequest *request, HttpCallback callback, void *param)
- : request(request), httpCallback(callback), jsonCallback(nullptr), param(param) {}
+ : request(request), httpCallback(callback), jsonCallback(nullptr), param(param)
+ {
+ }
RequestQueueItem(HttpRequest *request, JsonCallback callback, void *param)
- : request(request), httpCallback(nullptr), jsonCallback(callback), param(param) {}
+ : request(request), httpCallback(nullptr), jsonCallback(callback), param(param)
+ {
+ }
};
class CSteamProto : public PROTO<CSteamProto>
@@ -126,7 +132,7 @@ protected: // login
bool IsOnline();
bool IsMe(const char *steamId);
-
+
void Login();
void Logout();
@@ -183,7 +189,7 @@ protected: void OnSearchByNameStarted(const HttpResponse &response, void *arg);
// messages
- int OnSendMessage(MCONTACT hContact, const char* message);
+ int OnSendMessage(MCONTACT hContact, const char *message);
void OnMessageSent(const HttpResponse &response, void *arg);
int __cdecl OnPreCreateMessage(WPARAM, LPARAM lParam);
@@ -244,7 +250,8 @@ protected: INT_PTR __cdecl OnGetEventTextChatStates(WPARAM wParam, LPARAM lParam);
// helpers
- inline int IdleSeconds() {
+ inline int IdleSeconds()
+ {
// Based on idle time we report Steam server will mark us as online/away/snooze
switch (m_iStatus) {
case ID_STATUS_AWAY:
@@ -284,4 +291,4 @@ struct CMPlugin : public ACCPROTOPLUGIN<CSteamProto> int OnReloadIcons(WPARAM wParam, LPARAM lParam);
void SetContactExtraIcon(MCONTACT hContact, int status);
-#endif //_STEAM_PROTO_H_
\ No newline at end of file +#endif //_STEAM_PROTO_H_
diff --git a/protocols/Steam/src/steam_utils.cpp b/protocols/Steam/src/steam_utils.cpp index cf00c1653e..e4a45e7dbe 100644 --- a/protocols/Steam/src/steam_utils.cpp +++ b/protocols/Steam/src/steam_utils.cpp @@ -2,8 +2,7 @@ WORD CSteamProto::SteamToMirandaStatus(PersonaState state)
{
- switch (state)
- {
+ switch (state) {
case PersonaState::Offline:
return ID_STATUS_OFFLINE;
case PersonaState::Online:
@@ -24,8 +23,7 @@ WORD CSteamProto::SteamToMirandaStatus(PersonaState state) PersonaState CSteamProto::MirandaToSteamState(int status)
{
- switch (status)
- {
+ switch (status) {
case ID_STATUS_OFFLINE:
return PersonaState::Offline;
case ID_STATUS_ONLINE:
@@ -71,8 +69,8 @@ INT_PTR CSteamProto::OnGetEventTextChatStates(WPARAM pEvent, LPARAM datatype) DBEVENTINFO *dbei = (DBEVENTINFO *)pEvent;
if (dbei->cbBlob > 0 && dbei->pBlob[0] == STEAM_DB_EVENT_CHATSTATES_GONE)
return (datatype == DBVT_WCHAR)
- ? (INT_PTR)mir_wstrdup(TranslateT("closed chat session"))
- : (INT_PTR)mir_strdup(Translate("closed chat session"));
+ ? (INT_PTR)mir_wstrdup(TranslateT("closed chat session"))
+ : (INT_PTR)mir_strdup(Translate("closed chat session"));
return NULL;
}
diff --git a/protocols/Steam/src/steam_xstatus.cpp b/protocols/Steam/src/steam_xstatus.cpp index 9acf06187f..167355f0d2 100644 --- a/protocols/Steam/src/steam_xstatus.cpp +++ b/protocols/Steam/src/steam_xstatus.cpp @@ -29,7 +29,7 @@ INT_PTR CSteamProto::OnGetXStatusEx(WPARAM wParam, LPARAM lParam) { MCONTACT hContact = (MCONTACT)wParam; - CUSTOM_STATUS *pData = (CUSTOM_STATUS*)lParam; + CUSTOM_STATUS *pData = (CUSTOM_STATUS *)lParam; if (pData->cbSize < sizeof(CUSTOM_STATUS)) return 1; @@ -38,8 +38,7 @@ INT_PTR CSteamProto::OnGetXStatusEx(WPARAM wParam, LPARAM lParam) *pData->status = GetContactXStatus(hContact); // fill status name member - if (pData->flags & CSSF_MASK_NAME) - { + if (pData->flags & CSSF_MASK_NAME) { int status = (pData->wParam == nullptr) ? GetContactXStatus(hContact) : *pData->wParam; if (status < 1) return 1; @@ -59,7 +58,7 @@ INT_PTR CSteamProto::OnGetXStatusEx(WPARAM wParam, LPARAM lParam) // fill status message member if (pData->flags & CSSF_MASK_MESSAGE) { ptrW message(getWStringA(hContact, "XStatusMsg")); - + if (pData->flags & CSSF_UNICODE) mir_wstrncpy(pData->ptszMessage, message, STATUS_DESC_MAX); else @@ -83,8 +82,10 @@ INT_PTR CSteamProto::OnGetXStatusEx(WPARAM wParam, LPARAM lParam) // data sizes if (pData->flags & CSSF_STR_SIZES) { - if (pData->wParam) *pData->wParam = STATUS_TITLE_MAX; - if (pData->lParam) *pData->lParam = STATUS_DESC_MAX; + if (pData->wParam) + *pData->wParam = STATUS_TITLE_MAX; + if (pData->lParam) + *pData->lParam = STATUS_DESC_MAX; } return 0; @@ -116,14 +117,11 @@ INT_PTR CSteamProto::OnGetXStatusIcon(WPARAM wParam, LPARAM lParam) INT_PTR CSteamProto::OnRequestAdvStatusIconIdx(WPARAM wParam, LPARAM) { int status = GetContactXStatus(wParam); - if (status) - { - if (std::find(xstatusIconsValid.begin(), xstatusIconsValid.end(), status) == xstatusIconsValid.end()) - { + if (status) { + if (std::find(xstatusIconsValid.begin(), xstatusIconsValid.end(), status) == xstatusIconsValid.end()) { // adding/updating icon HIMAGELIST clistImageList = Clist_GetImageList(); - if (clistImageList) - { + if (clistImageList) { HICON hXStatusIcon = GetXStatusIcon(status, LR_SHARED); std::map<int, int>::iterator it = xstatusIcons.find(status); @@ -139,13 +137,12 @@ INT_PTR CSteamProto::OnRequestAdvStatusIconIdx(WPARAM wParam, LPARAM) } } - if (std::find(xstatusIconsValid.begin(), xstatusIconsValid.end(), status) != xstatusIconsValid.end()) - { + if (std::find(xstatusIconsValid.begin(), xstatusIconsValid.end(), status) != xstatusIconsValid.end()) { std::map<int, int>::iterator it = xstatusIcons.find(status); if (it != xstatusIcons.end()) - return ((INT_PTR) it->second & 0xFFFF) << 16; + return ((INT_PTR)it->second & 0xFFFF) << 16; } } return -1; -}
\ No newline at end of file +} diff --git a/protocols/Steam/src/version.h b/protocols/Steam/src/version.h index 7c7ca89f97..6288301c5f 100644 --- a/protocols/Steam/src/version.h +++ b/protocols/Steam/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 11
#define __RELEASE_NUM 6
-#define __BUILD_NUM 5
+#define __BUILD_NUM 6
#include <stdver.h>
|