From 1b9a0663b03e8225afe0f5f40a4949dbd4adc798 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 27 Dec 2024 19:49:45 +0300 Subject: Steam: fix for avatars fetching --- protocols/Steam/Steam.vcxproj | 1 - protocols/Steam/Steam.vcxproj.filters | 3 --- protocols/Steam/src/api/avatar.h | 13 ------------- protocols/Steam/src/stdafx.h | 1 - protocols/Steam/src/steam_avatars.cpp | 7 ++++--- protocols/Steam/src/steam_contacts.cpp | 11 +++++++---- protocols/Steam/src/steam_utils.cpp | 11 +++++++++++ protocols/Steam/src/steam_utils.h | 2 ++ 8 files changed, 24 insertions(+), 25 deletions(-) delete mode 100644 protocols/Steam/src/api/avatar.h diff --git a/protocols/Steam/Steam.vcxproj b/protocols/Steam/Steam.vcxproj index d70475e829..5049b6d579 100644 --- a/protocols/Steam/Steam.vcxproj +++ b/protocols/Steam/Steam.vcxproj @@ -91,7 +91,6 @@ - diff --git a/protocols/Steam/Steam.vcxproj.filters b/protocols/Steam/Steam.vcxproj.filters index 6f8d6f3a66..360efb6dde 100644 --- a/protocols/Steam/Steam.vcxproj.filters +++ b/protocols/Steam/Steam.vcxproj.filters @@ -128,9 +128,6 @@ Header Files\api - - Header Files\api - Header Files\api diff --git a/protocols/Steam/src/api/avatar.h b/protocols/Steam/src/api/avatar.h deleted file mode 100644 index 4140583ead..0000000000 --- a/protocols/Steam/src/api/avatar.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _STEAM_REQUEST_AVATAR_H_ -#define _STEAM_REQUEST_AVATAR_H_ - -struct GetAvatarRequest : public HttpRequest -{ - GetAvatarRequest(const char *url) : - HttpRequest(REQUEST_GET, url) - { - flags = NLHRF_HTTP11 | NLHRF_NODUMP; - } -}; - -#endif //_STEAM_REQUEST_AVATAR_H_ diff --git a/protocols/Steam/src/stdafx.h b/protocols/Steam/src/stdafx.h index 7dbc349381..48b7ac38d1 100644 --- a/protocols/Steam/src/stdafx.h +++ b/protocols/Steam/src/stdafx.h @@ -75,7 +75,6 @@ extern HANDLE hExtraXStatus; #include "steam_proto.h" #include "steam_utils.h" -#include "api/avatar.h" #include "api/captcha.h" #include "api/friend.h" #include "api/pending.h" diff --git a/protocols/Steam/src/steam_avatars.cpp b/protocols/Steam/src/steam_avatars.cpp index 022ec914c5..762a06d368 100644 --- a/protocols/Steam/src/steam_avatars.cpp +++ b/protocols/Steam/src/steam_avatars.cpp @@ -54,8 +54,8 @@ INT_PTR CSteamProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) PROTO_AVATAR_INFORMATION *pai = (PROTO_AVATAR_INFORMATION *)lParam; - ptrA avatarUrl(getStringA(pai->hContact, "AvatarUrl")); - if (!avatarUrl) + ptrA avatarHash(getStringA(pai->hContact, "AvatarHash")); + if (!avatarHash) return GAIR_NOAVATAR; if (GetDbAvatarInfo(*pai)) { @@ -68,7 +68,8 @@ INT_PTR CSteamProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) needLoad = (wParam & GAIF_FORCE) || !fileExist; if (needLoad) { - SendRequest(new GetAvatarRequest(avatarUrl), &CSteamProto::OnGotAvatar, (void *)pai->hContact); + CMStringA szUrl(FORMAT, "https://avatars.steamstatic.com/%s_full.jpg", avatarHash.get()); + SendRequest(new HttpRequest(REQUEST_GET, szUrl), &CSteamProto::OnGotAvatar, (void *)pai->hContact); return GAIR_WAITFOR; } if (fileExist) diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index da654dfa3e..901ea8d771 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -102,10 +102,13 @@ void CSteamProto::OnGotFriendInfo(const CMsgClientPersonaState &reply, const CMs // avatar if (F->avatar_hash.len != 0) { - CMStringA szHash; - szHash.Truncate(int(F->avatar_hash.len) * 2 + 1); - bin2hex(F->avatar_hash.data, F->avatar_hash.len, szHash.GetBuffer()); - CheckAvatarChange(hContact, szHash); + if (!IsNull(F->avatar_hash)) { + CMStringA szHash; + szHash.Truncate(int(F->avatar_hash.len) * 2 + 1); + bin2hex(F->avatar_hash.data, F->avatar_hash.len, szHash.GetBuffer()); + CheckAvatarChange(hContact, szHash); + } + else CheckAvatarChange(hContact, 0); } else CheckAvatarChange(hContact, 0); diff --git a/protocols/Steam/src/steam_utils.cpp b/protocols/Steam/src/steam_utils.cpp index 9666316ceb..b8b15f5db8 100644 --- a/protocols/Steam/src/steam_utils.cpp +++ b/protocols/Steam/src/steam_utils.cpp @@ -9,6 +9,17 @@ uint64_t getRandomInt() ///////////////////////////////////////////////////////////////////////////////////////// +bool IsNull(const ProtobufCBinaryData &buf) +{ + for (auto i = 0; i < buf.len; i++) + if (buf.data[i] != 0) + return false; + + return true; +} + +///////////////////////////////////////////////////////////////////////////////////////// + MBinBuffer createMachineID(const char *accName) { uint8_t hashOut[MIR_SHA1_HASH_SIZE]; diff --git a/protocols/Steam/src/steam_utils.h b/protocols/Steam/src/steam_utils.h index 29ac97b1e2..6762f89f99 100644 --- a/protocols/Steam/src/steam_utils.h +++ b/protocols/Steam/src/steam_utils.h @@ -12,6 +12,8 @@ MBinBuffer createMachineID(const char *accName); #define now() time(0) +bool IsNull(const ProtobufCBinaryData &buf); + uint64_t getRandomInt(); CMStringA protobuf_c_text_to_string(const ProtobufCMessage &msg); -- cgit v1.2.3