-
Notifications
You must be signed in to change notification settings - Fork 203
feature: add stats api #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #include "StatsClient.h" | ||
|
|
||
| #include "OSTPlatform/include/Http.h" | ||
| #include "OSTPlatform/include/Numbers.h" | ||
| #include "Utils/Config/Config.h" | ||
| #include "Utils/Logging/Log.h" | ||
|
|
||
| #include <cctype> | ||
| #include <cstdio> | ||
| #include <mutex> | ||
| #include <string_view> | ||
| #include <unordered_map> | ||
|
|
||
| namespace StatsClient { | ||
| namespace { | ||
|
|
||
| std::mutex g_mutex; | ||
| std::unordered_map<AppId_t, uint64_t> g_cache; | ||
|
|
||
| bool ParseSteamId(std::string_view body, uint64_t* outSteamId) { | ||
| const auto parsed = OSTPlatform::Numbers::ParseUInt64(body); | ||
| if (!parsed || *parsed == 0) return false; | ||
| *outSteamId = *parsed; | ||
| return true; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| bool FetchStatSteamId(AppId_t appId, uint64_t* outSteamId) { | ||
| if (!outSteamId || appId == k_uAppIdInvalid) return false; | ||
|
|
||
| if (!Config::GetStatsEnableApi()) { | ||
| LOG_ACHIEVEMENT_DEBUG("Stats SteamID API disabled for appid={}", appId); | ||
| return false; | ||
| } | ||
|
|
||
| { | ||
| std::lock_guard<std::mutex> lock(g_mutex); | ||
| auto it = g_cache.find(appId); | ||
| if (it != g_cache.end()) { | ||
| *outSteamId = it->second; | ||
| LOG_ACHIEVEMENT_DEBUG("Stats SteamID API cache hit appid={} steamid={}", appId, *outSteamId); | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| char url[128]; | ||
| std::snprintf(url, sizeof(url), "https://stats.opensteamtool.com/%u", appId); | ||
|
|
||
| auto r = OSTPlatform::Http::Execute(L"GET", url); | ||
| LOG_ACHIEVEMENT_INFO("Stats SteamID API status={} appid={}", r.status, appId); | ||
|
|
||
| if (!r.ok || r.status != 200) { | ||
| LOG_ACHIEVEMENT_WARN("Stats SteamID API failed appid={} status={} ok={}", appId, r.status, r.ok); | ||
| return false; | ||
| } | ||
|
|
||
| uint64_t steamId = 0; | ||
| if (!ParseSteamId(r.body, &steamId)) { | ||
| LOG_ACHIEVEMENT_WARN("Stats SteamID API returned invalid body appid={} bytes={}", appId, r.body.size()); | ||
| return false; | ||
| } | ||
|
|
||
| { | ||
| std::lock_guard<std::mutex> lock(g_mutex); | ||
| g_cache[appId] = steamId; | ||
| } | ||
|
|
||
| *outSteamId = steamId; | ||
| LOG_ACHIEVEMENT_INFO("Stats SteamID API resolved appid={} steamid={}", appId, steamId); | ||
| return true; | ||
| } | ||
|
|
||
| } // namespace StatsClient | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #pragma once | ||
|
|
||
| #include "Steam/Types.h" | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| namespace StatsClient { | ||
|
|
||
| bool FetchStatSteamId(AppId_t appId, uint64_t* outSteamId); | ||
|
|
||
| } // namespace StatsClient |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an unlocked app has no
setStatoverride and the stats API is enabled by default, this synchronous WinHTTP request runs insideLuaConfig::GetStatSteamId, which is called from the outgoing user-stats packet handlers before forwarding the packet. Ifstats.opensteamtool.comis slow or unreachable, each uncached app can stall Steam/game networking until the HTTP timeouts expire; failures are not cached, so the stall repeats on later stats requests. Consider resolving this asynchronously, prefetching, or caching failures/using much shorter configurable timeouts.Useful? React with 👍 / 👎.