From 6c2312fe87c9a514b3b42baccd92be16ea206a08 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Mon, 8 May 2023 19:59:10 -0700 Subject: [PATCH] Implement page fetching --- dGame/LeaderboardManager.cpp | 12 +++++++----- dGame/LeaderboardManager.h | 5 ++++- dGame/dGameMessages/GameMessages.cpp | 8 +++----- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/dGame/LeaderboardManager.cpp b/dGame/LeaderboardManager.cpp index 4b56fb60..c662bd6d 100644 --- a/dGame/LeaderboardManager.cpp +++ b/dGame/LeaderboardManager.cpp @@ -240,6 +240,8 @@ std::string Leaderboard::GetOrdering(Leaderboard::Type leaderboardType) { } void Leaderboard::SetupLeaderboard(uint32_t resultStart, uint32_t resultEnd) { + resultStart++; + resultEnd++; std::string queryBase = R"QUERY( WITH leaderboardsRanked AS ( @@ -296,11 +298,11 @@ void Leaderboard::SetupLeaderboard(uint32_t resultStart, uint32_t resultEnd) { // If we are getting the friends leaderboard, add the friends query, otherwise fill it in with nothing. if (this->infoType == InfoType::Friends) { snprintf(lookupBuffer, STRING_LENGTH, queryBase.c_str(), - orderBase.c_str(), friendsQuery, selectBase.c_str(), resultStart + 1, resultEnd + 1); + orderBase.c_str(), friendsQuery, selectBase.c_str(), resultStart, resultEnd); } else { snprintf(lookupBuffer, STRING_LENGTH, queryBase.c_str(), - orderBase.c_str(), "", selectBase.c_str(), resultStart + 1, resultEnd + 1); + orderBase.c_str(), "", selectBase.c_str(), resultStart, resultEnd); } std::string baseLookupStr; @@ -527,10 +529,10 @@ void LeaderboardManager::SaveScore(const LWOOBJID& playerID, GameID gameID, Lead va_end(argsCopy); } -void LeaderboardManager::SendLeaderboard(uint32_t gameID, Leaderboard::InfoType infoType, bool weekly, LWOOBJID targetID, LWOOBJID playerID) { +void LeaderboardManager::SendLeaderboard(uint32_t gameID, Leaderboard::InfoType infoType, bool weekly, LWOOBJID playerID, uint32_t resultStart, uint32_t resultEnd) { Leaderboard leaderboard(gameID, infoType, weekly, playerID, GetLeaderboardType(gameID)); - leaderboard.SetupLeaderboard(); - leaderboard.Send(targetID); + leaderboard.SetupLeaderboard(resultStart, resultEnd); + leaderboard.Send(playerID); } Leaderboard::Type LeaderboardManager::GetLeaderboardType(const GameID gameID) { diff --git a/dGame/LeaderboardManager.h b/dGame/LeaderboardManager.h index 3d3e4b70..ab70ae88 100644 --- a/dGame/LeaderboardManager.h +++ b/dGame/LeaderboardManager.h @@ -63,6 +63,9 @@ public: /** * Builds the leaderboard from the database based on the associated gameID + * + * @param resultStart The index to start the leaderboard at. Zero indexed. + * @param resultEnd The index to end the leaderboard at. Zero indexed. */ void SetupLeaderboard(uint32_t resultStart = 0, uint32_t resultEnd = 10); @@ -96,7 +99,7 @@ private: class LeaderboardManager : public Singleton { typedef std::map LeaderboardCache; public: - void SendLeaderboard(GameID gameID, Leaderboard::InfoType infoType, bool weekly, LWOOBJID targetID, LWOOBJID playerID = LWOOBJID_EMPTY); + void SendLeaderboard(GameID gameID, Leaderboard::InfoType infoType, bool weekly, LWOOBJID playerID, uint32_t resultStart = 0, uint32_t resultEnd = 10); // Saves a score to the database for the Racing minigame inline void SaveRacingScore(const LWOOBJID& playerID, GameID gameID, uint32_t bestLapTime, uint32_t bestTime, bool won) { diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index ec24248b..55f40037 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -1647,8 +1647,8 @@ void GameMessages::HandleRequestActivitySummaryLeaderboardData(RakNet::BitStream int32_t gameID = 0; if (inStream->ReadBit()) inStream->Read(gameID); - int32_t queryType = 1; - if (inStream->ReadBit()) inStream->Read(queryType); + Leaderboard::InfoType queryType = Leaderboard::InfoType::MyStanding; + if (inStream->ReadBit()) inStream->Read(queryType); int32_t resultsEnd = 10; if (inStream->ReadBit()) inStream->Read(resultsEnd); @@ -1661,9 +1661,7 @@ void GameMessages::HandleRequestActivitySummaryLeaderboardData(RakNet::BitStream bool weekly = inStream->ReadBit(); - //const auto* leaderboard = LeaderboardManager::GetLeaderboard(gameID, (InfoType)queryType, weekly, entity->GetObjectID()); - //SendActivitySummaryLeaderboardData(entity->GetObjectID(), leaderboard, sysAddr); - //delete leaderboard; + LeaderboardManager::Instance().SendLeaderboard(gameID, queryType, weekly, target, resultsStart, resultsEnd); } void GameMessages::HandleActivityStateChangeRequest(RakNet::BitStream* inStream, Entity* entity) {