From b979f25b24279e58f616f2e65d6a76be59735fdf Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Mon, 9 Dec 2024 23:17:03 -0800 Subject: [PATCH] fix leaderboard not incrementing on a not better score --- dDatabase/GameDatabase/ITables/ILeaderboard.h | 1 + dDatabase/GameDatabase/MySQL/MySQLDatabase.h | 1 + dDatabase/GameDatabase/MySQL/Tables/Leaderboard.cpp | 4 ++++ dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h | 1 + dGame/LeaderboardManager.cpp | 2 ++ 5 files changed, 9 insertions(+) diff --git a/dDatabase/GameDatabase/ITables/ILeaderboard.h b/dDatabase/GameDatabase/ITables/ILeaderboard.h index fc4164bc..f88497b0 100644 --- a/dDatabase/GameDatabase/ITables/ILeaderboard.h +++ b/dDatabase/GameDatabase/ITables/ILeaderboard.h @@ -41,6 +41,7 @@ class ILeaderboard { virtual void SaveScore(const uint32_t playerId, const uint32_t gameId, const Score& score) = 0; virtual void UpdateScore(const uint32_t playerId, const uint32_t gameId, const Score& score) = 0; virtual void IncrementNumWins(const uint32_t playerId, const uint32_t gameId) = 0; + virtual void IncrementTimesPlayed(const uint32_t playerId, const uint32_t gameId) = 0; }; #endif //!__ILEADERBOARD__H__ diff --git a/dDatabase/GameDatabase/MySQL/MySQLDatabase.h b/dDatabase/GameDatabase/MySQL/MySQLDatabase.h index fa3edfbc..08168141 100644 --- a/dDatabase/GameDatabase/MySQL/MySQLDatabase.h +++ b/dDatabase/GameDatabase/MySQL/MySQLDatabase.h @@ -121,6 +121,7 @@ class MySQLDatabase : public GameDatabase { void UpdateScore(const uint32_t playerId, const uint32_t gameId, const Score& score) override; std::optional GetPlayerScore(const uint32_t playerId, const uint32_t gameId) override; void IncrementNumWins(const uint32_t playerId, const uint32_t gameId) override; + void IncrementTimesPlayed(const uint32_t playerId, const uint32_t gameId) override; void InsertUgcBuild(const std::string& modules, const LWOOBJID bigId, const std::optional characterId) override; void DeleteUgcBuild(const LWOOBJID bigId) override; sql::PreparedStatement* CreatePreppedStmt(const std::string& query); diff --git a/dDatabase/GameDatabase/MySQL/Tables/Leaderboard.cpp b/dDatabase/GameDatabase/MySQL/Tables/Leaderboard.cpp index a6734030..14ac121a 100644 --- a/dDatabase/GameDatabase/MySQL/Tables/Leaderboard.cpp +++ b/dDatabase/GameDatabase/MySQL/Tables/Leaderboard.cpp @@ -68,6 +68,10 @@ void MySQLDatabase::UpdateScore(const uint32_t playerId, const uint32_t gameId, score.primaryScore, score.secondaryScore, score.tertiaryScore, playerId, gameId); } +void MySQLDatabase::IncrementTimesPlayed(const uint32_t playerId, const uint32_t gameId) { + ExecuteUpdate("UPDATE leaderboard SET timesPlayed = timesPlayed + 1 WHERE character_id = ? AND game_id = ?;", playerId, gameId); +} + std::optional MySQLDatabase::GetPlayerScore(const uint32_t playerId, const uint32_t gameId) { std::optional toReturn = std::nullopt; auto res = ExecuteSelect("SELECT * FROM leaderboard WHERE character_id = ? AND game_id = ?;", playerId, gameId); diff --git a/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h b/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h index ffa14020..9d4b184f 100644 --- a/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h +++ b/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h @@ -98,6 +98,7 @@ class TestSQLDatabase : public GameDatabase { void UpdateScore(const uint32_t playerId, const uint32_t gameId, const Score& score) override {}; std::optional GetPlayerScore(const uint32_t playerId, const uint32_t gameId) override { return {}; }; void IncrementNumWins(const uint32_t playerId, const uint32_t gameId) override {}; + void IncrementTimesPlayed(const uint32_t playerId, const uint32_t gameId) override {}; void InsertUgcBuild(const std::string& modules, const LWOOBJID bigId, const std::optional characterId) override {}; void DeleteUgcBuild(const LWOOBJID bigId) override {}; uint32_t GetAccountCount() override { return 0; }; diff --git a/dGame/LeaderboardManager.cpp b/dGame/LeaderboardManager.cpp index f3a27919..da27e88b 100644 --- a/dGame/LeaderboardManager.cpp +++ b/dGame/LeaderboardManager.cpp @@ -288,6 +288,8 @@ void LeaderboardManager::SaveScore(const LWOOBJID& playerID, const GameID activi if (newHighScore) { Database::Get()->UpdateScore(playerID, activityId, newScore); + } else { + Database::Get()->IncrementTimesPlayed(playerID, activityId); } } else { Database::Get()->SaveScore(playerID, activityId, newScore);