From a17538fc10c6dc15cf4585a10a59bc45f35654fa Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 25 Dec 2024 13:48:29 +0300 Subject: fixes #4811 (Steam: Add now playing game title support) --- protocols/Steam/src/api/app_info.h | 4 ++-- protocols/Steam/src/main.cpp | 14 +++++++++++--- protocols/Steam/src/steam_contacts.cpp | 28 ++++++++++++---------------- protocols/Steam/src/steam_proto.cpp | 25 ------------------------- protocols/Steam/src/steam_xstatus.cpp | 5 +---- 5 files changed, 26 insertions(+), 50 deletions(-) (limited to 'protocols/Steam/src') diff --git a/protocols/Steam/src/api/app_info.h b/protocols/Steam/src/api/app_info.h index cf54e52adf..d8a187d444 100644 --- a/protocols/Steam/src/api/app_info.h +++ b/protocols/Steam/src/api/app_info.h @@ -3,10 +3,10 @@ struct GetAppInfoRequest : public HttpRequest { - GetAppInfoRequest(const char *token, const char *appIds) : + GetAppInfoRequest(const char *token, uint32_t appId) : HttpRequest(REQUEST_GET, "/ISteamGameOAuth/GetAppInfo/v0001") { - this << CHAR_PARAM("access_token", token) << CHAR_PARAM("appIds", appIds); + this << CHAR_PARAM("access_token", token) << INT_PARAM("appIds", appId); } //{ diff --git a/protocols/Steam/src/main.cpp b/protocols/Steam/src/main.cpp index fcb3b1b9d9..5be2f85902 100644 --- a/protocols/Steam/src/main.cpp +++ b/protocols/Steam/src/main.cpp @@ -169,14 +169,22 @@ void CMPlugin::InitSteamServices() serviceHandlers[NotificationReceived] = ServiceResponseHandler(&CSteamProto::OnGotNotification); } +///////////////////////////////////////////////////////////////////////////////////////// + +static IconItem iconList[] = { + { LPGEN("Protocol icon"), "main", IDI_STEAM }, + { LPGEN("Gaming icon"), "gaming", IDI_GAMING }, +}; + int CMPlugin::Load() { InitSteamServices(); + // icons + g_plugin.registerIcon("Protocols/" MODULE, iconList, MODULE); + // extra statuses - char iconName[100]; - mir_snprintf(iconName, "%s_%s", MODULE, "gaming"); - hExtraXStatus = ExtraIcon_RegisterIcolib("steam_game", LPGEN("Steam game"), iconName); + hExtraXStatus = ExtraIcon_RegisterIcolib("steam_game", LPGEN("Steam game"), g_plugin.getIconHandle(IDI_GAMING)); HookEvent(ME_SKIN_ICONSCHANGED, OnReloadIcons); diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index 9a0cd603a6..5886f262c4 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -28,7 +28,7 @@ void CSteamProto::SetContactStatus(MCONTACT hContact, uint16_t status) // if contact is offline, remove played game info delSetting(hContact, "GameID"); delSetting(hContact, "ServerIP"); - delSetting(hContact, "ServerID"); + // clear also xstatus delSetting(hContact, "XStatusId"); delSetting(hContact, "XStatusName"); @@ -160,26 +160,23 @@ void CSteamProto::OnGotFriendInfo(const CMsgClientPersonaState &reply, const CMs } // playing game - /* - json_string appId = data["gameid"].as_string(); - CMStringW gameInfo = data["gameextrainfo"].as_mstring(); - if (!appId.empty() || !gameInfo.IsEmpty()) { - uint32_t gameId = atol(appId.c_str()); - json_string serverIP = data["gameserverip"].as_string(); - json_string serverID = data["gameserversteamid"].as_string(); + auto gameId = F->has_game_played_app_id ? F->game_played_app_id : 0; + char *gameInfo = F->game_name; + if (gameId && gameInfo) { + in_addr in; in.S_un.S_addr = F->game_server_ip; + auto *serverIP = inet_ntoa(in); setDword(hContact, "GameID", gameId); - setString(hContact, "ServerIP", serverIP.c_str()); - setString(hContact, "ServerID", serverID.c_str()); + setString(hContact, "ServerIP", serverIP); CMStringW message(gameInfo); if (gameId && message.IsEmpty()) - SendRequest(new GetAppInfoRequest(m_szAccessToken, appId.c_str()), &CSteamProto::OnGotAppInfo, (void *)hContact); + SendRequest(new GetAppInfoRequest(m_szAccessToken, gameId), &CSteamProto::OnGotAppInfo, (void *)hContact); else { if (!gameId) message.Append(TranslateT(" (Non-Steam)")); - if (!serverIP.empty()) - message.AppendFormat(TranslateT(" on server %S"), serverIP.c_str()); + if (serverIP) + message.AppendFormat(TranslateT(" on server %S"), serverIP); } setDword(hContact, "XStatusId", gameId); @@ -188,17 +185,16 @@ void CSteamProto::OnGotFriendInfo(const CMsgClientPersonaState &reply, const CMs SetContactExtraIcon(hContact, gameId); } - else {*/ + else { delSetting(hContact, "GameID"); delSetting(hContact, "ServerIP"); - delSetting(hContact, "ServerID"); delSetting(hContact, "XStatusId"); delSetting(hContact, "XStatusName"); delSetting(hContact, "XStatusMsg"); SetContactExtraIcon(hContact, NULL); - // } + } } } diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp index 2fcbfb72f3..cd95b072e2 100644 --- a/protocols/Steam/src/steam_proto.cpp +++ b/protocols/Steam/src/steam_proto.cpp @@ -7,30 +7,6 @@ CSteamProto::CSteamProto(const char *protoName, const wchar_t *userName) : m_wszGroupName(this, "DefaultGroup", L"Steam"), m_wszDeviceName(this, "DeviceName", L"Miranda NG") { - // icons - wchar_t filePath[MAX_PATH]; - GetModuleFileName(g_plugin.getInst(), filePath, MAX_PATH); - - wchar_t sectionName[100]; - mir_snwprintf(sectionName, L"%s/%s", LPGENW("Protocols"), _A2W(MODULE)); - - char settingName[100]; - mir_snprintf(settingName, "%s_%s", MODULE, "main"); - - SKINICONDESC sid = {}; - sid.flags = SIDF_ALL_UNICODE; - sid.defaultFile.w = filePath; - sid.pszName = settingName; - sid.section.w = sectionName; - sid.description.w = LPGENW("Protocol icon"); - sid.iDefaultIndex = -IDI_STEAM; - g_plugin.addIcon(&sid); - - mir_snprintf(settingName, "%s_%s", MODULE, "gaming"); - sid.description.w = LPGENW("Gaming icon"); - sid.iDefaultIndex = -IDI_GAMING; - g_plugin.addIcon(&sid); - // temporary DB settings db_set_resident(m_szModuleName, "XStatusId"); db_set_resident(m_szModuleName, "XStatusName"); @@ -38,7 +14,6 @@ CSteamProto::CSteamProto(const char *protoName, const wchar_t *userName) : db_set_resident(m_szModuleName, "IdleTS"); db_set_resident(m_szModuleName, "GameID"); db_set_resident(m_szModuleName, "ServerIP"); - db_set_resident(m_szModuleName, "ServerID"); SetAllContactStatuses(ID_STATUS_OFFLINE); diff --git a/protocols/Steam/src/steam_xstatus.cpp b/protocols/Steam/src/steam_xstatus.cpp index 167355f0d2..0594be7665 100644 --- a/protocols/Steam/src/steam_xstatus.cpp +++ b/protocols/Steam/src/steam_xstatus.cpp @@ -19,10 +19,7 @@ int CSteamProto::GetContactXStatus(MCONTACT hContact) void SetContactExtraIcon(MCONTACT hContact, int status) { - char iconName[100]; - mir_snprintf(iconName, "%s_%s", MODULE, "gaming"); - - ExtraIcon_SetIcon(hExtraXStatus, hContact, (status > 0) ? IcoLib_GetIconHandle(iconName) : nullptr); + ExtraIcon_SetIcon(hExtraXStatus, hContact, (status > 0) ? g_plugin.getIconHandle(IDI_GAMING) : nullptr); } INT_PTR CSteamProto::OnGetXStatusEx(WPARAM wParam, LPARAM lParam) -- cgit v1.2.3