Implement page fetching

This commit is contained in:
EmosewaMC 2023-05-08 19:59:10 -07:00
parent d98ad4b94f
commit 6c2312fe87
3 changed files with 14 additions and 11 deletions

View File

@ -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) {

View File

@ -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<LeaderboardManager> {
typedef std::map<GameID, Leaderboard::Type> 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) {

View File

@ -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<Leaderboard::InfoType>(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) {