diff --git a/src/data/context/EmulatorContext.cpp b/src/data/context/EmulatorContext.cpp index 3d81cc16..2cd44928 100644 --- a/src/data/context/EmulatorContext.cpp +++ b/src/data/context/EmulatorContext.cpp @@ -203,6 +203,13 @@ void EmulatorContext::UpdateUserAgent() ra::services::ServiceLocator::GetMutable().SetUserAgent(sUserAgent); } +std::string EmulatorContext::GetUserAgentClause() const +{ + std::string sClause = "Integration/"; + AppendIntegrationVersion(sClause); + return sClause; +} + static unsigned long long ParseVersion(const char* sVersion) { Expects(sVersion != nullptr); diff --git a/src/data/context/EmulatorContext.hh b/src/data/context/EmulatorContext.hh index 5f18f070..966b5a9c 100644 --- a/src/data/context/EmulatorContext.hh +++ b/src/data/context/EmulatorContext.hh @@ -66,6 +66,10 @@ public: /// void SetClientUserAgentDetail(const std::string& sDetail) { m_sClientUserAgentDetail = sDetail; UpdateUserAgent(); } + /// + /// Gets the Integration/X.X.X.X portion of the User-Agent clause. + /// + std::string GetUserAgentClause() const; /// /// Prompts the user to confirm disabling hardcore mode to perform some activity. diff --git a/src/services/AchievementRuntimeExports.cpp b/src/services/AchievementRuntimeExports.cpp index 06501464..cefbab82 100644 --- a/src/services/AchievementRuntimeExports.cpp +++ b/src/services/AchievementRuntimeExports.cpp @@ -100,6 +100,13 @@ class AchievementRuntimeExports : private AchievementRuntime pConfiguration->SetHost(value); } + static size_t get_user_agent_clause(char buffer[], size_t buffer_size) + { + auto& pEmulatorContext = ra::services::ServiceLocator::GetMutable(); + const auto sUserAgent = pEmulatorContext.GetUserAgentClause(); + return snprintf(buffer, buffer_size, "%s", sUserAgent.c_str()); + } + static bool IsUpdatingHardcore() noexcept { return s_bUpdatingHardcore; } static void set_hardcore_enabled(int value) @@ -892,6 +899,7 @@ static void GetExternalClientV1(rc_client_external_t* pClientExternal) noexcept pClientExternal->set_read_memory = ra::services::AchievementRuntimeExports::set_read_memory; pClientExternal->set_get_time_millisecs = ra::services::AchievementRuntimeExports::set_get_time_millisecs; pClientExternal->set_host = ra::services::AchievementRuntimeExports::set_host; + pClientExternal->get_user_agent_clause = ra::services::AchievementRuntimeExports::get_user_agent_clause; pClientExternal->set_hardcore_enabled = ra::services::AchievementRuntimeExports::set_hardcore_enabled; pClientExternal->get_hardcore_enabled = ra::services::AchievementRuntimeExports::get_hardcore_enabled; diff --git a/tests/services/AchievementRuntimeExports_Tests.cpp b/tests/services/AchievementRuntimeExports_Tests.cpp index 25fae9ef..cae37050 100644 --- a/tests/services/AchievementRuntimeExports_Tests.cpp +++ b/tests/services/AchievementRuntimeExports_Tests.cpp @@ -15,6 +15,7 @@ #include #include "Exports.hh" +#include "RA_BuildVer.h" #include "RA_Resource.h" // the exported functions are not defined in a header anywhere. the only thing that should normally be @@ -224,6 +225,7 @@ TEST_CLASS(AchievementRuntimeExports_Tests) Assert::IsNotNull((void*)pClient.set_read_memory, L"set_read_memory not set"); Assert::IsNotNull((void*)pClient.set_get_time_millisecs, L"set_get_time_millisecs not set"); Assert::IsNotNull((void*)pClient.set_host, L"set_host not set"); + Assert::IsNotNull((void*)pClient.get_user_agent_clause, L"set_host not set"); Assert::IsNotNull((void*)pClient.set_hardcore_enabled, L"set_hardcore_enabled not set"); Assert::IsNotNull((void*)pClient.get_hardcore_enabled, L"get_hardcore_enabled not set"); @@ -425,6 +427,25 @@ TEST_CLASS(AchievementRuntimeExports_Tests) runtime.AssertResetEventSeen(); } + + TEST_METHOD(TestUserAgentClause) + { + AchievementRuntimeExportsHarness runtime; + + rc_client_external_t pClient; + memset(&pClient, 0, sizeof(pClient)); + _Rcheevos_GetExternalClient(&pClient, 1); + + char buffer[32]; + Assert::IsTrue(pClient.get_user_agent_clause(buffer, 8) > 8); + Assert::AreEqual("Integra", buffer); + + pClient.get_user_agent_clause(buffer, 32); + char* ptr = strchr(buffer, '-'); + if (ptr != nullptr) + *ptr = '\0'; + Assert::AreEqual("Integration/" RA_INTEGRATION_VERSION, buffer); + } }; } // namespace tests