Repository: RetroAchievements/RAIntegration
Pull request #739 (2021-05-27 15:09:34)

show error when invalid RP is the only RP available
When adding the initial rich presence to a game, if an error is present, the monitor would not report the error and would not start watching the file. If an error was introduced after the monitor started watching the file, it would be reported normally. This fixes the first case so an error can be reported on initial load of the rich presence script.


Patch:
diff --git a/src/api/impl/ConnectedServer.cpp b/src/api/impl/ConnectedServer.cpp
index aaa2bd57..156942fb 100644
--- a/src/api/impl/ConnectedServer.cpp
+++ b/src/api/impl/ConnectedServer.cpp
@@ -497,7 +497,7 @@ Login::Response ConnectedServer::Login(const Login::Request& request)
 
     rc_api_destroy_request(&api_request);
 
-    return std::move(response);
+    return response;
 }
 
 Logout::Response ConnectedServer::Logout(const Logout::Request&)
@@ -541,7 +541,7 @@ StartSession::Response ConnectedServer::StartSession(const StartSession::Request
 
     rc_api_destroy_request(&api_request);
 
-    return std::move(response);
+    return response;
 }
 
 Ping::Response ConnectedServer::Ping(const Ping::Request& request)
@@ -582,7 +582,7 @@ Ping::Response ConnectedServer::Ping(const Ping::Request& request)
 
     rc_api_destroy_request(&api_request);
 
-    return std::move(response);
+    return response;
 }
 
 FetchUserUnlocks::Response ConnectedServer::FetchUserUnlocks(const FetchUserUnlocks::Request& request)
@@ -622,7 +622,7 @@ FetchUserUnlocks::Response ConnectedServer::FetchUserUnlocks(const FetchUserUnlo
 
     rc_api_destroy_request(&api_request);
 
-    return std::move(response);
+    return response;
 }
 
 AwardAchievement::Response ConnectedServer::AwardAchievement(const AwardAchievement::Request& request)
@@ -664,7 +664,7 @@ AwardAchievement::Response ConnectedServer::AwardAchievement(const AwardAchievem
 
     rc_api_destroy_request(&api_request);
 
-    return std::move(response);
+    return response;
 }
 
 SubmitLeaderboardEntry::Response ConnectedServer::SubmitLeaderboardEntry(const SubmitLeaderboardEntry::Request& request)
@@ -718,7 +718,7 @@ SubmitLeaderboardEntry::Response ConnectedServer::SubmitLeaderboardEntry(const S
 
     rc_api_destroy_request(&api_request);
 
-    return std::move(response);
+    return response;
 }
 
 FetchUserFriends::Response ConnectedServer::FetchUserFriends(const FetchUserFriends::Request&)
@@ -758,7 +758,7 @@ FetchUserFriends::Response ConnectedServer::FetchUserFriends(const FetchUserFrie
         }
     }
 
-    return std::move(response);
+    return response;
 }
 
 ResolveHash::Response ConnectedServer::ResolveHash(const ResolveHash::Request& request)
@@ -795,7 +795,7 @@ ResolveHash::Response ConnectedServer::ResolveHash(const ResolveHash::Request& r
 
     rc_api_destroy_request(&api_request);
 
-    return std::move(response);
+    return response;
 }
 
 FetchGameData::Response ConnectedServer::FetchGameData(const FetchGameData::Request& request)
@@ -848,7 +848,7 @@ FetchGameData::Response ConnectedServer::FetchGameData(const FetchGameData::Requ
 
     rc_api_destroy_request(&api_request);
 
-    return std::move(response);
+    return response;
 }
 
 void ConnectedServer::ProcessGamePatchData(ra::api::FetchGameData::Response &response, const ra::services::Http::Response& httpResponse)
@@ -931,7 +931,7 @@ FetchCodeNotes::Response ConnectedServer::FetchCodeNotes(const FetchCodeNotes::R
         }
     }
 
-    return std::move(response);
+    return response;
 }
 
 void ConnectedServer::ProcessCodeNotes(ra::api::FetchCodeNotes::Response &response, const rapidjson::Value& CodeNotes)
@@ -968,7 +968,7 @@ UpdateCodeNote::Response ConnectedServer::UpdateCodeNote(const UpdateCodeNote::R
         response.Result = ApiResult::Success;
     }
 
-    return std::move(response);
+    return response;
 }
 
 DeleteCodeNote::Response ConnectedServer::DeleteCodeNote(const DeleteCodeNote::Request& request)
@@ -985,7 +985,7 @@ DeleteCodeNote::Response ConnectedServer::DeleteCodeNote(const DeleteCodeNote::R
         response.Result = ApiResult::Success;
     }
 
-    return std::move(response);
+    return response;
 }
 
 UpdateAchievement::Response ConnectedServer::UpdateAchievement(const UpdateAchievement::Request& request)
@@ -1015,7 +1015,7 @@ UpdateAchievement::Response ConnectedServer::UpdateAchievement(const UpdateAchie
         GetRequiredJsonField(response.AchievementId, document, "AchievementID", response);
     }
 
-    return std::move(response);
+    return response;
 }
 
 FetchAchievementInfo::Response ConnectedServer::FetchAchievementInfo(const FetchAchievementInfo::Request& request)
@@ -1076,7 +1076,7 @@ FetchAchievementInfo::Response ConnectedServer::FetchAchievementInfo(const Fetch
         }
     }
 
-    return std::move(response);
+    return response;
 }
 
 FetchLeaderboardInfo::Response ConnectedServer::FetchLeaderboardInfo(const FetchLeaderboardInfo::Request& request)
@@ -1137,7 +1137,7 @@ FetchLeaderboardInfo::Response ConnectedServer::FetchLeaderboardInfo(const Fetch
         }
     }
 
-    return std::move(response);
+    return response;
 }
 
 LatestClient::Response ConnectedServer::LatestClient(const LatestClient::Request& request)
diff --git a/src/api/impl/OfflineServer.cpp b/src/api/impl/OfflineServer.cpp
index d28d3f4b..8c651f49 100644
--- a/src/api/impl/OfflineServer.cpp
+++ b/src/api/impl/OfflineServer.cpp
@@ -17,14 +17,14 @@ Login::Response OfflineServer::Login(const Login::Request& request)
     response.Result = ApiResult::Success;
     response.Username = request.Username;
     response.ApiToken = "offlineToken";
-    return std::move(response);
+    return response;
 }
 
 Logout::Response OfflineServer::Logout(const Logout::Request&) noexcept
 {
     Logout::Response response;
     response.Result = ApiResult::Success;
-    return std::move(response);
+    return response;
 }
 
 FetchGameData::Response OfflineServer::FetchGameData(const FetchGameData::Request& request)
@@ -57,7 +57,7 @@ FetchGameData::Response OfflineServer::FetchGameData(const FetchGameData::Reques
         ConnectedServer::ProcessGamePatchData(response, httpResponse);
     }
 
-    return std::move(response);
+    return response;
 }
 
 FetchCodeNotes::Response OfflineServer::FetchCodeNotes(const FetchCodeNotes::Request& request)
@@ -85,7 +85,7 @@ FetchCodeNotes::Response OfflineServer::FetchCodeNotes(const FetchCodeNotes::Req
         ConnectedServer::ProcessCodeNotes(response, document);
     }
 
-    return std::move(response);
+    return response;
 }
 
 } // namespace impl
diff --git a/src/services/AchievementRuntime.hh b/src/services/AchievementRuntime.hh
index a01f4228..05b048a1 100644
--- a/src/services/AchievementRuntime.hh
+++ b/src/services/AchievementRuntime.hh
@@ -115,7 +115,16 @@ public:
         if (!m_bInitialized)
             return false;
 
-        return (m_pRuntime.richpresence != nullptr && m_pRuntime.richpresence->richpresence != nullptr);
+        /* valid rich presence */
+        if (m_pRuntime.richpresence != nullptr && m_pRuntime.richpresence->richpresence != nullptr)
+            return true;
+
+        /* invalid rich presence */
+        if (m_nRichPresenceParseResult != RC_OK)
+            return true;
+
+        /* no rich presence */
+        return false;
     }
 
     /// <summary>


Test patch:
diff --git a/tests/services/AchievementRuntime_Tests.cpp b/tests/services/AchievementRuntime_Tests.cpp
index 3d24ebd4..01a988a9 100644
--- a/tests/services/AchievementRuntime_Tests.cpp
+++ b/tests/services/AchievementRuntime_Tests.cpp
@@ -881,9 +881,11 @@ public:
 
         AchievementRuntimeHarness runtime;
         runtime.mockEmulatorContext.MockMemory(memory);
+        Assert::IsFalse(runtime.HasRichPresence());
 
         const char* pRichPresence = "Format:Num\nFormatType:Value\n\nDisplay:\n@Num(0xH01) @Num(d0xH01)\n";
         runtime.ActivateRichPresence(pRichPresence);
+        Assert::IsTrue(runtime.HasRichPresence());
 
         // string is evaluated with current memrefs (which will be 0)
         Assert::AreEqual(std::wstring(L"0 0"), runtime.GetRichPresenceDisplayString());
@@ -918,15 +920,19 @@ public:
 
         AchievementRuntimeHarness runtime;
         runtime.mockEmulatorContext.MockMemory(memory);
+        Assert::IsFalse(runtime.HasRichPresence());
 
         runtime.ActivateRichPresence("Display:\nHello, World\n");
         Assert::AreEqual(std::wstring(L"Hello, World"), runtime.GetRichPresenceDisplayString());
+        Assert::IsTrue(runtime.HasRichPresence());
 
         runtime.ActivateRichPresence("Display:\nNew String\n");
         Assert::AreEqual(std::wstring(L"New String"), runtime.GetRichPresenceDisplayString());
+        Assert::IsTrue(runtime.HasRichPresence());
 
         runtime.ActivateRichPresence("");
         Assert::AreEqual(std::wstring(L"No Rich Presence defined."), runtime.GetRichPresenceDisplayString());
+        Assert::IsFalse(runtime.HasRichPresence());
     }
 
     TEST_METHOD(TestActivateRichPresenceWithError)
@@ -939,6 +945,7 @@ public:
 
         const char* pRichPresence = "Format:Num\nFormatType:Value\n\nDisplay:\n@Num(0H01) @Num(d0xH01)\n";
         runtime.ActivateRichPresence(pRichPresence);
+        Assert::IsTrue(runtime.HasRichPresence());
 
         Assert::AreEqual(std::wstring(L"Parse error -6 (line 5): Invalid operator"), runtime.GetRichPresenceDisplayString());
     }